Skip to content

Commit

Permalink
fix: agent not work
Browse files Browse the repository at this point in the history
  • Loading branch information
Lellansin authored and czy88840616 committed Nov 15, 2018
1 parent 94d95c3 commit f43c553
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/midway-schedule/lib/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import loadSchedule from './load_schedule';
const BaseSchedule = require('egg-schedule/lib/schedule');
const loadEggSchedule = require('egg-schedule/lib/load_schedule');

const M_STRATEGY: string = Symbol('strategy') as any;
const M_STRATEGY_INSTANCE: string = Symbol('strategy_instance') as any;
Expand All @@ -28,7 +29,8 @@ module.exports = class Schedule extends BaseSchedule {
}

loadSchedule() {
const scheduleItems = loadSchedule(this.agent);
const scheduleItems = loadEggSchedule(this.agent);
loadSchedule(this.agent);

for (const k of Object.keys(scheduleItems)) {
const { key, schedule } = scheduleItems[k];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let i = 1;

exports.task = async (ctx) => {
console.log('hasdf');
ctx.logger.info(process.pid, 'hehehehe', i++);
};

exports.schedule = {
type: 'worker',
interval: 1000,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

exports.logrotator = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "worker-egg-schedule"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import { schedule } from '../../../../../../../midway';
})
export default class IntervalCron {
async exec(ctx) {
ctx.logger.info(process.pid, 'interval');
ctx.logger.info(process.pid, 'hello decorator');
}
}
16 changes: 14 additions & 2 deletions packages/midway-schedule/test/schedule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,19 @@ describe('test/schedule.test.ts', () => {
assert.deepEqual(item.schedule, { type: 'worker', interval: 1000 });
});

it('should support interval with @schedule decorator', async () => {
it('should support exec app/schedule/*.js (for egg)', async () => {
const name = 'worker-egg-schedule';
application = cluster(name, {
typescript: false,
worker: 2,
});
await application.ready();
await sleep(5000);
const log = getLogContent(name);
assert(contains(log, 'hehehehe') === 4, '未正确执行 4 次');
});

it('should support interval with @schedule decorator (both app/schedule & lib/schedule)', async () => {
const name = 'worker';
application = cluster(name, {
typescript: true,
Expand All @@ -47,7 +59,7 @@ describe('test/schedule.test.ts', () => {
await application.ready();
await sleep(5000);
const log = getLogContent(name);
assert(contains(log, 'interval') === 4, '未正确执行 4 次');
assert(contains(log, 'hello decorator') === 4, '未正确执行 4 次');
});
});
});
Expand Down

0 comments on commit f43c553

Please sign in to comment.