Commits

Zemian Deng committed 728b5ed

Moved delete dead schedule into init service state only.
Added after job run to check for dead schedule.

Comments (0)

Files changed (1)

timemachine-scheduler/src/main/java/timemachine/scheduler/service/PollingScheduleRunner.java

 					logger.debug("Updating {} after a jobTask run.", schedule);
 					schedule.updateNextRun();
 					Date nextRun = schedule.getNextRun();
-					if (nextRun == null) {
+					if (nextRun == null || schedule.isDeleted()) {
 						// This schedule is done. Remove it.
 						dataStore.deleteSchedule(schedulerId, schedule);
 					} else {
 		if (maxSchedulesPerInterval <= 0) {
 			maxSchedulesPerInterval = 1;
 		}
+		
+		if (!disableDeadScheduleRemoval)
+			dataStore.deleteDeadSchedules(scheduler.getSchedulerId(), -1);
 	}
 	
 	private int findSmallestThreadPoolSize() {
 				if (!disableMissedRun)
 					checkScheduleForMissedRun();
 				
-				if (!disableDeadScheduleRemoval)
-					dataStore.deleteDeadSchedules(scheduler.getSchedulerId(), maxSchedulesPerInterval);
-				
 				int scheduleSubmittedCount = checkSchedulesToRun();
 				
 				// The checkSchedulesToRun might takes a while, so we might check to see if we are in pause or start mode.