@@ -232,15 +232,17 @@ public void completeAsyncJob(final long jobId, final Status jobStatus, final int
232232 s_logger .debug ("job-" + jobId + " no longer exists, we just log completion info here. " + jobStatus + ", resultCode: " + resultCode + ", result: " +
233233 resultObject );
234234 }
235-
235+ // still purge item from queue to avoid any blocking
236+ _queueMgr .purgeAsyncJobQueueItemId (jobId );
236237 return ;
237238 }
238239
239240 if (job .getStatus () != JobInfo .Status .IN_PROGRESS ) {
240241 if (s_logger .isDebugEnabled ()) {
241242 s_logger .debug ("job-" + jobId + " is already completed." );
242243 }
243-
244+ // still purge item from queue to avoid any blocking
245+ _queueMgr .purgeAsyncJobQueueItemId (jobId );
244246 return ;
245247 }
246248
@@ -547,6 +549,8 @@ protected void runInContext() {
547549 // guard final clause as well
548550 try {
549551 if (job .getSyncSource () != null ) {
552+ // here check queue item one more time to double make sure that queue item is removed in case of any uncaught exception
553+ _queueMgr .purgeItem (job .getSyncSource ().getId ());
550554 checkQueue (job .getSyncSource ().getQueueId ());
551555 }
552556
@@ -976,6 +980,12 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
976980 _queueMgr .cleanupActiveQueueItems (msid , true );
977981 // reset job status for all jobs running on this ms node
978982 _jobDao .resetJobProcess (msid , ApiErrorCode .INTERNAL_ERROR .getHttpCode (), "job cancelled because of management server restart or shutdown" );
983+ // purge those queue items for those cancelled jobs above, which may not be picked up by any MS node yet
984+ List <AsyncJobVO > cancelJobs = _jobDao .getResetJobs (msid );
985+ for (AsyncJobVO job : cancelJobs ){
986+ _queueMgr .purgeAsyncJobQueueItemId (job .getId ());
987+ }
988+
979989 }
980990 });
981991 } catch (Throwable e ) {
0 commit comments