@clairejs/server 3.22.9 → 3.22.10

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,5 +1,9 @@
1
1
  ## Change Log
2
2
 
3
+ #### 3.22.10
4
+
5
+ - fix aws job scheduler name space job removal issue
6
+
3
7
  #### 3.22.9
4
8
 
5
9
  - fix typing issue with job handler function
@@ -12,10 +12,10 @@ export declare class AwsJobScheduler extends AbstractJobScheduler {
12
12
  protected readonly db: AbstractDbAdapter;
13
13
  protected readonly uniqueJobIdFactory: () => string;
14
14
  protected readonly apiLambdaFunctionArn: string;
15
+ protected readonly jobNamespace: string;
15
16
  protected readonly eventBusName: string;
16
- protected readonly jobNamePrefix: string;
17
17
  protected readonly eventbridge: aws.EventBridge;
18
- constructor(logger: AbstractLogger, db: AbstractDbAdapter, uniqueJobIdFactory: () => string, apiLambdaFunctionArn: string, eventBusName?: string, jobNamePrefix?: string);
18
+ constructor(logger: AbstractLogger, db: AbstractDbAdapter, uniqueJobIdFactory: () => string, apiLambdaFunctionArn: string, jobNamespace: string, eventBusName?: string);
19
19
  handleCron(jobInfo: ScheduledJob): Promise<void>;
20
20
  protected afterJob(_job: ScheduledJob, _tx: ITransaction): Promise<void>;
21
21
  private generateCronFromTimestamp;
@@ -21,17 +21,17 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
21
21
  db;
22
22
  uniqueJobIdFactory;
23
23
  apiLambdaFunctionArn;
24
+ jobNamespace;
24
25
  eventBusName;
25
- jobNamePrefix;
26
26
  eventbridge = new aws.EventBridge();
27
- constructor(logger, db, uniqueJobIdFactory, apiLambdaFunctionArn, eventBusName = "default", jobNamePrefix = "claire-aws-job-") {
27
+ constructor(logger, db, uniqueJobIdFactory, apiLambdaFunctionArn, jobNamespace, eventBusName = "default") {
28
28
  super(logger, db);
29
29
  this.logger = logger;
30
30
  this.db = db;
31
31
  this.uniqueJobIdFactory = uniqueJobIdFactory;
32
32
  this.apiLambdaFunctionArn = apiLambdaFunctionArn;
33
+ this.jobNamespace = jobNamespace;
33
34
  this.eventBusName = eventBusName;
34
- this.jobNamePrefix = jobNamePrefix;
35
35
  }
36
36
  async handleCron(jobInfo) {
37
37
  this.logger.debug(`Handle cron`, jobInfo);
@@ -59,7 +59,7 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
59
59
  const allRules = await this.eventbridge
60
60
  .listRules({
61
61
  EventBusName: this.eventBusName,
62
- NamePrefix: this.jobNamePrefix,
62
+ NamePrefix: this.jobNamespace,
63
63
  })
64
64
  .promise();
65
65
  const allJobs = await Promise.all((allRules.Rules || []).map(async (rule) => {
@@ -83,7 +83,7 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
83
83
  async scheduleJob(jobInfo) {
84
84
  this.logger.debug("Scheduling job: ", jobInfo);
85
85
  if (jobInfo.cron || jobInfo.at) {
86
- const jobId = `${this.jobNamePrefix}${this.uniqueJobIdFactory()}`;
86
+ const jobId = `${this.jobNamespace}${this.uniqueJobIdFactory()}`;
87
87
  let cronExpression;
88
88
  if (jobInfo.at) {
89
89
  cronExpression = this.generateCronFromTimestamp(jobInfo.at);
@@ -139,8 +139,10 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
139
139
  //-- remove job that no more exist
140
140
  const nomoreExistJobs = scheduledJobs.filter((job) => !allJobs.find((j) => j.jobName === job.jobName));
141
141
  for (const job of nomoreExistJobs) {
142
- this.logger.info(`Removing stale job: ${job.jobName} of id: ${job.id}`);
143
- await this.removeJob(job.id);
142
+ if (job.id) {
143
+ this.logger.info(`Removing stale job: ${job.jobName} of id: ${job.id}`);
144
+ await this.removeJob(job.id);
145
+ }
144
146
  }
145
147
  if (nomoreExistJobs.length) {
146
148
  this.logger.info(`Cleaned up: ${nomoreExistJobs.length} stale jobs`);
@@ -184,6 +186,6 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
184
186
  AwsJobScheduler = __decorate([
185
187
  LogContext(),
186
188
  __metadata("design:paramtypes", [AbstractLogger,
187
- AbstractDbAdapter, Function, String, Object, Object])
189
+ AbstractDbAdapter, Function, String, String, Object])
188
190
  ], AwsJobScheduler);
189
191
  export { AwsJobScheduler };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clairejs/server",
3
- "version": "3.22.9",
3
+ "version": "3.22.10",
4
4
  "description": "Claire server NodeJs framework written in Typescript.",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",