@celljs/schedule 3.0.0

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.
Files changed (89) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/cell.yml +0 -0
  4. package/lib/node/annotation/cron.d.ts +11 -0
  5. package/lib/node/annotation/cron.d.ts.map +1 -0
  6. package/lib/node/annotation/cron.js +17 -0
  7. package/lib/node/annotation/cron.js.map +1 -0
  8. package/lib/node/annotation/index.d.ts +3 -0
  9. package/lib/node/annotation/index.d.ts.map +1 -0
  10. package/lib/node/annotation/index.js +19 -0
  11. package/lib/node/annotation/index.js.map +1 -0
  12. package/lib/node/annotation/scheduler.d.ts +10 -0
  13. package/lib/node/annotation/scheduler.d.ts.map +1 -0
  14. package/lib/node/annotation/scheduler.js +29 -0
  15. package/lib/node/annotation/scheduler.js.map +1 -0
  16. package/lib/node/application-lifecycle.d.ts +12 -0
  17. package/lib/node/application-lifecycle.d.ts.map +1 -0
  18. package/lib/node/application-lifecycle.js +71 -0
  19. package/lib/node/application-lifecycle.js.map +1 -0
  20. package/lib/node/constants.d.ts +5 -0
  21. package/lib/node/constants.d.ts.map +1 -0
  22. package/lib/node/constants.js +8 -0
  23. package/lib/node/constants.js.map +1 -0
  24. package/lib/node/cron-expression.d.ts +86 -0
  25. package/lib/node/cron-expression.d.ts.map +1 -0
  26. package/lib/node/cron-expression.js +90 -0
  27. package/lib/node/cron-expression.js.map +1 -0
  28. package/lib/node/error/errors.d.ts +10 -0
  29. package/lib/node/error/errors.d.ts.map +1 -0
  30. package/lib/node/error/errors.js +20 -0
  31. package/lib/node/error/errors.js.map +1 -0
  32. package/lib/node/error/index.d.ts +2 -0
  33. package/lib/node/error/index.d.ts.map +1 -0
  34. package/lib/node/error/index.js +18 -0
  35. package/lib/node/error/index.js.map +1 -0
  36. package/lib/node/factory/cron-job-factory.d.ts +8 -0
  37. package/lib/node/factory/cron-job-factory.d.ts.map +1 -0
  38. package/lib/node/factory/cron-job-factory.js +29 -0
  39. package/lib/node/factory/cron-job-factory.js.map +1 -0
  40. package/lib/node/factory/factory-protocol.d.ts +7 -0
  41. package/lib/node/factory/factory-protocol.d.ts.map +1 -0
  42. package/lib/node/factory/factory-protocol.js +5 -0
  43. package/lib/node/factory/factory-protocol.js.map +1 -0
  44. package/lib/node/factory/index.d.ts +3 -0
  45. package/lib/node/factory/index.d.ts.map +1 -0
  46. package/lib/node/factory/index.js +19 -0
  47. package/lib/node/factory/index.js.map +1 -0
  48. package/lib/node/index.d.ts +8 -0
  49. package/lib/node/index.d.ts.map +1 -0
  50. package/lib/node/index.js +24 -0
  51. package/lib/node/index.js.map +1 -0
  52. package/lib/node/module.d.ts +4 -0
  53. package/lib/node/module.d.ts.map +1 -0
  54. package/lib/node/module.js +6 -0
  55. package/lib/node/module.js.map +1 -0
  56. package/lib/node/registry/index.d.ts +3 -0
  57. package/lib/node/registry/index.d.ts.map +1 -0
  58. package/lib/node/registry/index.js +19 -0
  59. package/lib/node/registry/index.js.map +1 -0
  60. package/lib/node/registry/registry-protocol.d.ts +12 -0
  61. package/lib/node/registry/registry-protocol.d.ts.map +1 -0
  62. package/lib/node/registry/registry-protocol.js +5 -0
  63. package/lib/node/registry/registry-protocol.js.map +1 -0
  64. package/lib/node/registry/scheduler-registry.d.ts +14 -0
  65. package/lib/node/registry/scheduler-registry.d.ts.map +1 -0
  66. package/lib/node/registry/scheduler-registry.js +61 -0
  67. package/lib/node/registry/scheduler-registry.js.map +1 -0
  68. package/lib/package.spec.d.ts +1 -0
  69. package/lib/package.spec.d.ts.map +1 -0
  70. package/lib/package.spec.js +4 -0
  71. package/lib/package.spec.js.map +1 -0
  72. package/package.json +44 -0
  73. package/src/node/annotation/cron.ts +21 -0
  74. package/src/node/annotation/index.ts +2 -0
  75. package/src/node/annotation/scheduler.ts +31 -0
  76. package/src/node/application-lifecycle.ts +56 -0
  77. package/src/node/constants.ts +4 -0
  78. package/src/node/cron-expression.ts +86 -0
  79. package/src/node/error/errors.ts +21 -0
  80. package/src/node/error/index.ts +1 -0
  81. package/src/node/factory/cron-job-factory.ts +16 -0
  82. package/src/node/factory/factory-protocol.ts +7 -0
  83. package/src/node/factory/index.ts +2 -0
  84. package/src/node/index.ts +7 -0
  85. package/src/node/module.ts +4 -0
  86. package/src/node/registry/index.ts +2 -0
  87. package/src/node/registry/registry-protocol.ts +14 -0
  88. package/src/node/registry/scheduler-registry.ts +50 -0
  89. package/src/package.spec.ts +4 -0
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./factory-protocol"), exports);
18
+ __exportStar(require("./cron-job-factory"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/factory/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,qDAAmC"}
@@ -0,0 +1,8 @@
1
+ export * from './annotation';
2
+ export * from './error';
3
+ export * from './application-lifecycle';
4
+ export * from './constants';
5
+ export * from './registry';
6
+ export * from './cron-expression';
7
+ export * from './factory';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./annotation"), exports);
18
+ __exportStar(require("./error"), exports);
19
+ __exportStar(require("./application-lifecycle"), exports);
20
+ __exportStar(require("./constants"), exports);
21
+ __exportStar(require("./registry"), exports);
22
+ __exportStar(require("./cron-expression"), exports);
23
+ __exportStar(require("./factory"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,0CAAwB;AACxB,0DAAwC;AACxC,8CAA4B;AAC5B,6CAA2B;AAC3B,oDAAkC;AAClC,4CAA0B"}
@@ -0,0 +1,4 @@
1
+ import './index';
2
+ declare const _default: import("inversify/lib/interfaces/interfaces").interfaces.ContainerModule;
3
+ export default _default;
4
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,CAAC;;AAEjB,wBAA0B"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@celljs/core");
4
+ require("./index");
5
+ exports.default = (0, core_1.autoBind)();
6
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,mBAAiB;AAEjB,kBAAe,IAAA,eAAQ,GAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './registry-protocol';
2
+ export * from './scheduler-registry';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/registry/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./registry-protocol"), exports);
18
+ __exportStar(require("./scheduler-registry"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/registry/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,uDAAqC"}
@@ -0,0 +1,12 @@
1
+ import { CronJobParameters, CronJob } from 'cron';
2
+ export declare const SchedulerRegistry: unique symbol;
3
+ export interface CronJobOptions extends CronJobParameters {
4
+ }
5
+ export interface SchedulerRegistry {
6
+ get(name: string): CronJob;
7
+ getAll(): Map<string, CronJob>;
8
+ add(name: string, options: CronJobOptions): CronJob;
9
+ delete(name: string): void;
10
+ has(name: string): boolean;
11
+ }
12
+ //# sourceMappingURL=registry-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry-protocol.d.ts","sourceRoot":"","sources":["../../../src/node/registry/registry-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAClD,eAAO,MAAM,iBAAiB,eAA8B,CAAC;AAE7D,MAAM,WAAW,cAAe,SAAQ,iBAAiB;CAExD;AAED,MAAM,WAAW,iBAAiB;IAC9B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC;IACpD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC9B"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchedulerRegistry = void 0;
4
+ exports.SchedulerRegistry = Symbol('SchedulerRegistry');
5
+ //# sourceMappingURL=registry-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry-protocol.js","sourceRoot":"","sources":["../../../src/node/registry/registry-protocol.ts"],"names":[],"mappings":";;;AACa,QAAA,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { CronJob } from 'cron';
2
+ import { SchedulerRegistry, CronJobOptions } from './registry-protocol';
3
+ import { CronJobFactory } from '../factory';
4
+ export declare class DefaultSchedulerRegistry implements SchedulerRegistry {
5
+ protected readonly defaultCronJobOptions: Partial<CronJobOptions>;
6
+ protected readonly cronJobFactory: CronJobFactory;
7
+ protected readonly cronJobs: Map<string, CronJob>;
8
+ get(name: string): CronJob;
9
+ getAll(): Map<string, CronJob>;
10
+ add(name: string, options: CronJobOptions): CronJob;
11
+ delete(name: string): void;
12
+ has(name: string): boolean;
13
+ }
14
+ //# sourceMappingURL=scheduler-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler-registry.d.ts","sourceRoot":"","sources":["../../../src/node/registry/scheduler-registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAExE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,qBACa,wBAAyB,YAAW,iBAAiB;IAG9D,SAAS,CAAC,QAAQ,CAAC,qBAAqB,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IAGlE,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IAElD,SAAS,CAAC,QAAQ,CAAC,QAAQ,uBAA8B;IAEzD,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAQ1B,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAI9B,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO;IAUnD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAM1B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAI7B"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DefaultSchedulerRegistry = void 0;
13
+ const core_1 = require("@celljs/core");
14
+ const registry_protocol_1 = require("./registry-protocol");
15
+ const error_1 = require("../error");
16
+ const factory_1 = require("../factory");
17
+ let DefaultSchedulerRegistry = class DefaultSchedulerRegistry {
18
+ constructor() {
19
+ this.cronJobs = new Map();
20
+ }
21
+ get(name) {
22
+ const job = this.cronJobs.get(name);
23
+ if (!job) {
24
+ throw new error_1.NoSchedulerFoundError(name);
25
+ }
26
+ return job;
27
+ }
28
+ getAll() {
29
+ return this.cronJobs;
30
+ }
31
+ add(name, options) {
32
+ let job = this.cronJobs.get(name);
33
+ if (job) {
34
+ throw new error_1.DuplicateSchedulerError(name);
35
+ }
36
+ job = this.cronJobFactory.create(options);
37
+ this.cronJobs.set(name, job);
38
+ return job;
39
+ }
40
+ delete(name) {
41
+ const job = this.get(name);
42
+ job.stop();
43
+ this.cronJobs.delete(name);
44
+ }
45
+ has(name) {
46
+ return this.cronJobs.has(name);
47
+ }
48
+ };
49
+ __decorate([
50
+ (0, core_1.Value)('cell.schedule.defaultCronJobOptions'),
51
+ __metadata("design:type", Object)
52
+ ], DefaultSchedulerRegistry.prototype, "defaultCronJobOptions", void 0);
53
+ __decorate([
54
+ (0, core_1.Autowired)(factory_1.CronJobFactory),
55
+ __metadata("design:type", Object)
56
+ ], DefaultSchedulerRegistry.prototype, "cronJobFactory", void 0);
57
+ DefaultSchedulerRegistry = __decorate([
58
+ (0, core_1.Component)(registry_protocol_1.SchedulerRegistry)
59
+ ], DefaultSchedulerRegistry);
60
+ exports.DefaultSchedulerRegistry = DefaultSchedulerRegistry;
61
+ //# sourceMappingURL=scheduler-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler-registry.js","sourceRoot":"","sources":["../../../src/node/registry/scheduler-registry.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAA2D;AAE3D,2DAAwE;AACxE,oCAA0E;AAC1E,wCAA4C;AAGrC,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAA9B;QAQgB,aAAQ,GAAG,IAAI,GAAG,EAAmB,CAAC;IAkC7D,CAAC;IAhCG,GAAG,CAAC,IAAY;QACZ,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,GAAG,EAAE;YACN,MAAM,IAAI,6BAAqB,CAAC,IAAI,CAAC,CAAC;SACzC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IAED,MAAM;QACF,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED,GAAG,CAAC,IAAY,EAAE,OAAuB;QACrC,IAAI,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,GAAG,EAAE;YACL,MAAM,IAAI,+BAAuB,CAAC,IAAI,CAAC,CAAC;SAC3C;QACD,GAAG,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC7B,OAAO,GAAG,CAAC;IACf,CAAC;IAED,MAAM,CAAC,IAAY;QACf,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC3B,GAAG,CAAC,IAAI,EAAE,CAAC;QACX,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,GAAG,CAAC,IAAY;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;CAEJ,CAAA;AAxCG;IAAC,IAAA,YAAK,EAAC,qCAAqC,CAAC;;uEACqB;AAElE;IAAC,IAAA,gBAAS,EAAC,wBAAc,CAAC;;gEACwB;AANzC,wBAAwB;IADpC,IAAA,gBAAS,EAAC,qCAAiB,CAAC;GAChB,wBAAwB,CA0CpC;AA1CY,4DAAwB"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=package.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.spec.d.ts","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ describe('schedule package', () => {
2
+ it('support code coverage statistics', () => { });
3
+ });
4
+ //# sourceMappingURL=package.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":"AAAA,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAE9B,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AACrD,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@celljs/schedule",
3
+ "version": "3.0.0",
4
+ "description": "",
5
+ "main": "lib/node/index.js",
6
+ "typings": "lib/node/index.d.ts",
7
+ "dependencies": {
8
+ "@celljs/core": "3.0.0",
9
+ "@types/cron": "^1.7.2",
10
+ "cron": "^1.8.2",
11
+ "reflect-metadata": "^0.1.13"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "keywords": [
17
+ "cell-component"
18
+ ],
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/cellbang/cell.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/cellbang/cell/issues"
26
+ },
27
+ "homepage": "https://github.com/cellbang/cell",
28
+ "files": [
29
+ "lib",
30
+ "src",
31
+ "cell.yml"
32
+ ],
33
+ "scripts": {
34
+ "lint": "cell-component lint",
35
+ "build": "cell-component build",
36
+ "watch": "cell-component watch",
37
+ "clean": "cell-component clean",
38
+ "test": "cell-component test:js"
39
+ },
40
+ "devDependencies": {
41
+ "@celljs/component": "3.0.0"
42
+ },
43
+ "gitHead": "c0ef8d269e33a795406bcbb240cac4b845c6c24c"
44
+ }
@@ -0,0 +1,21 @@
1
+ import { METADATA_KEY } from '../constants';
2
+ import { CronJobOptions } from '../registry';
3
+
4
+ export type CronOptions = Omit<CronJobOptions, 'onTick' | 'cronTime'> & { name?: string };
5
+
6
+ export interface CronMetadata extends CronOptions {
7
+ cronTime: string | Date;
8
+ method: string | symbol;
9
+ }
10
+
11
+ export function Cron(cronTime: string | Date, options?: CronOptions): MethodDecorator {
12
+ return (t, k, d) => {
13
+ applyCronDecorator(t, k, d, cronTime, options);
14
+ };
15
+ }
16
+
17
+ export function applyCronDecorator(target: any, targetKey: string | symbol, descriptor: TypedPropertyDescriptor<any>, cronTime: string | Date, options?: CronOptions): void {
18
+ const metadatas: CronMetadata[] = Reflect.getOwnMetadata(METADATA_KEY.cron, target.constructor) || [];
19
+ metadatas.push({ ...options, cronTime, method: targetKey });
20
+ Reflect.defineMetadata(METADATA_KEY.cron, metadatas, target.constructor);
21
+ }
@@ -0,0 +1,2 @@
1
+ export * from './scheduler';
2
+ export * from './cron';
@@ -0,0 +1,31 @@
1
+ import { METADATA_KEY } from '../constants';
2
+ import { CronJobOptions } from '../registry/registry-protocol';
3
+ import { Component, ComponentId, ComponentOption, parseComponentOption } from '@celljs/core';
4
+
5
+ export const SCHEDULER = Symbol('Scheduler');
6
+
7
+ export const SCHEDULER_TAG = 'Scheduler';
8
+
9
+ export interface SchedulerMetadata extends Partial<CronJobOptions> {
10
+ }
11
+
12
+ export function Scheduler(cronJobOptions?: CronJobOptions, componentOptions?: ComponentOption): ClassDecorator {
13
+ return function (target) {
14
+ const option = parseCornJobOptionOption(target, componentOptions);
15
+ applySchedulerDecorator(target, option, cronJobOptions);
16
+ };
17
+ }
18
+
19
+ export function parseCornJobOptionOption(target: any, componentOption?: ComponentOption) {
20
+ const parsed = <ComponentOption>parseComponentOption(target, componentOption);
21
+ parsed.sysTags!.push(SCHEDULER_TAG);
22
+ (parsed.id as Array<ComponentId>).push(SCHEDULER);
23
+ return parsed;
24
+ }
25
+
26
+ export function applySchedulerDecorator(target: any, componentOptions: ComponentOption, cronJobOptions?: CronJobOptions) {
27
+ const metadata: SchedulerMetadata = { ...cronJobOptions };
28
+ Reflect.defineMetadata(METADATA_KEY.scheduler, metadata, target);
29
+ Component(componentOptions)(target);
30
+ return metadata;
31
+ }
@@ -0,0 +1,56 @@
1
+ import { CronMetadata, SCHEDULER, SchedulerMetadata } from './annotation';
2
+ import { METADATA_KEY } from './constants';
3
+ import { Component, Value, Autowired, Optional, ApplicationLifecycle, getTargetClass, getOwnMetadata, Logger, generateUUUID } from '@celljs/core';
4
+
5
+ import { BackendApplication } from '@celljs/core/lib/node';
6
+ import { SchedulerRegistry } from './registry';
7
+
8
+ @Component(ApplicationLifecycle)
9
+ export class ApplicationLifecycleImpl implements ApplicationLifecycle<BackendApplication> {
10
+
11
+ @Autowired(SCHEDULER) @Optional()
12
+ protected readonly shedulers: any[] = [];
13
+
14
+ @Value('cell.schedule.disabled')
15
+ protected readonly scheduleDisabled = false;
16
+
17
+ @Autowired(SchedulerRegistry)
18
+ protected readonly schedulerRegistry: SchedulerRegistry;
19
+
20
+ @Autowired(Logger)
21
+ protected readonly logger: Logger;
22
+
23
+ initialize(): void {
24
+ if (this.scheduleDisabled) {
25
+ return;
26
+ }
27
+ for (const scheduler of this.shedulers) {
28
+ const targetConstructor = getTargetClass(scheduler);
29
+ const schedulerMetadata = <SchedulerMetadata>Reflect.getOwnMetadata(METADATA_KEY.scheduler, targetConstructor);
30
+ const cronMetadatas = <CronMetadata[]>getOwnMetadata(METADATA_KEY.cron, targetConstructor);
31
+ for (const cronMetadata of cronMetadatas) {
32
+ const name = cronMetadata.name || generateUUUID();
33
+ const method = cronMetadata.method;
34
+ this.schedulerRegistry.add(name, {
35
+ ...schedulerMetadata,
36
+ ...cronMetadata,
37
+ onTick: async () => {
38
+ try {
39
+ await scheduler[method]();
40
+ } catch (error) {
41
+ this.logger.error(error);
42
+ }
43
+ }
44
+ }).start();
45
+ }
46
+
47
+ }
48
+ }
49
+
50
+ onStop() {
51
+ for (const [ name ] of this.schedulerRegistry.getAll()) {
52
+ this.schedulerRegistry.delete(name);
53
+ }
54
+ }
55
+
56
+ }
@@ -0,0 +1,4 @@
1
+ export const METADATA_KEY = {
2
+ scheduler: 'cell:scheduler',
3
+ cron: 'cell:cron'
4
+ };
@@ -0,0 +1,86 @@
1
+
2
+ export enum CronExpression {
3
+ EVERY_SECOND = '* * * * * *',
4
+ EVERY_5_SECONDS = '*/5 * * * * *',
5
+ EVERY_10_SECONDS = '*/10 * * * * *',
6
+ EVERY_30_SECONDS = '*/30 * * * * *',
7
+ EVERY_MINUTE = '*/1 * * * *',
8
+ EVERY_5_MINUTES = '0 */5 * * * *',
9
+ EVERY_10_MINUTES = '0 */10 * * * *',
10
+ EVERY_30_MINUTES = '0 */30 * * * *',
11
+ EVERY_HOUR = '0 0-23/1 * * *',
12
+ EVERY_2_HOURS = '0 0-23/2 * * *',
13
+ EVERY_3_HOURS = '0 0-23/3 * * *',
14
+ EVERY_4_HOURS = '0 0-23/4 * * *',
15
+ EVERY_5_HOURS = '0 0-23/5 * * *',
16
+ EVERY_6_HOURS = '0 0-23/6 * * *',
17
+ EVERY_7_HOURS = '0 0-23/7 * * *',
18
+ EVERY_8_HOURS = '0 0-23/8 * * *',
19
+ EVERY_9_HOURS = '0 0-23/9 * * *',
20
+ EVERY_10_HOURS = '0 0-23/10 * * *',
21
+ EVERY_11_HOURS = '0 0-23/11 * * *',
22
+ EVERY_12_HOURS = '0 0-23/12 * * *',
23
+ EVERY_DAY_AT_1AM = '0 01 * * *',
24
+ EVERY_DAY_AT_2AM = '0 02 * * *',
25
+ EVERY_DAY_AT_3AM = '0 03 * * *',
26
+ EVERY_DAY_AT_4AM = '0 04 * * *',
27
+ EVERY_DAY_AT_5AM = '0 05 * * *',
28
+ EVERY_DAY_AT_6AM = '0 06 * * *',
29
+ EVERY_DAY_AT_7AM = '0 07 * * *',
30
+ EVERY_DAY_AT_8AM = '0 08 * * *',
31
+ EVERY_DAY_AT_9AM = '0 09 * * *',
32
+ EVERY_DAY_AT_10AM = '0 10 * * *',
33
+ EVERY_DAY_AT_11AM = '0 11 * * *',
34
+ EVERY_DAY_AT_NOON = '0 12 * * *',
35
+ EVERY_DAY_AT_1PM = '0 13 * * *',
36
+ EVERY_DAY_AT_2PM = '0 14 * * *',
37
+ EVERY_DAY_AT_3PM = '0 15 * * *',
38
+ EVERY_DAY_AT_4PM = '0 16 * * *',
39
+ EVERY_DAY_AT_5PM = '0 17 * * *',
40
+ EVERY_DAY_AT_6PM = '0 18 * * *',
41
+ EVERY_DAY_AT_7PM = '0 19 * * *',
42
+ EVERY_DAY_AT_8PM = '0 20 * * *',
43
+ EVERY_DAY_AT_9PM = '0 21 * * *',
44
+ EVERY_DAY_AT_10PM = '0 22 * * *',
45
+ EVERY_DAY_AT_11PM = '0 23 * * *',
46
+ EVERY_DAY_AT_MIDNIGHT = '0 0 * * *',
47
+ EVERY_WEEK = '0 0 * * 0',
48
+ EVERY_WEEKDAY = '0 0 * * 1-5',
49
+ EVERY_WEEKEND = '0 0 * * 6,0',
50
+ EVERY_1ST_DAY_OF_MONTH_AT_MIDNIGHT = '0 0 1 * *',
51
+ EVERY_1ST_DAY_OF_MONTH_AT_NOON = '0 12 1 * *',
52
+ EVERY_2ND_HOUR = '0 */2 * * *',
53
+ EVERY_2ND_HOUR_FROM_1AM_THROUGH_11PM = '0 1-23/2 * * *',
54
+ EVERY_2ND_MONTH = '0 0 1 */2 *',
55
+ EVERY_QUARTER = '0 0 1 */3 *',
56
+ EVERY_6_MONTHS = '0 0 1 */6 *',
57
+ EVERY_YEAR = '0 0 1 1 *',
58
+ EVERY_30_MINUTES_BETWEEN_9AM_AND_5PM = '0 */30 9-17 * * *',
59
+ EVERY_30_MINUTES_BETWEEN_9AM_AND_6PM = '0 */30 9-18 * * *',
60
+ EVERY_30_MINUTES_BETWEEN_10AM_AND_7PM = '0 */30 10-19 * * *',
61
+ MONDAY_TO_FRIDAY_AT_1AM = '0 0 01 * * 1-5',
62
+ MONDAY_TO_FRIDAY_AT_2AM = '0 0 02 * * 1-5',
63
+ MONDAY_TO_FRIDAY_AT_3AM = '0 0 03 * * 1-5',
64
+ MONDAY_TO_FRIDAY_AT_4AM = '0 0 04 * * 1-5',
65
+ MONDAY_TO_FRIDAY_AT_5AM = '0 0 05 * * 1-5',
66
+ MONDAY_TO_FRIDAY_AT_6AM = '0 0 06 * * 1-5',
67
+ MONDAY_TO_FRIDAY_AT_7AM = '0 0 07 * * 1-5',
68
+ MONDAY_TO_FRIDAY_AT_8AM = '0 0 08 * * 1-5',
69
+ MONDAY_TO_FRIDAY_AT_9AM = '0 0 09 * * 1-5',
70
+ MONDAY_TO_FRIDAY_AT_09_30AM = '0 30 09 * * 1-5',
71
+ MONDAY_TO_FRIDAY_AT_10AM = '0 0 10 * * 1-5',
72
+ MONDAY_TO_FRIDAY_AT_11AM = '0 0 11 * * 1-5',
73
+ MONDAY_TO_FRIDAY_AT_11_30AM = '0 30 11 * * 1-5',
74
+ MONDAY_TO_FRIDAY_AT_12PM = '0 0 12 * * 1-5',
75
+ MONDAY_TO_FRIDAY_AT_1PM = '0 0 13 * * 1-5',
76
+ MONDAY_TO_FRIDAY_AT_2PM = '0 0 14 * * 1-5',
77
+ MONDAY_TO_FRIDAY_AT_3PM = '0 0 15 * * 1-5',
78
+ MONDAY_TO_FRIDAY_AT_4PM = '0 0 16 * * 1-5',
79
+ MONDAY_TO_FRIDAY_AT_5PM = '0 0 17 * * 1-5',
80
+ MONDAY_TO_FRIDAY_AT_6PM = '0 0 18 * * 1-5',
81
+ MONDAY_TO_FRIDAY_AT_7PM = '0 0 19 * * 1-5',
82
+ MONDAY_TO_FRIDAY_AT_8PM = '0 0 20 * * 1-5',
83
+ MONDAY_TO_FRIDAY_AT_9PM = '0 0 21 * * 1-5',
84
+ MONDAY_TO_FRIDAY_AT_10PM = '0 0 22 * * 1-5',
85
+ MONDAY_TO_FRIDAY_AT_11PM = '0 0 23 * * 1-5',
86
+ }
@@ -0,0 +1,21 @@
1
+ import { CustomError } from '@celljs/core';
2
+
3
+ export class SchedulerError extends CustomError {
4
+
5
+ }
6
+
7
+ export class NoSchedulerFoundError extends SchedulerError {
8
+
9
+ constructor(name: string) {
10
+ super(`No Cron Job was found with the given name (${name}). Check that you created one with a decorator or with the create API.`);
11
+ }
12
+
13
+ }
14
+
15
+ export class DuplicateSchedulerError extends SchedulerError {
16
+
17
+ constructor(name: string) {
18
+ super(`Cron Job with the given name (${name}) already exists. Ignored.`);
19
+ }
20
+
21
+ }
@@ -0,0 +1 @@
1
+ export * from './errors';
@@ -0,0 +1,16 @@
1
+ import { Component, Value } from '@celljs/core';
2
+ import { CronJob } from 'cron';
3
+ import { CronJobFactory } from './factory-protocol';
4
+ import { CronJobOptions } from '../registry';
5
+
6
+ @Component(CronJobFactory)
7
+ export class DefaultCronJobFactory implements CronJobFactory {
8
+
9
+ @Value('cell.schedule.defaultCronJobOptions')
10
+ protected readonly defaultCronJobOptions: Partial<CronJobOptions>;
11
+
12
+ create(options: CronJobOptions): CronJob {
13
+ return new CronJob({...this.defaultCronJobOptions, ...options });
14
+ }
15
+
16
+ }
@@ -0,0 +1,7 @@
1
+ import { CronJob } from 'cron';
2
+ import { CronJobOptions } from '../registry';
3
+ export const CronJobFactory = Symbol('CronJobFactory');
4
+
5
+ export interface CronJobFactory {
6
+ create(options: CronJobOptions): CronJob;
7
+ }
@@ -0,0 +1,2 @@
1
+ export * from './factory-protocol';
2
+ export * from './cron-job-factory';
@@ -0,0 +1,7 @@
1
+ export * from './annotation';
2
+ export * from './error';
3
+ export * from './application-lifecycle';
4
+ export * from './constants';
5
+ export * from './registry';
6
+ export * from './cron-expression';
7
+ export * from './factory';
@@ -0,0 +1,4 @@
1
+ import { autoBind } from '@celljs/core';
2
+ import './index';
3
+
4
+ export default autoBind();
@@ -0,0 +1,2 @@
1
+ export * from './registry-protocol';
2
+ export * from './scheduler-registry';
@@ -0,0 +1,14 @@
1
+ import { CronJobParameters, CronJob } from 'cron';
2
+ export const SchedulerRegistry = Symbol('SchedulerRegistry');
3
+
4
+ export interface CronJobOptions extends CronJobParameters {
5
+
6
+ }
7
+
8
+ export interface SchedulerRegistry {
9
+ get(name: string): CronJob;
10
+ getAll(): Map<string, CronJob>;
11
+ add(name: string, options: CronJobOptions): CronJob;
12
+ delete(name: string): void;
13
+ has(name: string): boolean;
14
+ }
@@ -0,0 +1,50 @@
1
+ import { Autowired, Component, Value } from '@celljs/core';
2
+ import { CronJob } from 'cron';
3
+ import { SchedulerRegistry, CronJobOptions } from './registry-protocol';
4
+ import { DuplicateSchedulerError, NoSchedulerFoundError } from '../error';
5
+ import { CronJobFactory } from '../factory';
6
+
7
+ @Component(SchedulerRegistry)
8
+ export class DefaultSchedulerRegistry implements SchedulerRegistry {
9
+
10
+ @Value('cell.schedule.defaultCronJobOptions')
11
+ protected readonly defaultCronJobOptions: Partial<CronJobOptions>;
12
+
13
+ @Autowired(CronJobFactory)
14
+ protected readonly cronJobFactory: CronJobFactory;
15
+
16
+ protected readonly cronJobs = new Map<string, CronJob>();
17
+
18
+ get(name: string): CronJob {
19
+ const job = this.cronJobs.get(name);
20
+ if (!job) {
21
+ throw new NoSchedulerFoundError(name);
22
+ }
23
+ return job;
24
+ }
25
+
26
+ getAll(): Map<string, CronJob> {
27
+ return this.cronJobs;
28
+ }
29
+
30
+ add(name: string, options: CronJobOptions): CronJob {
31
+ let job = this.cronJobs.get(name);
32
+ if (job) {
33
+ throw new DuplicateSchedulerError(name);
34
+ }
35
+ job = this.cronJobFactory.create(options);
36
+ this.cronJobs.set(name, job);
37
+ return job;
38
+ }
39
+
40
+ delete(name: string): void {
41
+ const job = this.get(name);
42
+ job.stop();
43
+ this.cronJobs.delete(name);
44
+ }
45
+
46
+ has(name: string): boolean {
47
+ return this.cronJobs.has(name);
48
+ }
49
+
50
+ }