使用 setTimeout() 安排推送 [英] Using setTimeout() to Schedule pushes

查看:68
本文介绍了使用 setTimeout() 安排推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 Parse 上没有预定推送,我使用 setTimeout() 来安排推送.我正在使用 back4app.

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) 我的方法可靠吗?

1) Is my method reliable?

2) 这样做的缺点是什么?

2) What can the disadvantages of this be ?

3) 服务器上可以排队多少个 setTimeouts(),有什么限制吗?

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

T.I.A

推荐答案

为什么不使用调度的 cron 作业?我相信 back4app 支持 cron 工作.将必要的推送信息保存到数据库.然后每x"次运行一个云代码.如果推送时间到了,您的云代码会发送推送.SetTimeOut() 方法,我相信保留了云代码的实例或参考.这意味着您的云代码仍然在工作",即使它只是在等待,解析服务器应该保留它的实例.这意味着你浪费了你的资源.另外我相信 back4app 有一个云代码超时.即使您使用 setTimeOut() 一小时,云代码也会在超时后终止.

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.

这篇关于使用 setTimeout() 安排推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆