django-background-task
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?
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.
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).
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...