Skip to content

Commit

Permalink
fix: app.runSchedule task key
Browse files Browse the repository at this point in the history
  • Loading branch information
Lellansin committed Jan 28, 2019
1 parent a2f21b0 commit 29249e9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/midway-schedule/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as qs from 'querystring';
import * as path from 'path';
import loadSchedule from './lib/load_schedule';
import * as fs from 'fs';

const loadEggSchedule = require('egg-schedule/lib/load_schedule');

Expand All @@ -16,19 +17,26 @@ module.exports = (app) => {
loadSchedule(app);

// for test purpose
app.runSchedule = (schedulePath) => {
app.runSchedule = (schedulePath, key = 'default') => {
if (!path.isAbsolute(schedulePath)) {
schedulePath = path.join(
app.config.baseDir,
'app/schedule',
schedulePath,
);
if (!fs.existsSync(schedulePath)) {
schedulePath = path.join(
app.config.baseDir,
'lib/schedule',
schedulePath,
);
}
}
schedulePath = require.resolve(schedulePath);
let schedule;

try {
schedule = schedules[schedulePath];
schedule = schedules[schedulePath] || schedules[schedulePath + '#' + key];
if (!schedule) {
throw new Error(`Cannot find schedule ${schedulePath}`);
}
Expand Down

0 comments on commit 29249e9

Please sign in to comment.