kue scheduler error handling

33 views
Skip to first unread message

vadiraj bidarahalli

unread,
Oct 6, 2016, 10:39:56 AM10/6/16
to nodejs
I am usinh kue for scheduling jobs that run at specific intervlas like daily, weekly, monthly etc...
Also from the ui when a campaign is created , a job is created and pushed to the kue.
Now my problem is whenever there is a problem with redis connection, the functions like kue.create, kue.get, kue.delete  never return error and are somehow lost forever,
I have no way of telling the user, "hey, there is some technical problem. the campaign could not be scheduled".
Here is a part of my code..  The one i am talking about is the part of code that says 'Job Creation failed'  .. if there is a problem with redis connection, the save() function never calls back and my promise keeps hanging.. neither resolved nor rejected

 var campaignObj = {
          title: row.title,
          id: row.id,
          emailList: campaignJSON.emailList,
          clientId: row.clientId,
          emailText: step.emailText,
          startDate: campaignJSON.startDate,
          endDate: campaignJSON.endDate,
          stepIndex: idx,
          type: 'delay'
        };

        var newJobStep;

        console.log('the step is', step);

        if ([undefined, null, 'null'].indexOf(step.jobId) !== -1) {
          //newly added delay campaign
          //schedule the step
          newJobStep = jobQueue.create('campaign-jobs', campaignObj).delay(stepDelay).removeOnComplete(true)
            .save(function(err) {

              if (err) {
                console.log('Job creation failed');
                if (idx === campaignJSON.steps.length - 1) {
                  defered.reject('Error creating the job for the step ', idx + 1);
                }
              } else {
                step.jobId = newJobStep.id;
                console.log('saving json', campaignJSON.steps[idx]);
                self.saveCampaignJSON(campaignJSON, row.id);
                if (idx === campaignJSON.steps.length - 1) {
                  defered.resolve();
                }
              }
            });


Reply all
Reply to author
Forward
0 new messages