mm_scheduler 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +16 -18
- package/lib/scheduler.js +18 -0
- package/package.json +28 -25
- package/test.js +18 -2
package/index.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
module.exports = Scheduler;
|
|
1
|
+
const Scheduler = require('./lib/scheduler');
|
|
2
|
+
const Admin = require('mm_corejs').Admin;
|
|
3
|
+
|
|
4
|
+
const admin = new Admin();
|
|
5
|
+
admin.setClass(Scheduler);
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
Scheduler,
|
|
9
|
+
admin,
|
|
10
|
+
schedulerAdmin(scope, config = {}) {
|
|
11
|
+
if (!scope) {
|
|
12
|
+
scope = 'os';
|
|
13
|
+
}
|
|
14
|
+
return admin.get(scope, config);
|
|
15
|
+
}
|
|
16
|
+
};
|
package/lib/scheduler.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Scheduler —— 任务调度模块。
|
|
5
|
+
*
|
|
6
|
+
* 骨架已就绪:构造时接收配置对象,具体功能待开发。
|
|
7
|
+
*/
|
|
8
|
+
class Scheduler {
|
|
9
|
+
/**
|
|
10
|
+
* 构造函数
|
|
11
|
+
* @param {Object} [config] 模块配置
|
|
12
|
+
*/
|
|
13
|
+
constructor(config = {}) {
|
|
14
|
+
this.config = config;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = Scheduler;
|
package/package.json
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
2
|
+
"name": "mm_scheduler",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "任务调度模块:提供任务的注册与调度管理能力",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://gitee.com/qiuwenwu91/mm_scheduler.git"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"mm_mod",
|
|
12
|
+
"mm_infra",
|
|
13
|
+
"scheduler",
|
|
14
|
+
"调度"
|
|
15
|
+
],
|
|
16
|
+
"layer": "infra",
|
|
17
|
+
"group": "common",
|
|
18
|
+
"author": "邱文武",
|
|
19
|
+
"license": "ISC",
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18.0.0"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"test": "node test.js"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"mm_corejs": "^1.1.6"
|
|
28
|
+
}
|
|
29
|
+
}
|
package/test.js
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const assert = require('assert');
|
|
4
|
-
const
|
|
4
|
+
const mod = require('./index.js');
|
|
5
5
|
|
|
6
|
+
// 1. 导出结构校验
|
|
7
|
+
assert.strictEqual(typeof mod.Scheduler, 'function', '应导出 Scheduler 类');
|
|
8
|
+
assert.ok(mod.admin, '应导出 admin 实例');
|
|
9
|
+
assert.strictEqual(typeof mod.schedulerAdmin, 'function', '应导出 schedulerAdmin 函数');
|
|
10
|
+
|
|
11
|
+
const { Scheduler } = mod;
|
|
12
|
+
|
|
13
|
+
// 2. 实例化与默认配置
|
|
6
14
|
const instance = new Scheduler();
|
|
7
15
|
assert.ok(instance instanceof Scheduler, 'instance 应为 Scheduler 实例');
|
|
8
16
|
assert.deepStrictEqual(instance.config, {}, '默认配置应为空对象');
|
|
9
17
|
|
|
10
|
-
|
|
18
|
+
// 3. 传入配置
|
|
19
|
+
const configured = new Scheduler({ cron: '* * * * *' });
|
|
20
|
+
assert.deepStrictEqual(configured.config, { cron: '* * * * *' }, '应保存传入的配置');
|
|
21
|
+
|
|
22
|
+
// 4. 工厂函数返回 Scheduler 实例
|
|
23
|
+
const scoped = mod.schedulerAdmin('test');
|
|
24
|
+
assert.ok(scoped instanceof Scheduler, 'schedulerAdmin 应返回 Scheduler 实例');
|
|
25
|
+
|
|
26
|
+
console.log('mm_scheduler test passed');
|