主要用来跑一些定时任务,比如获取某些服务配置
schedule写法(官网中有两种写法):
// app/schedule/setting.js
export default { schedule: { interval: ‘10s‘, // 每10 秒 执行一次 type: ‘all‘, // specify all `workers` need to execute },
//这个task是约定好的,而且必须是async函数 async task(ctx) { const settings = await ctx.service.ducc.getSetting() //具体的数据格式是自己决定的 if (settings && settings.data && settings.data.length > 0) { global.cache.ducc= setttings.data; } } }, };
原文:https://www.cnblogs.com/hellolol/p/11507886.html