vtlab-generic-functions 1.0.39 → 1.0.40
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/lambdaClass/index.js +25 -4
- package/package.json +1 -1
package/lambdaClass/index.js
CHANGED
|
@@ -57,14 +57,24 @@ module.exports = class Lambda {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
recoverFullPayload = async () => {
|
|
60
|
-
if (this.event?.s3PayloadPath) {
|
|
61
|
-
let contentResponse = await this.s3.download(this.event.s3PayloadPath);
|
|
60
|
+
if (this.event?.s3PayloadPath || this.event?.payloadS3Key) {
|
|
61
|
+
let contentResponse = await this.s3.download(this.event.s3PayloadPath || this.event.payloadS3Key);
|
|
62
62
|
this.jobs = JSON.parse(contentResponse.Body.toString());
|
|
63
63
|
} else {
|
|
64
64
|
this.jobs = this.event?.payload || [];
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
+
initialize = async () => {
|
|
69
|
+
try {
|
|
70
|
+
if(this.event?.s3PayloadPath || this.event?.payloadS3Key) {
|
|
71
|
+
await this.recoverFullPayload();
|
|
72
|
+
}
|
|
73
|
+
} catch (error) {
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
68
78
|
s3 = {
|
|
69
79
|
upload: async (data, path, options = {}) => {
|
|
70
80
|
return await s3bucket.uploadToS3(path, data, {
|
|
@@ -265,7 +275,18 @@ module.exports = class Lambda {
|
|
|
265
275
|
return objToReturn;
|
|
266
276
|
};
|
|
267
277
|
|
|
268
|
-
|
|
278
|
+
uploadResultToS3 = async () => {
|
|
279
|
+
return await this.s3.upload(Buffer.from(utils.dataToString(this.results, "data").res), `tmp/results/${this.carrier}-${new Date().getTime()}.json`);
|
|
280
|
+
};
|
|
281
|
+
endSuccess = async () => {
|
|
282
|
+
//check if the response is bigger than 6291400 bytes
|
|
283
|
+
if(Buffer.byteLength(utils.dataToString(this.results, "data").res) > 6291400) {
|
|
284
|
+
return {
|
|
285
|
+
isBase64Encoded: false, statusCode: 200, body: utils.dataToString({
|
|
286
|
+
pathS3Result: (await this.uploadResultToS3())
|
|
287
|
+
}, "data").res,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
269
290
|
return {
|
|
270
291
|
isBase64Encoded: false, statusCode: 200, body: utils.dataToString(this.results, "data").res,
|
|
271
292
|
};
|
|
@@ -282,4 +303,4 @@ module.exports = class Lambda {
|
|
|
282
303
|
const encodedToken = Buffer.from(token).toString("base64");
|
|
283
304
|
return encodedToken;
|
|
284
305
|
};
|
|
285
|
-
};
|
|
306
|
+
};
|