@tego/core 1.6.12 → 1.6.13-alpha.3

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.
@@ -7,8 +7,11 @@ export interface CronJobParameters {
7
7
  context?: any;
8
8
  }
9
9
  export declare class CronJob {
10
+ private params;
11
+ private timer?;
10
12
  constructor(params: CronJobParameters);
11
13
  start(): void;
14
+ private scheduleNext;
12
15
  stop(): void;
13
16
  }
14
17
  export declare class CronJobManager {
@@ -22,17 +22,45 @@ __export(cron_job_manager_exports, {
22
22
  CronJobManager: () => CronJobManager
23
23
  });
24
24
  module.exports = __toCommonJS(cron_job_manager_exports);
25
+ var import_cron_parser = require("cron-parser");
26
+ const MAX_TIMEOUT = 2 ** 31 - 1;
25
27
  const _CronJob = class _CronJob {
26
28
  constructor(params) {
29
+ this.params = params;
27
30
  if (params.start !== false) {
28
31
  this.start();
29
32
  }
30
33
  }
31
34
  start() {
32
- console.log("Mock CronJob started");
35
+ if (this.timer) {
36
+ return;
37
+ }
38
+ this.scheduleNext();
39
+ }
40
+ scheduleNext() {
41
+ const interval = import_cron_parser.CronExpressionParser.parse(this.params.cronTime, {
42
+ tz: this.params.timeZone
43
+ });
44
+ const next = interval.next().getTime();
45
+ const delay = Math.max(0, next - Date.now());
46
+ if (delay > MAX_TIMEOUT) {
47
+ this.timer = setTimeout(() => {
48
+ this.timer = void 0;
49
+ this.scheduleNext();
50
+ }, MAX_TIMEOUT);
51
+ } else {
52
+ this.timer = setTimeout(() => {
53
+ this.timer = void 0;
54
+ this.params.onTick();
55
+ this.scheduleNext();
56
+ }, delay);
57
+ }
33
58
  }
34
59
  stop() {
35
- console.log("Mock CronJob stopped");
60
+ if (this.timer) {
61
+ clearTimeout(this.timer);
62
+ this.timer = void 0;
63
+ }
36
64
  }
37
65
  };
38
66
  __name(_CronJob, "CronJob");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tego/core",
3
- "version": "1.6.12",
3
+ "version": "1.6.13-alpha.3",
4
4
  "homepage": "https://github.com/tegojs/tego#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/tegojs/tego/issues"
@@ -21,6 +21,7 @@
21
21
  "axios": "0.29.0",
22
22
  "commander": "^9.5.0",
23
23
  "compression": "^1.8.1",
24
+ "cron-parser": "^5.5.0",
24
25
  "dayjs": "1.11.13",
25
26
  "decompress": "4.2.1",
26
27
  "execa": "^5.1.1",
@@ -40,18 +41,18 @@
40
41
  "winston": "^3.17.0",
41
42
  "ws": "^8.18.3",
42
43
  "xpipe": "^1.0.8",
43
- "@tachybase/acl": "1.6.12",
44
- "@tachybase/actions": "1.6.12",
45
- "@tachybase/auth": "1.6.12",
46
- "@tachybase/cache": "1.6.12",
47
- "@tachybase/data-source": "1.6.12",
48
- "@tachybase/di": "1.6.12",
49
- "@tachybase/loader": "1.6.12",
50
- "@tachybase/logger": "1.6.12",
51
- "@tachybase/globals": "1.6.12",
52
- "@tachybase/resourcer": "1.6.12",
53
- "@tachybase/utils": "1.6.12",
54
- "@tachybase/database": "1.6.12"
44
+ "@tachybase/acl": "1.6.13-alpha.3",
45
+ "@tachybase/actions": "1.6.13-alpha.3",
46
+ "@tachybase/data-source": "1.6.13-alpha.3",
47
+ "@tachybase/auth": "1.6.13-alpha.3",
48
+ "@tachybase/di": "1.6.13-alpha.3",
49
+ "@tachybase/database": "1.6.13-alpha.3",
50
+ "@tachybase/globals": "1.6.13-alpha.3",
51
+ "@tachybase/resourcer": "1.6.13-alpha.3",
52
+ "@tachybase/utils": "1.6.13-alpha.3",
53
+ "@tachybase/cache": "1.6.13-alpha.3",
54
+ "@tachybase/loader": "1.6.13-alpha.3",
55
+ "@tachybase/logger": "1.6.13-alpha.3"
55
56
  },
56
57
  "devDependencies": {
57
58
  "@types/fs-extra": "11.0.4",