Search code examples
backgroundparse-platformpush-notificationjobsparse-cloud-code

Parse.com pushnotification shedule error


I am trying to set a push notification background job. - I am getting following error while running the background job-

E2015-02-15T21:45:23.581Z] v20: Ran job push_job with: Input: {} Failed with: success/error was not called This is my code- Kindly help me to figure this out

 Parse.Cloud.job("push_job", function(request, response) {

Parse.Cloud.define('httpRequest', function(request, response) {

 Parse.Cloud.httpRequest({

  method: "POST",
  headers: {
  "X-Parse-Application-Id": "xxxxxxxcxxxxxxxxxxxxx",
  "X-Parse-REST-API-Key": "xxxxxxxxxxxxxxxxxxxxxx",
  "Content-Type": "application/json"
  },
body: {
   "data": {
    "alert": "Local push notification"
  }
 },
 url: "https://api.parse.com/1/push"
 }).then(function() {
response.success();
console.log("Successful push");
 }, function(error) {
response.error(error);
console.log(error);
});
});
}); 

Solution

  •    Parse.Cloud.job("PushNtfct_job_TimeEnable", function(request, status) {
    
       function dateFormat(date, format) {
    // Calculate date parts and replace instances in format string    accordingly
       format = format.replace("DD", (date.getDate() < 10 ? '0' : '') +   date.getDate());
     // Pad with 0 if needed
    format = format.replace("MM", (date.getMonth() < 9 ? '0' : '') + (date.getMonth() + 1));
    // Months are zero-based
      format = format.replace("YYYY", date.getFullYear());
     return format;
    }
    
       var Today = dateFormat(new Date(), "YYYY-MM-DD")+ "T01:25:00";
       // this will sent push notification at 1:25 am daily
     Parse.Push.send({
    channels: [ "" ],
     push_time: new Date(Today),
     data: {
     alert: "Today's Push"
      }
     }, { success: function() {
      console.log("Succuss with Time, Local Push notification time was sent    at : " + Today);
     }, error: function(err) {
      console.log(err);
     }
    }).then(function() {
      // Set the job's success status
      status.success("Successfully Ran");
    }, function(error) {
      // Set the job's error status
       status.error("damn error");
     });
     });