1

I was wondering if Schedule Push is available on Parse Server? (I'm using Back4App)

Here is my cloud code:

Parse.Cloud.define("pushMultiple",async (request) => {  
    //Getting Current Date instance
    var d = new Date();
    //Where I live Current Hour is 14, so setting it to 15
    d.setHours(15);     
    //Sending push to a specific device
    return Parse.Push.send({
            push_time: d,
            channels: [ "t1g.com"],
            data: {alert: "The Giants won against the Mets 2-3."}   
            },{ useMasterKey: true });
});

But the code does not seem to be working. The push is sent out immediately.

And if it's not possible, please let me know how I can schedule push using a Cloud Job. A code snippet would be very helpful. Also will the Cloud Job stop running after it has completed sending the push?

Tanzim Chowdhury
  • 3,020
  • 2
  • 9
  • 21

1 Answers1

2

According to this document setHours method doesnt add your value to your date but just replace it.

Try this:

var extraTime = 1000*60*60*15; //15 hours
var currentDate = new Date();
//since date object is just number we can add our extra time to our date.
var pushDate = currentDate + extraTime; //push date is 15 hours later than now

return Parse.Push.send({
            push_time: pushDate,
            channels: [ "t1g.com"],
            data: {alert: "The Giants won against the Mets 2-3."}   
            },{ useMasterKey: true });

Edit: Parse docs says push_time is not supported yet. https://docs.parseplatform.org/parse-server/guide/#push-notifications

Docs can be outdated or if you are using back4app, they may be implemented this feature to their servers.

uzaysan
  • 583
  • 1
  • 4
  • 18