@appweaver/cron 2.0.2 → 2.1.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.
- package/cron-scheduler.js +15 -2
- package/package.json +3 -3
package/cron-scheduler.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.CronScheduler = void 0;
|
|
|
4
4
|
const cron_1 = require("cron");
|
|
5
5
|
const common_1 = require("@appweaver/common");
|
|
6
6
|
const core_1 = require("@appweaver/core");
|
|
7
|
+
const logger = (0, common_1.createLogger)('scheduler');
|
|
7
8
|
class CronScheduler extends common_1.Scheduler {
|
|
8
9
|
/** @internal */
|
|
9
10
|
_jobs = {};
|
|
@@ -21,7 +22,7 @@ class CronScheduler extends common_1.Scheduler {
|
|
|
21
22
|
const stopActions = [];
|
|
22
23
|
for (const job of Object.values(this._jobs)) {
|
|
23
24
|
if (!job.isActive) {
|
|
24
|
-
|
|
25
|
+
continue;
|
|
25
26
|
}
|
|
26
27
|
const stopAction = job.stop();
|
|
27
28
|
if (stopAction) {
|
|
@@ -37,15 +38,24 @@ class CronScheduler extends common_1.Scheduler {
|
|
|
37
38
|
start: core_1.schedulerConfig.AUTO_START_JOB,
|
|
38
39
|
waitForCompletion: true,
|
|
39
40
|
errorHandler: (e) => {
|
|
40
|
-
|
|
41
|
+
logger.error({ err: e, jobId }, 'Job handler error');
|
|
41
42
|
},
|
|
42
43
|
...providerOptions,
|
|
43
44
|
cronTime,
|
|
44
45
|
onTick: async () => {
|
|
46
|
+
const start = performance.now();
|
|
47
|
+
logger.debug({ jobId }, 'Job run started');
|
|
45
48
|
await onTick();
|
|
49
|
+
logger.debug({ jobId, durationMs: Math.round(performance.now() - start) }, 'Job run finished');
|
|
46
50
|
},
|
|
47
51
|
timeZone
|
|
48
52
|
});
|
|
53
|
+
logger.debug({
|
|
54
|
+
jobId,
|
|
55
|
+
cronTime,
|
|
56
|
+
timeZone,
|
|
57
|
+
nextRun: this._jobs[jobId].nextDate().toISO()
|
|
58
|
+
}, 'Job scheduled');
|
|
49
59
|
return jobId;
|
|
50
60
|
}
|
|
51
61
|
getJob(jobId) {
|
|
@@ -57,6 +67,7 @@ class CronScheduler extends common_1.Scheduler {
|
|
|
57
67
|
return false;
|
|
58
68
|
}
|
|
59
69
|
job.start();
|
|
70
|
+
logger.debug({ jobId }, 'Job started');
|
|
60
71
|
return true;
|
|
61
72
|
}
|
|
62
73
|
async stopJob(jobId) {
|
|
@@ -65,6 +76,7 @@ class CronScheduler extends common_1.Scheduler {
|
|
|
65
76
|
return false;
|
|
66
77
|
}
|
|
67
78
|
await job.stop();
|
|
79
|
+
logger.debug({ jobId }, 'Job stopped');
|
|
68
80
|
return true;
|
|
69
81
|
}
|
|
70
82
|
async removeJob(jobId) {
|
|
@@ -74,6 +86,7 @@ class CronScheduler extends common_1.Scheduler {
|
|
|
74
86
|
}
|
|
75
87
|
await job.stop();
|
|
76
88
|
delete this._jobs[jobId];
|
|
89
|
+
logger.debug({ jobId }, 'Job removed');
|
|
77
90
|
return true;
|
|
78
91
|
}
|
|
79
92
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appweaver/cron",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Appweaver - the backend framework for AI-first development (@cron)",
|
|
5
5
|
"author": "Luka Matosevic",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"cron": "4.4.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@appweaver/common": "^2.0
|
|
46
|
-
"@appweaver/core": "^2.0
|
|
45
|
+
"@appweaver/common": "^2.1.0",
|
|
46
|
+
"@appweaver/core": "^2.1.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@appweaver/common": "^1.12.2",
|