i am wondering if it is possible to use setTimeout() in cloud functions
let millisecond = (day *24*60*60*1000) (hour* 60*60*1000) (min *60*1000) (second *1000);
setTimeout(() => {
admin.firestore().doc("timer/" chatroom).set({
"millisecond":millisecond,
"username":username,
"tousername":tousername,
"day":day,
"min":min,
"second":second,
"hour":hour,
}, millisecond);
if not possible is there a way to accomplish this idea ? also am i billed as much as the function is active? thank you
CodePudding user response:
Using setTimeout
in a Cloud Function is possible, but keep in mind that:
- a function can run at most 9 minutes (1st generation) or 60 minutes (2nd generation) (see docs)
- you pay for the entire time a function is active this way
So if you need to wait for significant time (I usually use 30s as a threshold for this), consider using another mechanism to delay operations such as scheduling a callback with Cloud Tasks.