@clairejs/server 3.21.0 → 3.21.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/README.md +2 -1
- package/dist/job/AwsJobScheduler.js +20 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -121,10 +121,14 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
|
|
|
121
121
|
}
|
|
122
122
|
async syncJobs() {
|
|
123
123
|
//-- check jobs
|
|
124
|
+
console.log("syncJobs started");
|
|
124
125
|
const scheduledJobs = await this.getAllScheduledJobs();
|
|
126
|
+
console.log("scheduledJobs", scheduledJobs);
|
|
125
127
|
const allJobs = await this.getAvailableJobInfo();
|
|
128
|
+
console.log("allJobs", allJobs);
|
|
126
129
|
//-- remove job that no more exist
|
|
127
130
|
const nomoreExistJobs = scheduledJobs.filter((job) => !allJobs.find((j) => j.jobName === job.jobName));
|
|
131
|
+
console.log("nomoreExistJobs", nomoreExistJobs);
|
|
128
132
|
for (const job of nomoreExistJobs) {
|
|
129
133
|
this.logger.info(`Removing stale job: ${job.jobName} of id: ${job.id}`);
|
|
130
134
|
await this.removeJob(job.id);
|
|
@@ -132,20 +136,26 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
|
|
|
132
136
|
if (nomoreExistJobs.length) {
|
|
133
137
|
this.logger.info(`Cleaned up: ${nomoreExistJobs.length} stale jobs`);
|
|
134
138
|
}
|
|
135
|
-
//-- remove scheduled cron jobs
|
|
139
|
+
//-- remove scheduled cron jobs that diff the cron expression
|
|
136
140
|
this.logger.debug("Remove scheduled cron jobs");
|
|
137
141
|
const scheduledCronJobs = scheduledJobs.filter((j) => j.cron);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
142
|
+
const unmatchedCronJobs = scheduledCronJobs.filter((j) => j.cron && !allJobs.find((job) => job.jobName === j.jobName && job.cron === j.cron));
|
|
143
|
+
if (unmatchedCronJobs.length) {
|
|
144
|
+
await Promise.all(unmatchedCronJobs.map((j) => this.removeJob(j.id)));
|
|
145
|
+
//-- reschedule new cron jobs and those which are not synced
|
|
146
|
+
const resyncCronJobs = allJobs.filter((job) => job.cron &&
|
|
147
|
+
(unmatchedCronJobs.some((j) => j.jobName === job.jobName) ||
|
|
148
|
+
!scheduledCronJobs.some((j) => j.jobName === job.jobName)));
|
|
149
|
+
this.logger.debug("Reschedule cron jobs", resyncCronJobs);
|
|
150
|
+
for (const job of resyncCronJobs) {
|
|
151
|
+
await this.scheduleJob({
|
|
152
|
+
jobName: job.jobName,
|
|
153
|
+
cron: job.cron,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
147
156
|
}
|
|
148
157
|
//-- keep "at" jobs as is
|
|
158
|
+
console.log("syncJobs finished");
|
|
149
159
|
}
|
|
150
160
|
async removeJob(jobId) {
|
|
151
161
|
await this.eventbridge
|