Scheduled Task behaviour settings

Sometimes scheduled tasks do not finish as planned and the next instance of the same task can overlap (strangely, overlapping does not always happen)

It would be good to have the following options when creating a task:

  • Kill the previous instance if still running
  • Wait until the previous instance finishes (with the timeout option below)
  • Timeout Minutes
2 Likes

There is nothing to stop you implementing those for yourself right now. I often ensure that only one instance of a task is running.

1 Like

Please can you share how to do this within Anvil? Scheduled tasks skip if the previous call is still running - is there a way this can be managed?

You might try having your current background task you would like to be run called by a separate scheduled task.

In other words you have one background task that does work, then a different one that is triggered by the scheduler that will do nothing other than create a new background task object and then return.

If you did not want the same task run at the same time as another ( idempotence in scheduled calls ) , then you can use anvil.server.list_background_tasks() and iterate over its result finding the uncompleted tasks and seeing if the current request need to be skipped.

2 Likes