我想在Parse中使用计划的作业运行Cloud Code。(sashido.io)
randomMentor 函数以随机数选择Class
中的某个对象并将其保存为Today
类。当我通过PF.Cloud.callFunctionInBackground
从Swift调用此方法时,它有效很好。
但是我无法从 Parse Dashboard 中进行工作。我在仪表板中创建了一个名为pickTodaysMentor
的计划作业,该作业尝试使用Parse.cloud.run
关闭运行。 但它总是返回: error loading cloud code Parse.Cloud.define is not a function
有我的functions.js;
Parse.Cloud.define('randomMentor', async function (request, response) {
var Mentor = Parse.Object.extend('Mentor');
var countQuery = new Parse.Query(Mentor);
const count = await countQuery.count();
const query = new Parse.Query('Mentor');
const randomInt = Math.floor(Math.random() * count);
query.equalTo('position', randomInt);
query.limit(1); // limit to at most 10 results
const results = await query.find();
const Today = Parse.Object.extend('Today');
const today = new Today();
today.set('mentor', results[0]);
today.save()
.then((today) => {
response.success("Today Mentor Created.");
}, (error) => {
response.error(error);
});
response.success("Today Mentor Created.");
});
Parse.Cloud.job('pickTodaysMentor', (request) => {
const { params, headers, log, message } = request;
message("I just started");
Parse.Cloud.run('randomMentor', {}, {
success: function (result) {
},
error: function (error) {
}
});
});
我不是JS开发人员,所以找不到任何解决方案。我挖了教程,指南和谷歌,但没有运气。我认为错误对于发现问题过于笼统。
您如何看待?
非常感谢您的编码...
答案 0 :(得分:0)
The error you are receiving means that your Cloud Code function is invalid.
It should look something like this in versions of Parse Server 3.0.0 and above:
Parse.Cloud.define("function", async (request) => {
return "Hello World";
});