@pikku/lambda 0.9.2 → 0.9.4-next.0
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/CHANGELOG.md +15 -0
- package/dist/queue/sqs-worker.js +20 -6
- package/dist/queue/sqs-worker.js.map +1 -1
- package/package.json +3 -4
- package/run-tests.sh +1 -1
- package/src/queue/sqs-worker.ts +26 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
## 0.8.0
|
|
2
2
|
|
|
3
|
+
## 0.9.4-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @pikku/core@0.9.12-next.0
|
|
9
|
+
|
|
10
|
+
## 0.9.3
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- c18800d: feat: adding queue and scheduledTask to interactions
|
|
15
|
+
- Updated dependencies [c18800d]
|
|
16
|
+
- @pikku/core@0.9.4
|
|
17
|
+
|
|
3
18
|
## 0.9.2
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/queue/sqs-worker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { runQueueJob } from '@pikku/core/queue';
|
|
1
|
+
import { runQueueJob, QueueJobFailedError, QueueJobDiscardedError, } from '@pikku/core/queue';
|
|
2
2
|
export function mapSQSRecordToQueueJob(record, maxAttempts) {
|
|
3
3
|
let data;
|
|
4
4
|
try {
|
|
@@ -36,11 +36,25 @@ export function mapSQSRecordToQueueJob(record, maxAttempts) {
|
|
|
36
36
|
export const runSQSQueueWorker = async (singletonServices, createSessionServices, event) => {
|
|
37
37
|
console.log(JSON.stringify(event, null, 2));
|
|
38
38
|
const jobs = event.Records.map(mapSQSRecordToQueueJob);
|
|
39
|
-
const results = await Promise.allSettled(jobs.map((job) =>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
const results = await Promise.allSettled(jobs.map(async (job) => {
|
|
40
|
+
try {
|
|
41
|
+
return await runQueueJob({
|
|
42
|
+
singletonServices,
|
|
43
|
+
createSessionServices,
|
|
44
|
+
job,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (error instanceof QueueJobFailedError) {
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
else if (error instanceof QueueJobDiscardedError) {
|
|
52
|
+
singletonServices.logger.info(`SQS job ${job.id} discarded: ${error.message}`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}));
|
|
44
58
|
results.forEach((result, index) => {
|
|
45
59
|
if (result.status === 'rejected') {
|
|
46
60
|
singletonServices.logger.error(`Failed to process SQS message ${jobs[index].id}:`, result.reason);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqs-worker.js","sourceRoot":"","sources":["../../src/queue/sqs-worker.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"sqs-worker.js","sourceRoot":"","sources":["../../src/queue/sqs-worker.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,mBAAmB,CAAA;AAW1B,MAAM,UAAU,sBAAsB,CACpC,MAAiB,EACjB,WAAoB;IAEpB,IAAI,IAAS,CAAA;IAEb,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;IACpB,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;IAC5D,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CA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"license": "MIT",
|
|
5
5
|
"author": "yasser.fadl@gmail.com",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"tsc": "tsc",
|
|
11
11
|
"ncu": "npx npm-check-updates",
|
|
12
|
-
"build
|
|
13
|
-
"build": "yarn build:esm",
|
|
12
|
+
"build": "tsc -b",
|
|
14
13
|
"release": "npm run build && npm test",
|
|
15
14
|
"test": "bash run-tests.sh",
|
|
16
15
|
"test:watch": "bash run-tests.sh --watch",
|
|
@@ -24,7 +23,7 @@
|
|
|
24
23
|
},
|
|
25
24
|
"peerDependencies": {
|
|
26
25
|
"@aws-sdk/client-apigatewaymanagementapi": "^3.713.0",
|
|
27
|
-
"@pikku/core": "^0.9.
|
|
26
|
+
"@pikku/core": "^0.9.12-next.0",
|
|
28
27
|
"@types/aws-lambda": "^8.10.146"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
package/run-tests.sh
CHANGED
|
@@ -46,7 +46,7 @@ if [ "$watch_mode" = true ]; then
|
|
|
46
46
|
fi
|
|
47
47
|
|
|
48
48
|
if [ "$coverage_mode" = true ]; then
|
|
49
|
-
node_cmd="$node_cmd --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info"
|
|
49
|
+
node_cmd="$node_cmd --test-coverage-include=\"src/**/*.{ts,js}\" --test-coverage-exclude=\"**/dist/**\" --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info"
|
|
50
50
|
fi
|
|
51
51
|
|
|
52
52
|
# Execute the node command with the expanded list of files
|
package/src/queue/sqs-worker.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { SQSBatchResponse, SQSEvent, SQSRecord } from 'aws-lambda'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
runQueueJob,
|
|
4
|
+
QueueJobFailedError,
|
|
5
|
+
QueueJobDiscardedError,
|
|
6
|
+
} from '@pikku/core/queue'
|
|
3
7
|
import type {
|
|
4
8
|
CoreSingletonServices,
|
|
5
9
|
CreateSessionServices,
|
|
@@ -66,13 +70,27 @@ export const runSQSQueueWorker = async (
|
|
|
66
70
|
|
|
67
71
|
// Process all jobs in parallel
|
|
68
72
|
const results = await Promise.allSettled(
|
|
69
|
-
jobs.map((job) =>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
jobs.map(async (job) => {
|
|
74
|
+
try {
|
|
75
|
+
return await runQueueJob({
|
|
76
|
+
singletonServices,
|
|
77
|
+
createSessionServices,
|
|
78
|
+
job,
|
|
79
|
+
})
|
|
80
|
+
} catch (error: unknown) {
|
|
81
|
+
if (error instanceof QueueJobFailedError) {
|
|
82
|
+
// Let SQS handle this as a failed job (will go to retry or DLQ)
|
|
83
|
+
throw error
|
|
84
|
+
} else if (error instanceof QueueJobDiscardedError) {
|
|
85
|
+
// For SQS, discarding means completing successfully (no retry)
|
|
86
|
+
singletonServices.logger.info(
|
|
87
|
+
`SQS job ${job.id} discarded: ${error.message}`
|
|
88
|
+
)
|
|
89
|
+
return // Successfully "completed" by discarding
|
|
90
|
+
}
|
|
91
|
+
throw error
|
|
92
|
+
}
|
|
93
|
+
})
|
|
76
94
|
)
|
|
77
95
|
|
|
78
96
|
// Log any failures but don't throw (SQS will handle retries)
|