0

I'm using Cloud Functions as a server for a multiplayer game.

Is there a way to set a cloud function to execute some code or call another function in X seconds/minutes? I know about cron jobs and I'm already using them, but what I want to achieve now is different.

I want the function to schedule a future execution of the same or some other function:

exports.testFunction = functions.database.ref('...').onCreate(event => {

   //do stuff now

   //do the following in 120 seconds or schedule another function

});

PS. I knew that the limit that a function can run was 100 seconds. Is it now increased to 540 seconds?

steliosf
  • 3,669
  • 2
  • 31
  • 45
  • There is currently no scheduling of any sort. – Doug Stevenson May 04 '18 at 16:14
  • Not a duplicate of the question you specified. I'm not talking about cron-jobs, I need to dynamically schedule a task from within the function. The time is not fixed, it depends on when I'll get that specific call of the function. In any case, if I want to schedule a task to execute after 120 seconds within the function, should I keep the cloud function running for this time interval? Something like `sleep(120)` and then execute the code? – steliosf May 04 '18 at 18:37
  • There are no forms of scheduling in Cloud Functions, neither at-time nor delayed-time. A function can only run to completion or time out. It can't arrange for other work to be done on delay after it completes. – Doug Stevenson May 04 '18 at 18:39
  • If you want to use setTimeout to pause execution, you can do that, but you're paying for the time and memory consumed while the function is waiting to continue. – Doug Stevenson May 04 '18 at 18:39
  • Yes the cost will definitely increase that's why I asked whether there's any alternative solution. Thanks for the help. – steliosf May 04 '18 at 21:47

0 Answers0