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

阅读 3.7k
1 个回答

可以写成 corn 表达式

module.exports = {
 schedule: {
    cron: '0 0 7,12,23 * * *'
 }
};
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题