@clairejs/server 3.21.1 → 3.21.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.
package/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  ## Change Log
2
2
 
3
- #### 3.21.1:
3
+ #### 3.21.3:
4
4
 
5
+ - fix cron expression
5
6
  - add log to aws job scheduler & fix cronjob sync
6
7
  - simplify lambda job scheduler, remove job interval that is less than 60s
7
8
 
@@ -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 {
@@ -82,8 +83,19 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
82
83
  if (jobInfo.cron || jobInfo.at) {
83
84
  const jobId = `${this.jobNamePrefix}${this.uniqueJobIdFactory()}`;
84
85
  //-- generate pattern from cron (add * at the end for year) / at timestamp
85
- const cronExpression = jobInfo.cron ? `${jobInfo.cron} *` : this.generateCronFromTimestamp(jobInfo.at);
86
+ let cronExpression;
87
+ if (jobInfo.at) {
88
+ cronExpression = this.generateCronFromTimestamp(jobInfo.at);
89
+ }
90
+ else if (jobInfo.cron) {
91
+ let cron = jobInfo.cron;
92
+ if (cron.endsWith(" *")) {
93
+ cronExpression = `${cron.slice(0, -2)} ?`;
94
+ }
95
+ cronExpression = `${cron} *`;
96
+ }
86
97
  this.logger.debug("Cron expression", cronExpression);
98
+ assert.ok(cronExpression);
87
99
  await this.eventbridge
88
100
  .putRule({
89
101
  Name: jobId,
@@ -121,14 +133,10 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
121
133
  }
122
134
  async syncJobs() {
123
135
  //-- check jobs
124
- console.log("syncJobs started");
125
136
  const scheduledJobs = await this.getAllScheduledJobs();
126
- console.log("scheduledJobs", scheduledJobs);
127
137
  const allJobs = await this.getAvailableJobInfo();
128
- console.log("allJobs", allJobs);
129
138
  //-- remove job that no more exist
130
139
  const nomoreExistJobs = scheduledJobs.filter((job) => !allJobs.find((j) => j.jobName === job.jobName));
131
- console.log("nomoreExistJobs", nomoreExistJobs);
132
140
  for (const job of nomoreExistJobs) {
133
141
  this.logger.info(`Removing stale job: ${job.jobName} of id: ${job.id}`);
134
142
  await this.removeJob(job.id);
@@ -142,20 +150,19 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
142
150
  const unmatchedCronJobs = scheduledCronJobs.filter((j) => j.cron && !allJobs.find((job) => job.jobName === j.jobName && job.cron === j.cron));
143
151
  if (unmatchedCronJobs.length) {
144
152
  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
- }
153
+ }
154
+ //-- reschedule new cron jobs and those which are not synced
155
+ const resyncCronJobs = allJobs.filter((job) => job.cron &&
156
+ (unmatchedCronJobs.some((j) => j.jobName === job.jobName) ||
157
+ !scheduledCronJobs.some((j) => j.jobName === job.jobName)));
158
+ this.logger.debug("Reschedule cron jobs", resyncCronJobs);
159
+ for (const job of resyncCronJobs) {
160
+ await this.scheduleJob({
161
+ jobName: job.jobName,
162
+ cron: job.cron,
163
+ });
156
164
  }
157
165
  //-- keep "at" jobs as is
158
- console.log("syncJobs finished");
159
166
  }
160
167
  async removeJob(jobId) {
161
168
  await this.eventbridge
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clairejs/server",
3
- "version": "3.21.1",
3
+ "version": "3.21.3",
4
4
  "description": "Claire server NodeJs framework written in Typescript.",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",