Menu

#101 TaskHandler.isOnDemand causes one-off Tasks to become onDemand Tasks

None
closed-accepted
5
2015-04-19
2015-04-13
Ben Parker
No

A Task added to the Scheduler via addTimedAction() should run once and then disappear from the Scheduler (if it wasn't previously added via addOnDemandAction). However, TaskHandler's isOnDemand() method returns True if the handler's period is 0, which turns all non-periodic Tasks into onDemand Tasks.

I discovered this when going back to do maintenance on an older Webware site. After upgrading Webware, all the "run once" Tasks were accumulating in the Scheduler's onDemand list. That could be a memory leak depending on what objects those Tasks are referencing. The developer thinks the Task will run and be garbage collected, but instead it's hanging around in the onDemand list.

The fix is simply to manage onDemand state separately, because non-periodic Tasks are not always onDemand Tasks. If a Task is added to the Scheduler via addOnDemandTask(), then it should remain in the onDemand list, but otherwise non-periodic Tasks should drop out of the Scheduler.

The attached diffs from 1.1.1 to the fixed version maintains onDemand state in the TaskHandler. The changes retain the current behavior of adding an onDemand Task back to the onDemand list even if it was subsequently added again as a timed action with the same name, while fixing the bug of transforming all non-periodic actions into onDemand ones.

The state needs to be managed in the TaskHandler rather than simply relying on the Handler's presence in the Scheduler's onDemand list, because the Handler is unregistered (and removed from the onDemand list) at the beginning of both addTimedAction and addOnDemandAction.

2 Attachments

Discussion

  • Christoph Zwerschke

    • status: open --> closed-accepted
    • assigned_to: Christoph Zwerschke
    • Group: -->
     
  • Christoph Zwerschke

    Thank you. Commited as r8270.

     

Log in to post a comment.