Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

如题,例如在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是怎么做到动态的,麻烦大佬帮忙解惑


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.7k views
Welcome To Ask or Share your Answers For Others

1 Answer

可以写成 corn 表达式

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...