Monday, 15 May 2017

node js scheduler iterates 3 times while it supposed to Fire only one Time

i'm trying to schedule a message everyday at 8:00 GMT . The schedule works , the message is sent but 3 times a row . why is that ? here is my code : const schedule=require('node-schedule'); const rule=new schedule.RecurrenceRule();

function scheduleCours(senderId, message)
{



rule.dayOfWeek=[0,new schedule.Range(0,6)];
rule.hour=8;
rule.minute=0;


       j= schedule.scheduleJob(rule, function(){
    var messageData=
   {
       recipient:
       {
           id:senderId
       },
        message: {
  attachment: {
    type: "template",
    payload: {
      template_type: "button",
        text:message ,
        buttons: [{
          type: "postback",
          title: "J'ai fini",
          payload: "fini"
        },{
            type:"postback",
            title:"Annuler",
            payload:"Annuler"
        }

          ]
      }
  }
}

   };
    callSendAPI(messageData);

});  


 }

when i call j.cancel() after callSendApi(data) it also iterate three times the message . i have looked online but mostly found responses related to cron. Can someone tell me what is the problem here please ..?



via Jean Ouédraogo

No comments:

Post a Comment