Parse Cloud Code Job Function Optimization
I have a job on cloud code that I am running. It seems to work when I manually run the job. I think scheduling is posing an issue with its setup an frequency of running so I think
Solution 1:
Yes. It could be much better. I'd try something like this:
Parse.Cloud.job('updateReviews', async () => {
// Query all bookings with a status of confirmed
const query = new Parse.Query('bookings');
query.equalTo('status', 'confirmed');
const now = new Date();
query.greaterThanOrEqualTo('startTime', now);
query.lessThanOrEqualTo('startTime', new Date(now.getTime() + 60 * 60 * 1000));
const results = await query.find({ useMasterKey: true });
const pushType = "bookingConfirmed";
const pushQuery = new Parse.Query(Parse.Installation);
pushQuery.containedIn("userId", results.map(result => result.get('buyerId')).concat(results.map(result => result.get('placeOwner'))));
await Parse.Push.send({
where: pushQuery,
data: {
title: 'New Booking Coming Up',
alert: 'You have a booking coming up soon!',
pushType
}
}, { useMasterKey: true });
return (`Successfully sent ${results.length} new notifications!`);
});
Post a Comment for "Parse Cloud Code Job Function Optimization"