@@ -222,9 +222,13 @@ public String result() {
222
222
return this .result ;
223
223
}
224
224
225
- private void result (String result ) {
225
+ private synchronized boolean result (TaskStatus status , String result ) {
226
226
checkPropertySize (result , P .RESULT );
227
- this .result = result ;
227
+ if (this .status (status )) {
228
+ this .result = result ;
229
+ return true ;
230
+ }
231
+ return false ;
228
232
}
229
233
230
234
public void server (Id server ) {
@@ -319,18 +323,17 @@ public boolean fail(Throwable e) {
319
323
LOG .warn ("An exception occurred when running task: {}" ,
320
324
this .id (), e );
321
325
// Update status to FAILED if exception occurred(not interrupted)
322
- if (this .status (TaskStatus .FAILED )) {
323
- this .result (e .toString ());
326
+ if (this .result (TaskStatus .FAILED , e .toString ())) {
324
327
return true ;
325
328
}
326
329
}
327
330
return false ;
328
331
}
329
332
330
- public void failSave (Throwable e ) {
333
+ public void failToSave (Throwable e ) {
331
334
if (!this .fail (e )) {
332
335
// Can't update status, just set result to error message
333
- this .result ( e .toString () );
336
+ this .result = e .toString ();
334
337
}
335
338
}
336
339
@@ -352,9 +355,7 @@ protected void done() {
352
355
protected void set (V v ) {
353
356
String result = JsonUtil .toJson (v );
354
357
checkPropertySize (result , P .RESULT );
355
- if (this .status (TaskStatus .SUCCESS )) {
356
- this .result = result ;
357
- } else {
358
+ if (!this .result (TaskStatus .SUCCESS , result )) {
358
359
assert this .completed ();
359
360
}
360
361
// Will call done() and may cause to save to store
@@ -381,22 +382,21 @@ protected boolean checkDependenciesSuccess() {
381
382
if (this .dependencies == null || this .dependencies .isEmpty ()) {
382
383
return true ;
383
384
}
385
+ TaskScheduler scheduler = this .scheduler ();
384
386
for (Id dependency : this .dependencies ) {
385
- HugeTask <?> task = this . scheduler () .task (dependency );
387
+ HugeTask <?> task = scheduler .task (dependency );
386
388
if (!task .completed ()) {
387
389
// Dependent task not completed, re-schedule self
388
- this . scheduler () .schedule (this );
390
+ scheduler .schedule (this );
389
391
return false ;
390
392
} else if (task .status () == TaskStatus .CANCELLED ) {
391
- this .status (TaskStatus .CANCELLED );
392
- this .result (String .format (
393
+ this .result (TaskStatus .CANCELLED , String .format (
393
394
"Cancelled due to dependent task '%s' cancelled" ,
394
395
dependency ));
395
396
this .done ();
396
397
return false ;
397
398
} else if (task .status () == TaskStatus .FAILED ) {
398
- this .status (TaskStatus .FAILED );
399
- this .result (String .format (
399
+ this .result (TaskStatus .FAILED , String .format (
400
400
"Failed due to dependent task '%s' failed" ,
401
401
dependency ));
402
402
this .done ();
@@ -483,7 +483,7 @@ protected void property(String key, Object value) {
483
483
}
484
484
}
485
485
486
- protected Object [] asArray () {
486
+ protected synchronized Object [] asArray () {
487
487
E .checkState (this .type != null , "Task type can't be null" );
488
488
E .checkState (this .name != null , "Task name can't be null" );
489
489
@@ -563,7 +563,7 @@ public Map<String, Object> asMap() {
563
563
return this .asMap (true );
564
564
}
565
565
566
- public Map <String , Object > asMap (boolean withDetails ) {
566
+ public synchronized Map <String , Object > asMap (boolean withDetails ) {
567
567
E .checkState (this .type != null , "Task type can't be null" );
568
568
E .checkState (this .name != null , "Task name can't be null" );
569
569
0 commit comments