update_article.js(schedule目錄下):const Subscription = require('egg').Subscription;class UpdateArticleStatus extends Subscription { // 通過 schedule 屬性來設置定時任務的執行間隔等配置 static get schedule() { return { interval: '2s', // 1 分鐘間隔 type: 'all', // 指定所有的 worker 都需要執行 }; } * subscribe(ctx) { const res = yield ctx.service.article.getAllArticles(1); console.log(res); }}module.exports = UpdateArticleStatus;運行提示:excute error. Cannot read property 'service' of undefined我照官網的例子:module.exports = { schedule: { interval: '1m', // 1 分鐘間隔 type: 'all', // 指定所有的 worker 都需要執行 }, * task(ctx) { const res = yield ctx.curl('http://www.api.com/cache', { dataType: 'json', }); ctx.app.cache = res.data; },};發現curl屬性也是不能訪問
eggjs 在定時器訪問service提示Cannot read property
精慕HU
2019-02-27 12:27:58