gpt4 book ai didi

node.js - 将作业保存到 Node 中的议程时防止立即执行

转载 作者:太空宇宙 更新时间:2023-11-04 03:00:25 24 4
gpt4 key购买 nike

我正在使用由 MongoDB 支持的agenda.js 和 Node 来处理批处理作业。我使用的当前语法遇到的一个问题是安排一个重复事件,但没有立即执行它。我知道“skipImmediate: true”标志,但我不清楚我需要在当前配置中使用 IIFE 的位置应用该标志:

  agenda.define('test job', {
priority: 'high',
concurrency: 10
}, async job => {
const {
to
} = job.attrs.data;
job.repeatEvery('0 11 * * 1-5', {
skipImmediate: true
});
await send(to);
});

function send(to) {
const today = new Date();
const target = to;
const time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
console.log(`Emailing to ${target} regarding second job, at ${time}.`);
}

(async function () {
await agenda.start();
agenda.create('test job', {
to: 'someone@email.com',
from: 'sample@email.com'
}).save();
})();
};

如你所见,我...

{ skipImmediate: true }

...在repeatEvery block 中,但它似乎不起作用。如何防止使用当前配置立即执行?

最佳答案

我认为你使任务变得复杂,这可能适合你的情况

agenda.define('test job', {
priority: 'high',
concurrency: 10
}, async job => {
const {
to
} = job.attrs.data;
const today = new Date();
const target = to;
const time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
console.log(`Emailing to ${target} regarding second job, at ${time}.`);
});

这是为了打电话

;(async function() {
const returned = agenda.create('test job', {
to: 'someone@email.com',
from: 'sample@email.com'
})
await agenda.start();
await returned.repeatEvery('0 11 * * 1-5', {
skipImmediate: true
}).save()
})();

它的作用是define将定义您的议程应该做什么,然后您使用参数创建议程并启动它。它返回Job,您可以使用repeatEvery

重复它

关于node.js - 将作业保存到 Node 中的议程时防止立即执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58327099/

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