@clairejs/server 3.21.2 → 3.21.4
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/README.md +2 -1
- package/dist/job/AwsJobScheduler.js +16 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
import { AbstractLogger, Errors, LogContext } from "@clairejs/core";
|
|
11
11
|
import { AbstractDbAdapter } from "@clairejs/orm";
|
|
12
|
+
import assert from "assert";
|
|
12
13
|
import aws from "aws-sdk";
|
|
13
14
|
import { AbstractJobScheduler } from "./AbstractJobScheduler";
|
|
14
15
|
let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
|
|
@@ -81,13 +82,25 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
|
|
|
81
82
|
this.logger.debug("Scheduling job: ", jobInfo);
|
|
82
83
|
if (jobInfo.cron || jobInfo.at) {
|
|
83
84
|
const jobId = `${this.jobNamePrefix}${this.uniqueJobIdFactory()}`;
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
let cronExpression;
|
|
86
|
+
if (jobInfo.at) {
|
|
87
|
+
this.logger.debug("At job", jobInfo.at);
|
|
88
|
+
cronExpression = this.generateCronFromTimestamp(jobInfo.at);
|
|
89
|
+
}
|
|
90
|
+
else if (jobInfo.cron) {
|
|
91
|
+
let cron = jobInfo.cron;
|
|
92
|
+
this.logger.debug("Cron job", cron, cron.endsWith(" *"));
|
|
93
|
+
if (cron.endsWith(" *")) {
|
|
94
|
+
cronExpression = `${cron.slice(0, -2)} ?`;
|
|
95
|
+
}
|
|
96
|
+
cronExpression = `${cron} *`;
|
|
97
|
+
}
|
|
86
98
|
this.logger.debug("Cron expression", cronExpression);
|
|
99
|
+
assert.ok(cronExpression);
|
|
87
100
|
await this.eventbridge
|
|
88
101
|
.putRule({
|
|
89
102
|
Name: jobId,
|
|
90
|
-
Description: `${jobInfo.jobName} - ${
|
|
103
|
+
Description: `${jobInfo.jobName} - ${cronExpression || jobInfo.at}`,
|
|
91
104
|
EventBusName: this.eventBusName,
|
|
92
105
|
ScheduleExpression: `cron(${cronExpression})`,
|
|
93
106
|
State: "ENABLED",
|
|
@@ -121,14 +134,10 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
|
|
|
121
134
|
}
|
|
122
135
|
async syncJobs() {
|
|
123
136
|
//-- check jobs
|
|
124
|
-
console.log("syncJobs started");
|
|
125
137
|
const scheduledJobs = await this.getAllScheduledJobs();
|
|
126
|
-
console.log("scheduledJobs", scheduledJobs);
|
|
127
138
|
const allJobs = await this.getAvailableJobInfo();
|
|
128
|
-
console.log("allJobs", allJobs);
|
|
129
139
|
//-- remove job that no more exist
|
|
130
140
|
const nomoreExistJobs = scheduledJobs.filter((job) => !allJobs.find((j) => j.jobName === job.jobName));
|
|
131
|
-
console.log("nomoreExistJobs", nomoreExistJobs);
|
|
132
141
|
for (const job of nomoreExistJobs) {
|
|
133
142
|
this.logger.info(`Removing stale job: ${job.jobName} of id: ${job.id}`);
|
|
134
143
|
await this.removeJob(job.id);
|
|
@@ -155,7 +164,6 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
|
|
|
155
164
|
});
|
|
156
165
|
}
|
|
157
166
|
//-- keep "at" jobs as is
|
|
158
|
-
console.log("syncJobs finished");
|
|
159
167
|
}
|
|
160
168
|
async removeJob(jobId) {
|
|
161
169
|
await this.eventbridge
|