2017-03-11 3 views
0

私はこの問題は、それが唯一の最初のイベントに応答しているkueKueはイベントを正しく処理していませんか?

require('dotenv').load(); 
const mailer = require('../helper/mailer'); 
const kue = require('kue'), 
    queue = kue.createQueue(); 

console.log("Starting server"); 
queue.process('email',function(job,done){ 
    console.log(job.data); 
    mailer 
    .prepareContext(job.data) 
    .then(mailer.prepareBody) 
    .then(mailer.prepareMail) 
    .then(mailer.sendMail) 
    .then((data)=>{ 
     console.log("Mail sent"); 
    }) 
    .catch((err)=>{ 
     console.log(err.message); 
    }); 
}); 

queue.on('error',(err)=>{ 
    console.log(err); 
}); 

にメールを送信するために、次のコードを持っています。別のスクリプトを送信するにはスクリプトを再起動する必要があります。ここで何か間違っているのですか?私はドキュメント上でこれを見つけた

helper.sendVerificationMail = function(data){ 
    return new Promise(function(fullfill,reject){ 
    try{ 
     var ctx = {}; 
     ctx.from = "account"; 
     ctx.to_email = data.email; 
     ctx.subject = "Verifiy your email address"; 
     ctx.template = "signup"; 
     ctx.ctx = {}; 
     ctx.ctx.verification = data.verification; 
     queue.create('email',ctx).save(); 
     fullfill(data); 
    }catch(err){ 
     reject(err); 
    } 
    }); 
}; 

答えて

0

を使用してイベントを追加してい

Processing Concurrency 処理の同時実行

デフォルト(queue.processへの呼び出しでは)一度に一つの仕事を受け入れます処理のために。電子メールを送信するなどの小さなタスクの場合、これは理想的ではないため、番号を渡してこのタイプの最大アクティブジョブを指定することができます。

queue.process('email', 20, function(job, done){ 
    // ... 
}); 
関連する問題