使用setTimeout()安排推送次数

问题描述 投票:1回答:1

由于无法在Parse上使用计划的推送,因此我正在使用setTimeout()来计划推送。我正在使用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 });
}

我的代码工作正常。所以我的问题是这样的:

1)我的方法可靠吗?

2)这有什么缺点?

3)服务器上可以在队列中排队多少setTimeouts(),是否有任何限制?

T.I.A

parse-platform parse-server cloud-code back4app parse-javascript-sdk
1个回答
2
投票

您为什么不使用任职的cron工作?我相信back4app支持cron工作。将必要的推送信息保存到数据库。然后每“ x”次运行云代码。如果推送时间到了,您的云代码将发送推送。 SetTimeOut()方法,我相信保留云代码的位置或引用。这意味着即使只是等待,您的云代码仍在“工作”,Parse服务器应保留其实例。这意味着您浪费了资源。我也相信back4app有一个云代码超时。即使您使用setTimeOut()一小时,云代码也会在超时后终止。

© www.soinside.com 2019 - 2024. All rights reserved.