33import com .github .ltsopensource .core .commons .utils .Callable ;
44import com .github .ltsopensource .core .commons .utils .CollectionUtils ;
55import com .github .ltsopensource .core .constant .Constants ;
6+ import com .github .ltsopensource .core .constant .ExtConfig ;
67import com .github .ltsopensource .core .domain .JobMeta ;
78import com .github .ltsopensource .core .domain .JobRunResult ;
89import com .github .ltsopensource .core .exception .JobTrackerNotFoundException ;
@@ -50,29 +51,32 @@ public class JobPushProcessor extends AbstractProcessor {
5051 protected JobPushProcessor (TaskTrackerAppContext appContext ) {
5152 super (appContext );
5253 this .remotingClient = appContext .getRemotingClient ();
53- retryScheduler = new RetryScheduler <JobRunResult >(JobPushProcessor .class .getSimpleName (), appContext ,
54- FailStorePathBuilder .getJobFeedbackPath (appContext ), 3 ) {
55- @ Override
56- protected boolean isRemotingEnable () {
57- return remotingClient .isServerEnable ();
58- }
59-
60- @ Override
61- protected boolean retry (List <JobRunResult > results ) {
62- return retrySendJobResults (results );
63- }
64- };
65- retryScheduler .start ();
66-
6754 // 线程安全的
6855 jobRunnerCallback = new JobRunnerCallback ();
6956
70- NodeShutdownHook .registerHook (appContext , this .getClass ().getName (), new Callable () {
71- @ Override
72- public void call () throws Exception {
73- retryScheduler .stop ();
74- }
75- });
57+
58+ if (isEnableFailStore ()) {
59+ retryScheduler = new RetryScheduler <JobRunResult >(JobPushProcessor .class .getSimpleName (), appContext ,
60+ FailStorePathBuilder .getJobFeedbackPath (appContext ), 3 ) {
61+ @ Override
62+ protected boolean isRemotingEnable () {
63+ return remotingClient .isServerEnable ();
64+ }
65+
66+ @ Override
67+ protected boolean retry (List <JobRunResult > results ) {
68+ return retrySendJobResults (results );
69+ }
70+ };
71+ retryScheduler .start ();
72+
73+ NodeShutdownHook .registerHook (appContext , this .getClass ().getName (), new Callable () {
74+ @ Override
75+ public void call () throws Exception {
76+ retryScheduler .stop ();
77+ }
78+ });
79+ }
7680 }
7781
7882 @ Override
@@ -152,9 +156,15 @@ public void operationComplete(ResponseFuture responseFuture) {
152156 LOGGER .info ("Job feedback failed, save local files。{}" , jobRunResult );
153157 }
154158 try {
155- retryScheduler .inSchedule (
156- jobRunResult .getJobMeta ().getJobId ().concat ("_" ) + SystemClock .now (),
157- jobRunResult );
159+ if (isEnableFailStore ()) {
160+ retryScheduler .inSchedule (
161+ jobRunResult .getJobMeta ().getJobId ().concat ("_" ) + SystemClock .now (),
162+ jobRunResult );
163+ } else {
164+ LOGGER .error ("Send Job Result to JobTracker Error, code={}, jobRunResult={}" ,
165+ commandResponse != null ? commandResponse .getCode () : null , JSON .toJSONString (jobRunResult ));
166+ }
167+
158168 } catch (Exception e ) {
159169 LOGGER .error ("Job feedback failed" , e );
160170 }
@@ -173,9 +183,14 @@ public void operationComplete(ResponseFuture responseFuture) {
173183 } catch (JobTrackerNotFoundException e ) {
174184 try {
175185 LOGGER .warn ("No job tracker available! save local files." );
176- retryScheduler .inSchedule (
177- jobRunResult .getJobMeta ().getJobId ().concat ("_" ) + SystemClock .now (),
178- jobRunResult );
186+
187+ if (isEnableFailStore ()) {
188+ retryScheduler .inSchedule (
189+ jobRunResult .getJobMeta ().getJobId ().concat ("_" ) + SystemClock .now (),
190+ jobRunResult );
191+ } else {
192+ LOGGER .error ("Send Job Result to JobTracker Error, server is down, jobRunResult={}" , JSON .toJSONString (jobRunResult ));
193+ }
179194 } catch (Exception e1 ) {
180195 LOGGER .error ("Save files failed, {}" , jobRunResult .getJobMeta (), e1 );
181196 }
@@ -185,6 +200,10 @@ public void operationComplete(ResponseFuture responseFuture) {
185200 }
186201 }
187202
203+ private boolean isEnableFailStore () {
204+ return !appContext .getConfig ().getParameter (ExtConfig .TASK_TRACKER_JOB_RESULT_FAIL_STORE_CLOSE , false );
205+ }
206+
188207 /**
189208 * 发送JobResults
190209 */
0 commit comments