@@ -102,16 +102,16 @@ public DistributedJobManager(SchedJobMapper jobMapper,
102
102
// ------------------------------------------------------------------database single operation without spring transactional
103
103
104
104
public boolean renewInstanceUpdateTime (SchedInstance instance , Date updateTime ) {
105
- return instanceMapper .renewUpdateTime (instance .getInstanceId (), updateTime , instance .getVersion ()) == AFFECTED_ONE_ROW ;
105
+ return isOneAffectedRow ( instanceMapper .renewUpdateTime (instance .getInstanceId (), updateTime , instance .getVersion ())) ;
106
106
}
107
107
108
108
@ Override
109
109
protected boolean cancelWaitingTask (long taskId ) {
110
- return taskMapper .terminate (taskId , null , ExecuteState .BROADCAST_ABORTED .value (), ExecuteState .WAITING .value (), null , null ) == AFFECTED_ONE_ROW ;
110
+ return isOneAffectedRow ( taskMapper .terminate (taskId , null , ExecuteState .BROADCAST_ABORTED .value (), ExecuteState .WAITING .value (), null , null )) ;
111
111
}
112
112
113
113
public void savepoint (long taskId , String executeSnapshot ) {
114
- Assert . state (taskMapper .savepoint (taskId , executeSnapshot ) == AFFECTED_ONE_ROW , () -> "Save point failed: " + taskId + " | " + executeSnapshot );
114
+ assertOneAffectedRow (taskMapper .savepoint (taskId , executeSnapshot ), () -> "Save point failed: " + taskId + " | " + executeSnapshot );
115
115
}
116
116
117
117
// ------------------------------------------------------------------database operation within spring transactional
@@ -228,27 +228,27 @@ public void deleteInstance(long instanceId) {
228
228
229
229
// delete workflow lead instance
230
230
int row = instanceMapper .deleteByInstanceId (instanceId );
231
- Assert . isTrue (row == AFFECTED_ONE_ROW , () -> "Delete workflow lead instance conflict: " + instanceId );
231
+ assertOneAffectedRow (row , () -> "Delete workflow lead instance conflict: " + instanceId );
232
232
233
233
// delete task
234
234
for (SchedInstance e : instanceMapper .findWorkflowNode (instance .getWnstanceId ())) {
235
235
row = taskMapper .deleteByInstanceId (e .getInstanceId ());
236
- Assert . isTrue (row >= AFFECTED_ONE_ROW , () -> "Delete sched task conflict: " + instanceId );
236
+ assertManyAffectedRow (row , () -> "Delete sched task conflict: " + instanceId );
237
237
}
238
238
239
239
// delete workflow node instance
240
240
row = instanceMapper .deleteByWnstanceId (instanceId );
241
- Assert . isTrue (row >= AFFECTED_ONE_ROW , () -> "Delete workflow node instance conflict: " + instanceId );
241
+ assertManyAffectedRow (row , () -> "Delete workflow node instance conflict: " + instanceId );
242
242
243
243
// delete workflow config
244
244
row = workflowMapper .deleteByWnstanceId (instanceId );
245
- Assert . isTrue (row >= AFFECTED_ONE_ROW , () -> "Delete sched workflow conflict: " + instanceId );
245
+ assertManyAffectedRow (row , () -> "Delete sched workflow conflict: " + instanceId );
246
246
} else {
247
247
int row = instanceMapper .deleteByInstanceId (instanceId );
248
- Assert . isTrue (row == AFFECTED_ONE_ROW , () -> "Delete sched instance conflict: " + instanceId );
248
+ assertOneAffectedRow (row , () -> "Delete sched instance conflict: " + instanceId );
249
249
250
250
row = taskMapper .deleteByInstanceId (instanceId );
251
- Assert . isTrue (row >= AFFECTED_ONE_ROW , () -> "Delete sched task conflict: " + instanceId );
251
+ assertManyAffectedRow (row , () -> "Delete sched task conflict: " + instanceId );
252
252
}
253
253
LOG .info ("Delete sched instance success {}" , instanceId );
254
254
});
@@ -277,7 +277,7 @@ public boolean terminateTask(TerminateTaskParam param) {
277
277
278
278
Date executeEndTime = toState .isTerminal () ? new Date () : null ;
279
279
int row = taskMapper .terminate (param .getTaskId (), param .getWorker (), toState .value (), ExecuteState .EXECUTING .value (), executeEndTime , param .getErrorMsg ());
280
- if (row != AFFECTED_ONE_ROW ) {
280
+ if (! isOneAffectedRow ( row ) ) {
281
281
// usual is worker invoke http timeout, then retry
282
282
LOG .warn ("Conflict terminate executing task: {} | {}" , param .getTaskId (), toState );
283
283
return false ;
@@ -335,7 +335,7 @@ public boolean purgeInstance(SchedInstance inst) {
335
335
// cannot be paused
336
336
Assert .isTrue (tuple .a .isTerminal (), () -> "Purge instance state must be terminal state: " + instance );
337
337
}
338
- if (instanceMapper .terminate (instanceId , tuple .a .value (), RUN_STATE_TERMINABLE , tuple .b ) != AFFECTED_ONE_ROW ) {
338
+ if (! isOneAffectedRow ( instanceMapper .terminate (instanceId , tuple .a .value (), RUN_STATE_TERMINABLE , tuple .b )) ) {
339
339
return false ;
340
340
}
341
341
@@ -443,7 +443,7 @@ public boolean resumeInstance(long instanceId) {
443
443
Assert .isTrue (instance .isWorkflowLead (), () -> "Cannot resume workflow node instance: " + instanceId );
444
444
// update sched_instance paused lead to running state
445
445
int row = instanceMapper .updateState (instanceId , RunState .RUNNING .value (), RunState .PAUSED .value ());
446
- Assert . state (row == AFFECTED_ONE_ROW , () -> "Resume workflow lead instance failed: " + instanceId );
446
+ assertOneAffectedRow (row , () -> "Resume workflow lead instance failed: " + instanceId );
447
447
workflowMapper .resumeWaiting (instanceId );
448
448
for (SchedInstance nodeInstance : instanceMapper .findWorkflowNode (instanceId )) {
449
449
if (RunState .PAUSED .equals (nodeInstance .getRunState ())) {
@@ -540,7 +540,7 @@ private void pauseInstance(SchedInstance instance) {
540
540
// must be paused or terminate
541
541
Assert .notNull (tuple , () -> "Pause instance failed: " + instanceId );
542
542
int row = instanceMapper .terminate (instanceId , tuple .a .value (), RUN_STATE_PAUSABLE , tuple .b );
543
- Assert . isTrue (row == AFFECTED_ONE_ROW , () -> "Pause instance failed: " + instance + " | " + tuple .a );
543
+ assertOneAffectedRow (row , () -> "Pause instance failed: " + instance + " | " + tuple .a );
544
544
if (instance .isWorkflowNode ()) {
545
545
updateWorkflowEdgeState (instance , tuple .a .value (), RUN_STATE_PAUSABLE );
546
546
}
@@ -568,7 +568,7 @@ private void cancelInstance(SchedInstance instance, Operations ops) {
568
568
569
569
RunState toState = tuple .a ;
570
570
int row = instanceMapper .terminate (instanceId , toState .value (), RUN_STATE_TERMINABLE , tuple .b );
571
- Assert . isTrue (row == AFFECTED_ONE_ROW , () -> "Cancel instance failed: " + instance + " | " + toState );
571
+ assertOneAffectedRow (row , () -> "Cancel instance failed: " + instance + " | " + toState );
572
572
if (instance .isWorkflowNode ()) {
573
573
updateWorkflowEdgeState (instance , tuple .a .value (), RUN_STATE_TERMINABLE );
574
574
}
@@ -581,10 +581,10 @@ private void cancelInstance(SchedInstance instance, Operations ops) {
581
581
private void resumeInstance (SchedInstance instance ) {
582
582
long instanceId = instance .getInstanceId ();
583
583
int row = instanceMapper .updateState (instanceId , RunState .WAITING .value (), RunState .PAUSED .value ());
584
- Assert . state (row == AFFECTED_ONE_ROW , "Resume sched instance failed." );
584
+ assertOneAffectedRow (row , "Resume sched instance failed." );
585
585
586
586
row = taskMapper .updateStateByInstanceId (instanceId , ExecuteState .WAITING .value (), EXECUTE_STATE_PAUSED , null );
587
- Assert . state (row >= AFFECTED_ONE_ROW , "Resume sched task failed." );
587
+ assertManyAffectedRow (row , "Resume sched task failed." );
588
588
589
589
// dispatch task
590
590
Tuple3 <SchedJob , SchedInstance , List <SchedTask >> params = buildDispatchParams (instanceId , row );
@@ -602,11 +602,11 @@ private void updateWorkflowLeadState(SchedInstance instance) {
602
602
if (graph .allMatch (e -> e .getValue ().isTerminal ())) {
603
603
RunState state = graph .anyMatch (e -> e .getValue ().isFailure ()) ? RunState .CANCELED : RunState .FINISHED ;
604
604
int row = instanceMapper .terminate (instance .getWnstanceId (), state .value (), RUN_STATE_TERMINABLE , new Date ());
605
- Assert . isTrue (row == AFFECTED_ONE_ROW , () -> "Update workflow lead instance state failed: " + instance + " | " + state );
605
+ assertOneAffectedRow (row , () -> "Update workflow lead instance state failed: " + instance + " | " + state );
606
606
} else if (workflows .stream ().noneMatch (e -> RunState .RUNNING .equals (e .getRunState ()))) {
607
607
RunState state = RunState .PAUSED ;
608
608
int row = instanceMapper .updateState (instance .getWnstanceId (), state .value (), instance .getRunState ());
609
- Assert . isTrue (row == AFFECTED_ONE_ROW , () -> "Update workflow lead instance state failed: " + instance + " | " + state );
609
+ assertOneAffectedRow (row , () -> "Update workflow lead instance state failed: " + instance + " | " + state );
610
610
}
611
611
}
612
612
@@ -739,7 +739,7 @@ private void processWorkflow(SchedInstance nodeInstance) {
739
739
if (graph .allMatch (e -> e .getValue ().isTerminal ())) {
740
740
RunState state = graph .anyMatch (e -> e .getValue ().isFailure ()) ? RunState .CANCELED : RunState .FINISHED ;
741
741
int row = instanceMapper .terminate (wnstanceId , state .value (), RUN_STATE_TERMINABLE , new Date ());
742
- Assert . isTrue (row == AFFECTED_ONE_ROW , () -> "Terminate workflow lead instance failed: " + nodeInstance + " | " + state );
742
+ assertOneAffectedRow (row , () -> "Terminate workflow lead instance failed: " + nodeInstance + " | " + state );
743
743
afterTerminateTask (instanceMapper .get (wnstanceId ));
744
744
return ;
745
745
}
@@ -887,7 +887,7 @@ private List<ExecuteTaskParam> loadExecutingTasks(SchedInstance instance, Operat
887
887
// update dead task
888
888
Date executeEndTime = ops .toState ().isTerminal () ? new Date () : null ;
889
889
int row = taskMapper .terminate (task .getTaskId (), task .getWorker (), ops .toState ().value (), ExecuteState .EXECUTING .value (), executeEndTime , null );
890
- if (row != AFFECTED_ONE_ROW ) {
890
+ if (! isOneAffectedRow ( row ) ) {
891
891
LOG .error ("Cancel the dead task failed: {}" , task );
892
892
executingTasks .add (builder .build (ops , task .getTaskId (), triggerTime , worker ));
893
893
} else {
0 commit comments