Does push_time property work for Cloud Code notifications?

53 views
Skip to first unread message

vhin...@gmail.com

unread,
Jan 11, 2017, 6:20:12 AM1/11/17
to back{4}app
I have a background job which once a day sends a notification to 10 groups of users. The notification to each group should fire 5 minutes after the previous one. I handled this with the push_time property of Parse.Push.send but it doesn't seem to be taken into account now. When I run the job and I check the push logs at https://parse-dashboard.back4app.com/apps/APP_ID/push/activity/all it says they all fired at the same time. 

So my question is - is the push_time parameter respected at all now? I'm adding my code below

Parse.Cloud.job("checkNotify", function(request, status) {


 
var promises = [];


 
for (var i = 0; i < 10; ++i) {
   
var query = new Parse.Query(Parse.Installation);
    query
.equalTo('channels', 'WatchList');
    query
.equalTo('deviceType', 'ios');
    query
.equalTo('notificationGroup', i+1);
   
// spread alerts between 5 minute intervals
   
var pushTime = new Date();
    pushTime
.setMinutes(pushTime.getMinutes() + (5*i));
    pushTime
.setSeconds(pushTime.getSeconds() + 5); // add 5 seconds so the push isn't sent in the past for the first wave
   
// expire in 1 day
   
var expirationTime = new Date();
    expirationTime
.setDate(pushTime.getDate() + 1);


   
var promise = Parse.Push.send({
        where: query,
            push_time: pushTime,
            expiration_time: expirationTime,
           data: {
             reason: "CheckWatch",
             sound: "",
             "content-available": 1
         }
       }, { useMasterKey: true });

     promises.push(promise);
  }

 
Parse.Promise.when(promises).then(
 
// success
 
function() {
 status
.success("Sucessfully sent out push to all groups.");
 
},
 
function(error) {
 status
.error("Error sending push notifications " + error.message);
 
});
});



Davi Macêdo

unread,
Jan 11, 2017, 7:30:32 AM1/11/17
to back{4}app
Yes. Push Time is not yet implementes in Parse Server. Maybe you can use setTimeout() function to schedule the following pushes.

Best!

vhin...@gmail.com

unread,
Jan 12, 2017, 6:31:45 AM1/12/17
to back{4}app
Thanks for the info, Davi.

My JS is not that great (only learned it for Cloud Code) so I'd be grateful if you can give me an example of how to use setTimeout in this case?

casag...@back4app.com

unread,
Jan 19, 2017, 12:42:23 PM1/19/17
to back{4}app
Hello!

When your job starts it will have a "setTimeout(function, <your_time_lapse_in_milliseconds>)" then you'll implement that for each of the groups the setTimeout method will use the previous milliseconds count plus five minutes.
This way it will send the pushes at every five minutes as long as there is a group to send, when there are no groups to send, the job ends.

Hope I was clear to understand, if I haven't though please contact us again. :)

Best!
Reply all
Reply to author
Forward
0 new messages