@clairejs/server 3.22.13 → 3.22.15
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
|
@@ -119,10 +119,11 @@ let DefaultHttpRequestHandler = class DefaultHttpRequestHandler extends Abstract
|
|
|
119
119
|
return response;
|
|
120
120
|
}
|
|
121
121
|
catch (err) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
.
|
|
125
|
-
|
|
122
|
+
const errCode = err.code || 500;
|
|
123
|
+
if (errCode >= 500) {
|
|
124
|
+
this.logger.error(err);
|
|
125
|
+
}
|
|
126
|
+
const response = ResponseBuilder.json({ name: err.name, message: err.message }).status(errCode).get();
|
|
126
127
|
this.logger.info(`===== REQUEST FAILED: ${requestId} - ${httpData.method}:${httpData.fullPath}, code: ${response.code}`, response.value);
|
|
127
128
|
return response;
|
|
128
129
|
}
|
|
@@ -33,25 +33,17 @@ export class AbstractJobScheduler {
|
|
|
33
33
|
*/
|
|
34
34
|
async executeJob(job) {
|
|
35
35
|
//-- run job
|
|
36
|
-
console.log("executeJob", job);
|
|
37
36
|
const allJobs = await this.getAvailableJobInfo();
|
|
38
|
-
console.log("alljobs", allJobs);
|
|
39
37
|
const jobHandler = allJobs.find((j) => j.jobName === job.jobName);
|
|
40
|
-
console.log("creating transaction");
|
|
41
38
|
const tx = await this.db.createTransaction();
|
|
42
|
-
console.log("transaction created");
|
|
43
39
|
try {
|
|
44
40
|
if (!jobHandler) {
|
|
45
|
-
console.log("removing job");
|
|
46
41
|
//-- remove job
|
|
47
42
|
this.logger.info(`Remove job with id: ${job.id} as handler is not found`);
|
|
48
43
|
await this.removeJob(job.id, tx);
|
|
49
|
-
console.log("job removed");
|
|
50
44
|
}
|
|
51
45
|
else {
|
|
52
|
-
console.log("handle job");
|
|
53
46
|
const newJob = await jobHandler.handlerFn({ ...job }, tx);
|
|
54
|
-
console.log("return new job", newJob);
|
|
55
47
|
if (job.at) {
|
|
56
48
|
if (!newJob) {
|
|
57
49
|
await this.removeJob(job.id, tx);
|
|
@@ -62,10 +54,8 @@ export class AbstractJobScheduler {
|
|
|
62
54
|
}
|
|
63
55
|
}
|
|
64
56
|
}
|
|
65
|
-
console.log("commiting job");
|
|
66
57
|
this.logger.debug("Job tx commiting");
|
|
67
58
|
await tx.commit();
|
|
68
|
-
console.log("job commiited");
|
|
69
59
|
this.logger.debug("Job tx committed");
|
|
70
60
|
}
|
|
71
61
|
catch (err) {
|
|
@@ -34,10 +34,8 @@ 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);
|
|
38
37
|
this.logger.debug(`Handle cron`, jobInfo);
|
|
39
38
|
await this.executeJob(jobInfo);
|
|
40
|
-
console.log("after execute job");
|
|
41
39
|
}
|
|
42
40
|
async afterJob(_job, _tx) {
|
|
43
41
|
//-- do nothing
|
|
@@ -95,9 +95,7 @@ export class LambdaWrapper {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
async handler(event) {
|
|
98
|
-
console.log("Raw lambda event", event);
|
|
99
98
|
const requestOptions = this.requestMapper(event);
|
|
100
|
-
console.log("after map event", requestOptions);
|
|
101
99
|
const corsHeaders = convertCorsToHeaders(requestOptions?.headers?.origin || "", this.httpRequestHandler?.corsConfig);
|
|
102
100
|
try {
|
|
103
101
|
await this.bootServer();
|
|
@@ -108,9 +106,7 @@ export class LambdaWrapper {
|
|
|
108
106
|
return toApiGatewayFormat({ code: 200, headers: corsHeaders, cookies: {} });
|
|
109
107
|
}
|
|
110
108
|
if (requestOptions.method === CRON_REQUEST_METHOD) {
|
|
111
|
-
console.log("handling cron");
|
|
112
109
|
await this.jobScheduler?.handleCron(requestOptions.body);
|
|
113
|
-
console.log("handling cron done");
|
|
114
110
|
return toApiGatewayFormat({ code: 200, headers: corsHeaders, cookies: {} });
|
|
115
111
|
}
|
|
116
112
|
if (Object.values(HttpMethod).includes(requestOptions.method)) {
|
|
@@ -12,7 +12,6 @@ const parseCookie = (cookieArray) => {
|
|
|
12
12
|
};
|
|
13
13
|
export const lambdaRequestMapper = (event) => {
|
|
14
14
|
if (event.requestContext.eventType) {
|
|
15
|
-
console.log("map socket");
|
|
16
15
|
//-- socket
|
|
17
16
|
const method = event.requestContext.eventType.toLowerCase();
|
|
18
17
|
const body = event.body && JSON.parse(event.body);
|
|
@@ -23,7 +22,6 @@ export const lambdaRequestMapper = (event) => {
|
|
|
23
22
|
};
|
|
24
23
|
}
|
|
25
24
|
if (event.requestContext.cronScheduler) {
|
|
26
|
-
console.log("map cron");
|
|
27
25
|
//-- cron scheduler
|
|
28
26
|
return {
|
|
29
27
|
method: CRON_REQUEST_METHOD,
|
|
@@ -31,7 +29,6 @@ export const lambdaRequestMapper = (event) => {
|
|
|
31
29
|
body: event.requestContext.cronScheduler.data,
|
|
32
30
|
};
|
|
33
31
|
}
|
|
34
|
-
console.log("map http");
|
|
35
32
|
//-- http
|
|
36
33
|
return {
|
|
37
34
|
clientIP: event.requestContext.http.sourceIp,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clairejs/server",
|
|
3
|
-
"version": "3.22.
|
|
3
|
+
"version": "3.22.15",
|
|
4
4
|
"description": "Claire server NodeJs framework written in Typescript.",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"ws": "^7.5.5"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@clairejs/client": "^3.4.
|
|
36
|
+
"@clairejs/client": "^3.4.6",
|
|
37
37
|
"@clairejs/core": "^3.8.10",
|
|
38
|
-
"@clairejs/orm": "^3.16.
|
|
38
|
+
"@clairejs/orm": "^3.16.25"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/cookie-parser": "^1.4.3",
|