我只是想在我的工作职能中简单地调用云功能。
这是我的代码。
Parse.Cloud.job("helloTest", function(request, status) {
Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.User);
query.each(function(user){
console.log("started job helloTest");
Parse.Cloud.run("hello", {}, {
success: function(output) {
console.log("result from hello: ");
console.log(output);
},
error: function(error) {
console.log("hello failed");
}
});
}).then(function() {
status.success("Weather push notifications have been sent.");
}, function(error) {
status.error(error.message);
});
});
这是hello函数。
Parse.Cloud.define("hello", function(request, response) {
response.success("Hello world!");
});
所以基本上每个用户都运行该功能。
I2014-07-20T00:00:29.829Z] v298:云端功能问候你好: 输入:{} 结果:Hello world! I2014-07-20T00:00:29.839Z]开始工作helloTest
I2014-07-20T00:00:29.850Z]开始工作helloTest
I2014-07-20T00:00:29.861Z]开始工作helloTest
I2014-07-20T00:00:29.868Z]开始工作helloTest
I2014-07-20T00:00:29.880Z]开始工作helloTest
I2014-07-20T00:00:29.891Z]开始工作helloTest
I2014-07-20T00:00:29.903Z]开始工作helloTest
所以基本上发生的事情是它遍历我的用户表,但它不会调用hello云功能成功。如果" Ran云功能你好,不应该: 输入:{} 结果:Hello world!" 打印到控制台然后我应该自动踢到cloud.run的成功功能?
提前感谢您的帮助!
答案 0 :(得分:0)
它在空结果上运行each
,然后运行成功块。结果是空的,因为您在一个不存在的类上运行查询。
问题在于您要查询User
类,这是一种特殊情况(实际名称为_User
)。您应该按如下方式查询用户
var query = new Parse.Query(Parse.User);
然后,您的查询将包含要处理的实际行,您将获得更好的结果。
注意:Role
和Installation
类的工作方式相同。
关于在作业中运行云功能,我在main.js中创建了以下测试:
Parse.Cloud.define("hello", function(request, response) {
response.success("Hello world!");
});
Parse.Cloud.job("helloTest", function(request, status) {
console.log("started job helloTest");
Parse.Cloud.run("hello", {}, {
success: function(output) {
console.log("result from hello: ");
console.log(output);
status.success("test worked");
},
error: function(error) {
console.log("hello failed");
status.error(error);
}
});
});
获得以下记录输出:
I2014-07-19T23:48:21.262Z] started job helloTest
I2014-07-19T23:48:21.312Z] v37: Ran cloud function hello with:
Input: {}
Result: Hello world!
I2014-07-19T23:48:21.375Z] result from hello:
I2014-07-19T23:48:21.445Z] Hello world!
答案 1 :(得分:0)
我能从parse.run调用中获取任何内容的唯一方法是,如果我将作业状态置于调用成功之内。如果我想在同一个工作中进行多个云调用,我将不得不嵌套云调用,而在最低的孩子中,我必须在任何人返回之前将该成功调用。通过将作业消息放入cloud.run调用可能有更好的方法来实现这一点,但是我想要做的就是实现它的最简单方法。