在 parse.com 中保存对象后计划后台作业
schedule background job after save object in parse.com
我有以下逻辑,想使用 parse 实现它
1) 添加带有计划时间的提要对象2) 保存对象后 -->调度将在源调度时间运行的后台作业3) 当提要计划时间到来时,使用解析安装向用户发送带有提要数据的推送通知
我的代码如下:
Parse.Cloud.afterSave("Feed", function(request) {
// schedule background job here
});
// this is the code of my cloud job
Parse.Cloud.job("schedulePush", function(request, status) {
Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.Installation);
var message = {"message" : "Hello world!"}
query.each(function(installation) {
Parse.Push.send({
where:query,
data: {
"notification_info": {"message" : "hello world!"}
},
}
).then(function() {
console.log("Push was sent successfully | " + message)
}, function(error) {
response.error("Push failed to send with error: " + error.message);
});
}).then(function() {
status.success("schedulePush completed successfully.");
}, function(error) {
status.error("Uh oh, something went wrong." + error.message);
});
});
首先,更改
Parse.Cloud.job("schedulePush", function(request, status) {
自
Parse.Cloud.define("schedulePush", function(request, response) {
因为它可以是一个常规函数(请注意,超时时间为 15 秒)。这也意味着将status.success
和status.error
更改为 response.success
和 response.error
.
其次,你的顶级功能需要是:
Parse.Cloud.afterSave("Feed", function(request) {
// schedule background job here
Parse.Cloud.run("schedulePush", function(request, response) {
// handle response here
});
});
我在无法运行它的情况下键入了它,所以我可能会偏离一两个语法点。但这可以让您了解需要做什么。
相关文章:
- cron作业与Javascript计时事件
- 与运行长作业(javascript,node.js)的第三方API同步的最佳实践
- 在 parse.com 中保存对象后计划后台作业
- MEANIO群集(共4个)对于计划作业仅运行一次
- 无法部署分析后台作业
- 使用节点计划计划作业
- 分析作业未按计划计时间隔运行
- 为用户计划和配置分析作业
- 使用解析服务器的后台作业&Heroku调度器
- 使用节点 JS 运行连续后台作业
- Parse.com后台作业云代码无法调用方法'那么'的未定义
- 如何从解析云中获取完整的用户详细信息,并将其用于后台作业功能
- 如何设置查询.限制后台作业
- 引用解析.后台作业中的用户
- 计划抓取作业-流星JS
- 我怎么能有一个解析后台作业循环通过一个函数为每个用户
- 云代码解析RSS CDATA后台作业
- 分析后台作业添加多条记录导致错误
- 如何将后台作业转换为类似函数的内容
- 解析后台作业不保存文本文件