Skip to content

Commit

Permalink
Fix scheduled tasks sometimes not getting the correct timestamp. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
simon816 committed Jul 13, 2015
1 parent 51c0c1f commit 4104d1b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public enum ScheduledTaskState {
* Never ran before, waiting for the offset to pass.
*/
WAITING,
/**
* In the process of switching to the running state.
*/
SWITCHING,
/**
* Has ran, and will continue to unless removed from the task map.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ protected void processTask(ScheduledTask task) {
// If the task has a period of 0 (zero) this task will not repeat, and
// is removed after we start it.
if (threshold <= (now - task.getTimestamp())) {
task.setTimestamp(now);
task.setState(ScheduledTask.ScheduledTaskState.SWITCHING);
task.setTimestamp(this.getTimestamp(task));
startTask(task);
// If task is one time shot, remove it from the map.
if (task.period == 0L) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected long getTimestamp(ScheduledTask task) {
} else {
return super.getTimestamp(task);
}
} else if (task.getState() == ScheduledTask.ScheduledTaskState.RUNNING) {
} else if (task.getState() == ScheduledTask.ScheduledTaskState.RUNNING || task.getState() == ScheduledTask.ScheduledTaskState.SWITCHING) {
// The timestamp is based on the period
if (task.intervalIsTicks) {
return this.counter;
Expand Down

0 comments on commit 4104d1b

Please sign in to comment.