-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: run task with wront ctx & fill tests
- Loading branch information
1 parent
f16b9db
commit 94d95c3
Showing
12 changed files
with
180 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/midway-schedule/test/fixtures/app-load-schedule/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "app-load-schedule" | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/midway-schedule/test/fixtures/app-load-schedule/src/lib/schedule/hello.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
import { schedule } from '../../../../../../../midway'; | ||
|
||
@schedule({ | ||
type: 'worker', | ||
interval: 2333, | ||
}) | ||
export default class HelloCron { | ||
async exec(ctx) { | ||
ctx.logger.info(process.pid, 'hello'); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/midway-schedule/test/fixtures/egg-schedule/app/schedule/hello.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/midway-schedule/test/fixtures/egg-schedule/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "egg-schedule" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"name": "worker" | ||
"name": "worker", | ||
"scripts": { | ||
"build": "midway-bin build -c" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/midway-schedule/test/fixtures/worker/src/app/schedule/hello.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
File renamed without changes.
14 changes: 3 additions & 11 deletions
14
packages/midway-schedule/test/fixtures/worker/src/lib/schedule/interval.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,13 @@ | ||
'use strict'; | ||
|
||
import { schedule } from '../../../../../../../midway/dist'; | ||
// import * as fs from 'fs'; | ||
import { schedule } from '../../../../../../../midway'; | ||
|
||
@schedule({ | ||
type: 'worker', | ||
interval: 200, | ||
interval: 1000, | ||
}) | ||
export default class IntervalCron { | ||
async exec(ctx) { | ||
throw new Error('hahaha'); | ||
// console.log(1234); | ||
// ctx.logger.info('interval'); | ||
// ctx.app.coreLogger.info('hello world'); | ||
// fs.writeFileSync( | ||
// require('path').join(__dirname, '../../logs/worker/hello.log'), | ||
// 'hello world', | ||
// ); | ||
ctx.logger.info(process.pid, 'interval'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const mm = require('egg-mock'); | ||
const logDir = path.join(__dirname, '../logs'); | ||
|
||
process.setMaxListeners(0); | ||
|
||
if (!fs.existsSync(logDir)) { | ||
fs.mkdirSync(logDir); | ||
} | ||
|
||
export function app(name, options) { | ||
options = formatOptions(name, options); | ||
// mm.consoleLevel(options.consoleLevel || 'NONE'); | ||
const app = mm.app(options); | ||
app.close = () => { | ||
fs.rmdirSync(path.join(app.baseDir, 'run')); | ||
return app.close; | ||
}; | ||
return app; | ||
} | ||
|
||
export function cluster(name, options) { | ||
options = formatOptions(name, options); | ||
return mm.cluster(options); | ||
} | ||
|
||
export function formatOptions(name, options = {}) { | ||
return Object.assign( | ||
{}, | ||
{ | ||
baseDir: name, | ||
framework: path.join(__dirname, '../../midway'), | ||
// 默认关闭覆盖率,太慢 | ||
coverage: false, | ||
cache: false, | ||
}, | ||
options, | ||
); | ||
} |