Feature Request: Custom (or more diverse) Frequency Options w/ Background Tasks

Options

I doubt I'm the first person to mention this, but it would be awesome if we had the option to get a little bit more granular with the frequency options on Background Tasks.

I have one super intense task that takes about 6.5 to 7 hours to run. 6 hours could cause some overlap issues and 12 hours (my next option) causes an unnecessary gap (it's a background task related to pulling the latest product prices from retailers). It would be awesome if we could either type in specific times or just have a bigger list with more options.


Comments

  • pete letkeman
    Options

    One possible workaround could be to do something like

    Start Main Task -> get [status] value from database

    • if [status] = 'New' then update [status] to 'Started' in database and begin main process
    • - when main task is done, set [status] in database to 'Completed'

    Start Checking Task -> get [status] value from database

    • if [status] is 'Completed' then update [status] to 'New'

    Now you have two background tasks, one that runs the main task and the other that only checks and sets the status. If you set the interval to every hour then at most your main task would be idle for 59 minutes and a few seconds.

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    I'm pretty sure background tasks always run in sequence - they aren't allowed to overlap. So if you have a 20 minute task told to run every minute, it would run actually only fire every 20 mins - 19 of the scheduled events would be "whoops, its already running." If you want to go nose-to-tail, a short frequency would probably do it for you - without even the ceremony of the lock record pattern Pete describes (very well!) above.

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Yes @Ray Deck is correct - background tasks do not overlap. So if one is running it will need to complete before another one can begin.

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    Great! So you might even choose a frequency like every minute to get them to fire one after another - effectively every 6-7 hours, depending on the runtime, without gaps.

  • Brandon Hassler
    Options

    Didn't realize about the overlap! Although my situation is an odd one because 90% of the time for this particular Background Task of mine it will get a timeout error from Xano at some point. However, I can see evidence that the task is indeed still running (despite Xano saying it failed early).

    So in this case if I did every 6 hours, I would likely see overlap with the external API I'm calling since Xano start a new task despite the original task still finishing up.

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    Coming back to this one a little late: you can also set a "lock" value in the database or Redis to indicate the process is running - and the time it started. When your process finishes, it deletes/clears that value. Your script could run frequently but check that value for whether it should continue running, in case you are in that overlap situation.

    This is a well-established pattern, so you're in good company. Background processes and databases use lockfiles all the time to prevent parallel processes.