@clairejs/server 3.22.11 → 3.22.13
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
|
@@ -33,17 +33,25 @@ export class AbstractJobScheduler {
|
|
|
33
33
|
*/
|
|
34
34
|
async executeJob(job) {
|
|
35
35
|
//-- run job
|
|
36
|
+
console.log("executeJob", job);
|
|
36
37
|
const allJobs = await this.getAvailableJobInfo();
|
|
38
|
+
console.log("alljobs", allJobs);
|
|
37
39
|
const jobHandler = allJobs.find((j) => j.jobName === job.jobName);
|
|
40
|
+
console.log("creating transaction");
|
|
38
41
|
const tx = await this.db.createTransaction();
|
|
42
|
+
console.log("transaction created");
|
|
39
43
|
try {
|
|
40
44
|
if (!jobHandler) {
|
|
45
|
+
console.log("removing job");
|
|
41
46
|
//-- remove job
|
|
42
47
|
this.logger.info(`Remove job with id: ${job.id} as handler is not found`);
|
|
43
48
|
await this.removeJob(job.id, tx);
|
|
49
|
+
console.log("job removed");
|
|
44
50
|
}
|
|
45
51
|
else {
|
|
52
|
+
console.log("handle job");
|
|
46
53
|
const newJob = await jobHandler.handlerFn({ ...job }, tx);
|
|
54
|
+
console.log("return new job", newJob);
|
|
47
55
|
if (job.at) {
|
|
48
56
|
if (!newJob) {
|
|
49
57
|
await this.removeJob(job.id, tx);
|
|
@@ -53,9 +61,11 @@ export class AbstractJobScheduler {
|
|
|
53
61
|
await this.afterJob(newJob, tx);
|
|
54
62
|
}
|
|
55
63
|
}
|
|
56
|
-
this.logger.debug("Job tx commiting");
|
|
57
64
|
}
|
|
65
|
+
console.log("commiting job");
|
|
66
|
+
this.logger.debug("Job tx commiting");
|
|
58
67
|
await tx.commit();
|
|
68
|
+
console.log("job commiited");
|
|
59
69
|
this.logger.debug("Job tx committed");
|
|
60
70
|
}
|
|
61
71
|
catch (err) {
|
|
@@ -34,8 +34,10 @@ let AwsJobScheduler = class AwsJobScheduler extends AbstractJobScheduler {
|
|
|
34
34
|
this.eventBusName = eventBusName;
|
|
35
35
|
}
|
|
36
36
|
async handleCron(jobInfo) {
|
|
37
|
+
console.log("handleCron in AwsJobScheduler", jobInfo);
|
|
37
38
|
this.logger.debug(`Handle cron`, jobInfo);
|
|
38
39
|
await this.executeJob(jobInfo);
|
|
40
|
+
console.log("after execute job");
|
|
39
41
|
}
|
|
40
42
|
async afterJob(_job, _tx) {
|
|
41
43
|
//-- do nothing
|
|
@@ -95,7 +95,9 @@ export class LambdaWrapper {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
async handler(event) {
|
|
98
|
+
console.log("Raw lambda event", event);
|
|
98
99
|
const requestOptions = this.requestMapper(event);
|
|
100
|
+
console.log("after map event", requestOptions);
|
|
99
101
|
const corsHeaders = convertCorsToHeaders(requestOptions?.headers?.origin || "", this.httpRequestHandler?.corsConfig);
|
|
100
102
|
try {
|
|
101
103
|
await this.bootServer();
|
|
@@ -106,7 +108,9 @@ export class LambdaWrapper {
|
|
|
106
108
|
return toApiGatewayFormat({ code: 200, headers: corsHeaders, cookies: {} });
|
|
107
109
|
}
|
|
108
110
|
if (requestOptions.method === CRON_REQUEST_METHOD) {
|
|
111
|
+
console.log("handling cron");
|
|
109
112
|
await this.jobScheduler?.handleCron(requestOptions.body);
|
|
113
|
+
console.log("handling cron done");
|
|
110
114
|
return toApiGatewayFormat({ code: 200, headers: corsHeaders, cookies: {} });
|
|
111
115
|
}
|
|
112
116
|
if (Object.values(HttpMethod).includes(requestOptions.method)) {
|
|
@@ -141,6 +145,7 @@ export class LambdaWrapper {
|
|
|
141
145
|
return toApiGatewayFormat({ code: 200, headers: corsHeaders, cookies: {} });
|
|
142
146
|
}
|
|
143
147
|
catch (err) {
|
|
148
|
+
console.log(err);
|
|
144
149
|
this.logger?.error(err);
|
|
145
150
|
return toApiGatewayFormat({
|
|
146
151
|
code: typeof err.code === "number" ? err.code : 500,
|
|
@@ -12,6 +12,7 @@ const parseCookie = (cookieArray) => {
|
|
|
12
12
|
};
|
|
13
13
|
export const lambdaRequestMapper = (event) => {
|
|
14
14
|
if (event.requestContext.eventType) {
|
|
15
|
+
console.log("map socket");
|
|
15
16
|
//-- socket
|
|
16
17
|
const method = event.requestContext.eventType.toLowerCase();
|
|
17
18
|
const body = event.body && JSON.parse(event.body);
|
|
@@ -22,6 +23,7 @@ export const lambdaRequestMapper = (event) => {
|
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
if (event.requestContext.cronScheduler) {
|
|
26
|
+
console.log("map cron");
|
|
25
27
|
//-- cron scheduler
|
|
26
28
|
return {
|
|
27
29
|
method: CRON_REQUEST_METHOD,
|
|
@@ -29,6 +31,7 @@ export const lambdaRequestMapper = (event) => {
|
|
|
29
31
|
body: event.requestContext.cronScheduler.data,
|
|
30
32
|
};
|
|
31
33
|
}
|
|
34
|
+
console.log("map http");
|
|
32
35
|
//-- http
|
|
33
36
|
return {
|
|
34
37
|
clientIP: event.requestContext.http.sourceIp,
|