var campaignObj = {
title: row.title,
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();
}
}
});