ブルNodeJSで消費者を作成するための正しい方法は何ですか?

gimme4bucks:

私は、受信機は最初のメールにはまだ対応していない場合、24時間後にリマインダーメールを送信しますスケジュールされたジョブを作成しようとしているので。私はそれが電子メールを送信していない以外、これらのジョブと、これまでのすべての作業をスケジュールするブルを使用します。それはそれだけで何もしない機能に到達したときに実際には、エラーには、コードは何も以下ません。

'use strict'
const pool = require('../database')
const Mailer = require('../mailer')

module.exports = async (job) => {
    const query = `SELECT * FROM confirmations WHERE order_id = ${job.data.order_id} AND location_id = ${job.data.location_id}`
    console.log(query)

    const result = await pool.query(query)
    const order = result[0]

    if(!order.has_confirmed){
        console.log('Going to send reminders... ')
        console.log(order.reminders)
        if(order.reminders == 1){
            console.log('sending reminder 1') // This is is reached
            await Mailer.sendConfirmationMail(order.order_id, order.location_id, true, pool, 2)
            // Code placed here is not executed
        }else if(order.reminders == 2){
            const mail = console.log('sending reminder 2')
            await Mailer.sendConfirmationMail(order.order_id, order.location_id, true, pool, 3)

        }else if(order.reminders == 3){
            console.log('sending reminder 3')
            const mail = await Mailer.sendConfirmationMail(order.order_id, order.location_id, true, pool, 4)        

        } 
    }else{
        // if the receiver has confirmed the order the mail should expire without doing anything. 
        console.log('This job is expiring without doing anything...')
    }
}

私は何かが間違っをしましたか?Mailer.sendConfirmationMail(...)は、ビット大きいですが、私のアプリの他の部分から呼び出されたとき、それはメールを送信すると罰金を動作します。ヘルプは大歓迎しました!

EDIT:

メーラーは、機能のカップルを持っているクラスで、基本的な構造は次のとおりです。

class Mailer {
    static async sendConfirmationMail(orderId, locationId, reminder, pool, reminder number){
        console.log('inside Mailer')
        // check some stuff and do a db query
        this.addJobConfirmationQueue(orderId, locationId, reminders, pool)
        // send the email with the right info
    }
    static async addJobConfirmationQueue(orderId, locationId, reminders, pool){
         let day = 10000;
        //const day = 86400000; // milliseconds in a day
        const queue = Bull('checkConfrimation')
        queue.process(processCheckConfirmation)
        const job = await queue.add({
            order_id: order_id,
            location_id: location_id,   
        }, { delay: day })    

        const q =  `UPDATE confirmations
                    SET queue_id = ${pool.escape(job.id)}, reminders = ${pool.escape(reminders + 1)}
                    WHERE order_id = ${pool.escape(order_id)}
                    AND location_id = ${pool.escape(location_id)}`    
        const [rows, fields] = await pool.query(q)
    }
}

module.exports = Mailer

ログ私は本当にありません。私はそれが特定のポイントを通過した知っているので、私は特定のフレーズ(...)CONSOLE.LOG。コンソールログのチェーンは、次のとおりです。

  1. SQLクエリ
  2. 「リマインダーを送信するために行きます」
  3. リマインダの量
  4. 「リマインダー1を送信します」
gimme4bucks:

だからではなく、別のファイルの私は自分のメーラークラス内のすべてのコードを追加することによって、それを修正しました:

static async addJobConfirmationQueue(order_id, location_id, reminders, pool){

        const day = 86400000; // milliseconds in a day
        const queue = new Bull('checkConfirmation')

        queue.process(async (job) => {
            const query = `SELECT * FROM confirmations WHERE order_id = ${job.data.order_id} AND location_id = ${job.data.location_id}`

            const result = await pool.query(query)
            const order = result[0][0]

            if(!order.has_confirmed){
                if(order.reminders == 1){
                    this.sendConfirmationMail(order.order_id, order.location_id, true, pool, 2)

                }else if(order.reminders == 2){
                    this.sendConfirmationMail(order.order_id, order.location_id, true, pool, 3)

                }else if(order.reminders == 3){
                    this.sendConfirmationMail(order.order_id, order.location_id, true, pool, 4)        
                } 
            }else{
                // if the dealer has confirmed the order the mail should expire without doing anything. 
            }
        })
        const job = await queue.add({
            order_id: order_id,
            location_id: location_id,   
        }, { delay: day })    

        const q =  `UPDATE confirmations
                    SET queue_id = ${pool.escape(job.id)}, reminders = ${pool.escape(reminders + 1)}
                    WHERE order_id = ${pool.escape(order_id)}
                    AND location_id = ${pool.escape(location_id)}`    
        const [rows, fields] = await pool.query(q)
    }

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=343062&siteId=1