django-background-task icon indicating copy to clipboard operation
django-background-task copied to clipboard

When scheduling tasks, is it possible to get the id of the Task database object that has been created?

Open stargazer opened this issue 12 years ago • 2 comments

When scheduling tasks, is it possible to get the id of the Task object that has been created in the database? That would be really useful, since it would enable us to cancel the scheduled task, simply by deleting the object.

stargazer avatar Jul 16 '12 11:07 stargazer

It's not currently possible (it's currently fire and forget). I'll look into returning an object that would let you get the id when you schedule a task (currently None is returned).

lilspikey avatar Jul 16 '12 12:07 lilspikey

One things that occurs to me about this is being careful not to delete a task that's actually in the process of being run. We'd probably need to lock the task (in the same manner as the worker process) before deleting to avoid this issue. Plus we'd need to report back whether the deletion was successful or not. For tasks scheduled in the future it should always work, but there is the edge case of tasks that are getting cancelled just as they are about to run...

lilspikey avatar Mar 11 '15 10:03 lilspikey