@clairejs/server 3.27.3 → 3.27.6

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,12 @@
1
1
  ## Change Log
2
2
 
3
- #### 3.27.3
3
+ #### 3.27.6
4
4
 
5
+ - fix npm security issues
6
+
7
+ #### 3.27.5
8
+
9
+ - implement job retry logic
5
10
  - use aws scheduler for jobs
6
11
 
7
12
  #### 3.26.2
@@ -29,6 +29,7 @@ export declare abstract class AbstractJobScheduler {
29
29
  * @param id The job id returned from scheduleJobAt function
30
30
  */
31
31
  protected abstract cancelJob(id: string): Promise<void>;
32
+ protected retryJob(payload: AbstractJob): Promise<void>;
32
33
  /**
33
34
  * Remove the scheduled job and prevent if from running in the future
34
35
  * @param id The job id returned from scheduleJobAt function
@@ -96,6 +96,10 @@ export class AbstractJobScheduler {
96
96
  await tx.commit();
97
97
  return jobId;
98
98
  }
99
+ async retryJob(payload) {
100
+ this.logger.debug("Retrying job: ", payload);
101
+ await this._scheduleJob({ ...payload, id: `${payload.id}-retry-${payload.retryCount}` });
102
+ }
99
103
  /**
100
104
  * Remove the scheduled job and prevent if from running in the future
101
105
  * @param id The job id returned from scheduleJobAt function
@@ -148,7 +152,7 @@ export class AbstractJobScheduler {
148
152
  //-- retry by reschedule the job
149
153
  update.retryCount = (job.retryCount || 0) + 1;
150
154
  const retryDelay = job.retryDelayMs || 0;
151
- await this.scheduleJob({ ...job, at: Date.now() + (retryDelay < 60000 ? 60000 : retryDelay) });
155
+ await this.retryJob({ ...job, ...update, at: Date.now() + (retryDelay < 60000 ? 60000 : retryDelay) });
152
156
  }
153
157
  else {
154
158
  if (job.cron) {
@@ -15,6 +15,7 @@ export declare class AwsJobScheduler extends AbstractJobScheduler {
15
15
  constructor(logger: AbstractLogger, db: AbstractDbAdapter, jobRepo: AbstractJobRepository, apiLambdaFunctionArn: string, apiLambdaFunctionRoleArn: string, jobNamespace: string);
16
16
  handleCron(jobInfo: AbstractJob): Promise<void>;
17
17
  private convertCronToSchedulerExpression;
18
+ private getOneTimeExpression;
18
19
  protected getScheduledJobs(): Promise<AbstractJob[]>;
19
20
  protected _scheduleJob(jobInfo: AbstractJob): Promise<void>;
20
21
  cancelJob(jobId: string): Promise<void>;
@@ -56,6 +56,10 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
56
56
  }
57
57
  return parts.join(" ");
58
58
  }
59
+ getOneTimeExpression(at) {
60
+ const date = new Date(at);
61
+ return `at(${date.toISOString().replace(/\.\d{3}Z$/, '')})`;
62
+ }
59
63
  async getScheduledJobs() {
60
64
  try {
61
65
  const listCommand = new ListSchedulesCommand({
@@ -96,9 +100,7 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
96
100
  let scheduleExpression;
97
101
  let flexibleTimeWindow;
98
102
  if (jobInfo.at) {
99
- // For one-time jobs, use at() expression
100
- const date = new Date(jobInfo.at);
101
- scheduleExpression = `at(${date.toISOString().replace(/\.\d{3}Z$/, '')})`;
103
+ scheduleExpression = this.getOneTimeExpression(jobInfo.at);
102
104
  // Add flexible time window for one-time jobs to handle slight delays
103
105
  flexibleTimeWindow = {
104
106
  Mode: "OFF",
@@ -80,7 +80,7 @@ let LocalJobScheduler = class LocalJobScheduler extends AbstractJobScheduler {
80
80
  return;
81
81
  }
82
82
  const jobInfo = data;
83
- await this.scheduleJob(jobInfo);
83
+ await this._scheduleJob(jobInfo);
84
84
  break;
85
85
  case CommunicationMessage.REMOVE_JOB:
86
86
  if (!this.isActive) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clairejs/server",
3
- "version": "3.27.3",
3
+ "version": "3.27.6",
4
4
  "description": "Claire server NodeJs framework written in Typescript.",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",