2828import org .springframework .context .event .EventListener ;
2929import org .springframework .stereotype .Component ;
3030
31- import static com .iexec .common .replicate .ReplicateStatus .FAILED ;
31+ import java .util .List ;
32+
33+ import static com .iexec .common .replicate .ReplicateStatus .*;
3234import static com .iexec .common .replicate .ReplicateStatusCause .TASK_NOT_ACTIVE ;
3335
3436@ Slf4j
@@ -51,23 +53,31 @@ public ReplicateListeners(final WorkerService workerService,
5153 }
5254
5355 @ EventListener
54- public void onReplicateUpdatedEvent (ReplicateUpdatedEvent event ) {
55- log .debug ("Received ReplicateUpdatedEvent [chainTaskId:{}] " , event .getChainTaskId ());
56+ public void onReplicateUpdatedEvent (final ReplicateUpdatedEvent event ) {
57+ log .debug ("Received ReplicateUpdatedEvent [chainTaskId:{}, workerAddress:{}, status:{}]" ,
58+ event .getChainTaskId (), event .getWalletAddress (), event .getReplicateStatusUpdate ().getStatus ());
5659 final ReplicateStatusUpdate statusUpdate = event .getReplicateStatusUpdate ();
5760 final ReplicateStatus newStatus = statusUpdate .getStatus ();
5861 final ReplicateStatusCause cause = statusUpdate .getDetails () != null ? statusUpdate .getDetails ().getCause () : null ;
5962
60- taskUpdateRequestManager .publishRequest (event .getChainTaskId ());
63+ // Those are the only transitions justifying to update a task status
64+ // When one worker updates its replicate status to STARTED, its task status can be updated to RUNNING
65+ // When one worker updates its replicate status to RESULT_UPLOADED, its task status can be updated to RESULT_UPLOADED
66+ // The other statuses denote major PoCo events allowing to see an update of the associated task status
67+ // The check against isFailedBeforeComputed allows to trigger the running2runningFailed check in TaskUpdateManager
68+ // This protection allows to avoid unnecessary loops in update manager as well as unnecessary on-chain calls
69+ if (List .of (STARTED , CONTRIBUTE_AND_FINALIZE_DONE , CONTRIBUTED , REVEALED , RESULT_UPLOADED ).contains (newStatus )
70+ || newStatus .isFailedBeforeComputed ()) {
71+ taskUpdateRequestManager .publishRequest (event .getChainTaskId ());
72+ }
6173
6274 /*
6375 * Should release 1 CPU of given worker for this replicate if status is
6476 * "COMPUTED" or "*_FAILED" before COMPUTED
6577 */
66- if (newStatus == ReplicateStatus .START_FAILED
67- || newStatus == ReplicateStatus .APP_DOWNLOAD_FAILED
68- || newStatus == ReplicateStatus .DATA_DOWNLOAD_FAILED
69- || newStatus == ReplicateStatus .COMPUTED
70- || newStatus == ReplicateStatus .COMPUTE_FAILED ) {
78+ if (newStatus .isFailedBeforeComputed () || newStatus == ReplicateStatus .COMPUTED ) {
79+ log .info ("End of replicate computation detected [chainTaskId:{}, workerAddress:{}]" ,
80+ event .getChainTaskId (), event .getWalletAddress ());
7181 workerService .removeComputedChainTaskIdFromWorker (event .getChainTaskId (), event .getWalletAddress ());
7282 }
7383
0 commit comments