gpt4 book ai didi

node.js - 在 kue 中将作业添加到队列

转载 作者:搜寻专家 更新时间:2023-10-31 23:49:17 26 4
gpt4 key购买 nike

根据 kue 文档,创建队列和添加作业很容易,但我无法了解作业的存储方式

var kue = require('kue')
jobs = kue.createQueue();

添加工作

jobs.create('email', {
title: 'welcome email for tj'
, to: 'tj@learnboost.com'
, template: 'welcome-email'
}).priority('high').save();

这个例子很容易理解,但是,如果我需要更多的选择,比如在这个例子中,比如添加一个广告选项 - , ad: 'we are the best'

jobs.create('email', {
title: 'welcome email for tj'
, to: 'tj@learnboost.com'
, ad: 'we are the best'
, template: 'welcome-email'
}).priority('high').save();

我该怎么做呢?

最佳答案

jobs.create 的第二个参数是一个可以在作业处理器中访问的对象。你可以把你想要的任何字段放在那里。然后,一旦您设置了处理器,您就可以使用“广告”字段。

添加到您的示例中:

jobs.process('email', function (job, done) {
var advertOption = job.data.ad;

// Do your emailing stuff, like rendering template and sending...

});

如果你给出三个参数,你可以指定你想要的 worker 数量:

jobs.process('email', 1, function (job, done) { // samesame

associated source易于阅读且评论很好

关于node.js - 在 kue 中将作业添加到队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15862568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com