@@ -769,46 +769,57 @@ protected void runInContext() {
769769
770770 public void reallyRun () {
771771 try {
772- s_logger .trace ("Begin cleanup expired async-jobs" );
772+ s_logger .info ("Begin cleanup expired async-jobs" );
773773
774- Date cutTime = new Date (DateUtil .currentGMTTime ().getTime () - JobExpireMinutes .value () * 60000 );
774+ // forcefully cancel blocking queue items if they've been staying there for too long
775+ List <SyncQueueItemVO > blockItems = _queueMgr .getBlockedQueueItems (JobCancelThresholdMinutes .value () * 60000 , false );
776+ if (blockItems != null && blockItems .size () > 0 ) {
777+ for (SyncQueueItemVO item : blockItems ) {
778+ try {
779+ if (item .getContentType ().equalsIgnoreCase (SyncQueueItem .AsyncJobContentType )) {
780+ s_logger .info ("Remove Job-" + item .getContentId () + " from Queue-" + item .getId () + " since it has been blocked for too long" );
781+ completeAsyncJob (item .getContentId (), JobInfo .Status .FAILED , 0 , "Job is cancelled as it has been blocking others for too long" );
782+
783+ _jobMonitor .unregisterByJobId (item .getContentId ());
784+ }
785+
786+ // purge the item and resume queue processing
787+ _queueMgr .purgeItem (item .getId ());
788+ } catch (Throwable e ) {
789+ s_logger .error ("Unexpected exception when trying to remove job from sync queue, " , e );
790+ }
791+ }
792+ }
775793
794+ Date cutTime = new Date (DateUtil .currentGMTTime ().getTime () - JobExpireMinutes .value () * 60000 );
776795 // limit to 100 jobs per turn, this gives cleanup throughput as 600 jobs per minute
777796 // hopefully this will be fast enough to balance potential growth of job table
778797 // 1) Expire unfinished jobs that weren't processed yet
779798 List <AsyncJobVO > unfinishedJobs = _jobDao .getExpiredUnfinishedJobs (cutTime , 100 );
780799 for (AsyncJobVO job : unfinishedJobs ) {
781- s_logger .info ("Expunging unfinished job " + job );
800+ try {
801+ s_logger .info ("Expunging unfinished job-" + job .getId ());
782802
783- _jobMonitor .unregisterByJobId (job .getId ());
784- expungeAsyncJob (job );
803+ _jobMonitor .unregisterByJobId (job .getId ());
804+ expungeAsyncJob (job );
805+ } catch (Throwable e ) {
806+ s_logger .error ("Unexpected exception when trying to expunge job-" + job .getId (), e );
807+ }
785808 }
786809
787810 // 2) Expunge finished jobs
788811 List <AsyncJobVO > completedJobs = _jobDao .getExpiredCompletedJobs (cutTime , 100 );
789812 for (AsyncJobVO job : completedJobs ) {
790- s_logger .trace ("Expunging completed job " + job );
791-
792- expungeAsyncJob (job );
793- }
794-
795- // forcefully cancel blocking queue items if they've been staying there for too long
796- List <SyncQueueItemVO > blockItems = _queueMgr .getBlockedQueueItems (JobCancelThresholdMinutes .value () * 60000 , false );
797- if (blockItems != null && blockItems .size () > 0 ) {
798- for (SyncQueueItemVO item : blockItems ) {
799- if (item .getContentType ().equalsIgnoreCase (SyncQueueItem .AsyncJobContentType )) {
800- s_logger .info ("Remove Job-" + item .getContentId () + " from Queue-" + item .getId () + " since it has been blocked for too long" );
801- completeAsyncJob (item .getContentId (), JobInfo .Status .FAILED , 0 , "Job is cancelled as it has been blocking others for too long" );
802-
803- _jobMonitor .unregisterByJobId (item .getContentId ());
804- }
813+ try {
814+ s_logger .info ("Expunging completed job-" + job .getId ());
805815
806- // purge the item and resume queue processing
807- _queueMgr .purgeItem (item .getId ());
816+ expungeAsyncJob (job );
817+ } catch (Throwable e ) {
818+ s_logger .error ("Unexpected exception when trying to expunge job-" + job .getId (), e );
808819 }
809820 }
810821
811- s_logger .trace ("End cleanup expired async-jobs" );
822+ s_logger .info ("End cleanup expired async-jobs" );
812823 } catch (Throwable e ) {
813824 s_logger .error ("Unexpected exception when trying to execute queue item, " , e );
814825 }
0 commit comments