Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

egg怎么开启多个固定时间的定时任务

如题,例如在7点执行一次,12点执行一次,23点执行一次,看了文档的动态配置,

动态配置定时任务

有时候我们需要配置定时任务的参数。定时任务还有支持另一种写法:

module.exports = app => {
 return {
    schedule: {
        interval: app.config.cacheTick,
        type: 'all',
    },
 async task(ctx) {
    const res = await ctx.curl('http://www.api.com/cache',      {
        contentType: 'json',
       });
 ctx.app.cache = res.data;
        },
    };
};

实在搞不懂app.config.cacheTick是怎么做到动态的,麻烦大佬帮忙解惑


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

可以写成 corn 表达式

module.exports = {
 schedule: {
    cron: '0 0 7,12,23 * * *'
 }
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...