I want to run Cloud Code with scheduled Job in Parse.(sashido.io)
randomMentor function picks the some object in my Class
with random number and saving it Today
Class. When I call this method from Swift via PF.Cloud.callFunctionInBackground
it works pretty well.
But I couldn't work from the Parse Dashboard. I created a scheduled job in my Dashboard with pickTodaysMentor
name and it tries to run with Parse.cloud.run
closure. But it always return with: error loading cloud code Parse.Cloud.define is not a function
There is my 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) {
}
});
});
I am not a JS Developer so couldn't find any solution. I digged tutorials, guides and a search engine but no luck. I think error is too generic for finding the issue.
What do you think?