Run background functions at certain time (delay the execution)

Hi there! First a little context :slight_smile:

I’m building a massively multiplayer “real-time” strategy game that runs in browser and on mobile, akin to the old games of the late 90s and 00s, like Planetarion, Starsphere and more “modern” games like OGame. I want the game to feel “real-time”, and so what that means is that I can construct a building, then let’s say, 2 minutes later, that construction is “completed” by a background function.

Í can’t seem to find any documentation on delaying background functions, and this is honestly the main stumbling block for me in using netlify for this project. Be great if someone could either show me where the docs exist, or show how such a feature could be handled securely, using netlify.

Have you checked out:

I have, and it’s completely unnecessary (and expensive) to do it that way. I want one background job, executed at an exact time. Else I need to run scheduled functions every second, and check an entire database for updates/notifications to be sent out, not gonna work I’m afraid.

Hi, @Oddman. I think there are some additional details which are known to you but not to our support team. Maybe some Q&A can resolve this. If you answer the questions below, the information might help us to give you a more helpful answer.

  • Will you know in advance when you need the scheduled function to be run? If so, how far in advance will you know the time the function should be run?

  • How frequently do you estimate the functions will need to be run?

  • How long does it take to execute the code in a single run of the function?

No worries, thanks for responding.

Yes, I’ll know exactly when it needs to run.

They’ll run as often as is required, because of the nature of the game. If an attack is made against a player by 10 other players at different times but aiming to arrive around the same time, we could have 10 jobs running at once, or very close to that time window. Additionally, when other things “complete”, these jobs need to run. I’ve thought about this being a cronjob that runs every second, but this imposes huge read costs on the database to check for every single kind of timer that needs to execute every second.

Code execution is pretty quick - 50-100ms at most.

Just want to add, I can do this very, very easily with traditional server setups - have a background job, delay it to the exact time, and “bob’s your uncle”.

I feel the Netlify system can and should support this, it’s just a question of whether you will. Other systems do, such as Google firebase, using Cloud tasks.

One of the reasons I want to use the cloud for this, is that I can do this using background servers, and manage a bunch of queues so that these jobs are handled as soon as they come in, but it’s infra I dont want to have to manage :slight_smile:

Sounds like you need to dynamically configure the timing. That’s not possible and won’t be in the foreseeable future because Netlify needs to do a successful deploy to update any of your settings for the Cron execution. That’s an underlying architecture that’s not set to change.

Yeah, that’s right - I need to dynamically configure timing.

Shame you guys won’t do this, but thanks for the transparency. I can certainly see why it might be a pain.

1 Like