简体   繁体   中英

is it possible to use setTimeout() in firebase cloud functions?

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM