@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 CHANGED
@@ -1,7 +1,8 @@
1
1
  ## Change Log
2
2
 
3
- #### 3.21.0:
3
+ #### 3.21.1:
4
4
 
5
+ - add log to aws job scheduler & fix cronjob sync
5
6
  - simplify lambda job scheduler, remove job interval that is less than 60s
6
7
 
7
8
  #### 3.20.2:
@@ -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
- await Promise.all(scheduledCronJobs.map((j) => this.removeJob(j.id)));
139
- //-- reschedule cron & interval jobs because we might have updated the cron expression / interval value
140
- const cronJobs = allJobs.filter((job) => job.cron);
141
- this.logger.debug("Scheduling cron & interval jobs");
142
- for (const job of cronJobs) {
143
- await this.scheduleJob({
144
- jobName: job.jobName,
145
- cron: job.cron,
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clairejs/server",
3
- "version": "3.21.0",
3
+ "version": "3.21.1",
4
4
  "description": "Claire server NodeJs framework written in Typescript.",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",