Using setTimeout() to Schedule pushes

拜拜、爱过 提交于 2020-07-09 14:47:06

问题


Since Scheduled push is not available on Parse , I'm using setTimeout() to schedule pushes. I'm using back4app.

// I call this cloud code
Parse.Cloud.define("pushMultiple",async (request) => {
//Using set timeout to send out a push 1 hour later
  setTimeout(pushout,100000);
});

//The function to send Notificaiton 
const pushout = () => {
        Parse.Push.send({
          channels: [ "t1g.com"],
          data: {alert: "The Giants won against the Mets 2-3."}
         },{ useMasterKey: true });
}

My code works fine. So my question is this:

1) Is my method reliable?

2) What can the disadvantages of this be ?

3) How many setTimeouts() can be queued on the server, is there any sort of limit ?

T.I.A


回答1:


Why don't you use sheduled cron jobs? I believe back4app supports cron jobs. Save necessary push information to database. Then run a cloud code every "x" time. If push time is come your cloud code sends the push. SetTimeOut() method , I believe keeps the istance or reference of cloud code. Which means your cloud code is still "working" even its just waiting, Parse server should be keeping the instance of it. That means you wast your resources. Also I believe back4app has a cloud code timeout. Even you use setTimeOut() for one hour cloud code will be terminated after timeout.



来源:https://stackoverflow.com/questions/61181249/using-settimeout-to-schedule-pushes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!