@mbc-cqrs-serverless/import 1.0.17 → 1.0.18
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
|
@@ -219,6 +219,37 @@ enum ComparisonStatus {
|
|
|
219
219
|
| `COMPLETED` | Successfully completed |
|
|
220
220
|
| `FAILED` | Processing failed |
|
|
221
221
|
|
|
222
|
+
### ImportStatusHandler
|
|
223
|
+
|
|
224
|
+
The `ImportStatusHandler` is an internal event handler that manages Step Functions callbacks for import jobs. When using Step Functions orchestration (ZIP imports or STEP_FUNCTION mode CSV imports), this handler ensures proper communication with the state machine.
|
|
225
|
+
|
|
226
|
+
#### Behavior
|
|
227
|
+
|
|
228
|
+
| Import Status | Action | Step Functions Command |
|
|
229
|
+
|---------------|--------|----------------------|
|
|
230
|
+
| `COMPLETED` | Send success callback | `SendTaskSuccessCommand` |
|
|
231
|
+
| `FAILED` | Send failure callback | `SendTaskFailureCommand` |
|
|
232
|
+
| Other statuses | Ignored | None |
|
|
233
|
+
|
|
234
|
+
#### Methods
|
|
235
|
+
|
|
236
|
+
| Method | Description |
|
|
237
|
+
|--------|-------------|
|
|
238
|
+
| `sendTaskSuccess(taskToken, output)` | Sends success signal to Step Functions with the import result |
|
|
239
|
+
| `sendTaskFailure(taskToken, error, cause)` | Sends failure signal to Step Functions with error details |
|
|
240
|
+
|
|
241
|
+
#### Step Functions Integration
|
|
242
|
+
|
|
243
|
+
When an import job is created as part of a Step Functions workflow (e.g., ZIP import), a `taskToken` is stored in the job's attributes. The `ImportStatusHandler` listens for status change notifications and:
|
|
244
|
+
|
|
245
|
+
1. Retrieves the import job from DynamoDB
|
|
246
|
+
2. Checks if a `taskToken` exists in the job's attributes
|
|
247
|
+
3. Sends the appropriate callback based on the final status:
|
|
248
|
+
- `COMPLETED` → `SendTaskSuccessCommand` with result data
|
|
249
|
+
- `FAILED` → `SendTaskFailureCommand` with error details
|
|
250
|
+
|
|
251
|
+
This ensures Step Functions workflows properly handle both success and failure cases without hanging indefinitely.
|
|
252
|
+
|
|
222
253
|
## Usage Examples
|
|
223
254
|
|
|
224
255
|
### REST API Import
|
|
@@ -13,4 +13,11 @@ export declare class ImportStatusHandler implements IEventHandler<ImportStatusQu
|
|
|
13
13
|
* @param output The JSON output to send back to the state machine.
|
|
14
14
|
*/
|
|
15
15
|
sendTaskSuccess(taskToken: string, output: any): Promise<import("@aws-sdk/client-sfn").SendTaskSuccessCommandOutput>;
|
|
16
|
+
/**
|
|
17
|
+
* Sends a failure signal to a waiting Step Function task.
|
|
18
|
+
* @param taskToken The unique token of the paused task.
|
|
19
|
+
* @param error The error code to send back to the state machine.
|
|
20
|
+
* @param cause The detailed cause of the failure (will be JSON stringified).
|
|
21
|
+
*/
|
|
22
|
+
sendTaskFailure(taskToken: string, error: string, cause: any): Promise<import("@aws-sdk/client-sfn").SendTaskFailureCommandOutput>;
|
|
16
23
|
}
|
|
@@ -26,14 +26,17 @@ let ImportStatusHandler = ImportStatusHandler_1 = class ImportStatusHandler {
|
|
|
26
26
|
}
|
|
27
27
|
async execute(event) {
|
|
28
28
|
const notification = JSON.parse(event.body);
|
|
29
|
-
// 1. Filter for
|
|
29
|
+
// 1. Filter for specific events: completed or failed master CSV jobs.
|
|
30
30
|
const pk = notification.pk;
|
|
31
31
|
const status = notification.content?.status;
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
// Only process COMPLETED or FAILED status for CSV_IMPORT jobs
|
|
33
|
+
const isTerminalStatus = status === enum_1.ImportStatusEnum.COMPLETED ||
|
|
34
|
+
status === enum_1.ImportStatusEnum.FAILED;
|
|
35
|
+
const isCsvImportJob = pk?.startsWith(`${constant_1.CSV_IMPORT_PK_PREFIX}${core_1.KEY_SEPARATOR}`);
|
|
36
|
+
if (!isTerminalStatus || !isCsvImportJob) {
|
|
34
37
|
return;
|
|
35
38
|
}
|
|
36
|
-
this.logger.log(`Received
|
|
39
|
+
this.logger.log(`Received ${status} master CSV job event for: ${notification.id}`);
|
|
37
40
|
try {
|
|
38
41
|
// 2. Get the full import job entity from DynamoDB.
|
|
39
42
|
const importKey = { pk: notification.pk, sk: notification.sk };
|
|
@@ -45,10 +48,14 @@ let ImportStatusHandler = ImportStatusHandler_1 = class ImportStatusHandler {
|
|
|
45
48
|
// 3. Check if a taskToken was saved in its attributes.
|
|
46
49
|
const taskToken = importJob.attributes?.taskToken;
|
|
47
50
|
if (taskToken) {
|
|
48
|
-
this.logger.log(`Found task token.
|
|
49
|
-
// 4. Send the
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
this.logger.log(`Found task token. Sending ${status} signal to Step Function.`);
|
|
52
|
+
// 4. Send the appropriate signal based on status.
|
|
53
|
+
if (status === enum_1.ImportStatusEnum.COMPLETED) {
|
|
54
|
+
await this.sendTaskSuccess(taskToken, importJob.result);
|
|
55
|
+
}
|
|
56
|
+
else if (status === enum_1.ImportStatusEnum.FAILED) {
|
|
57
|
+
await this.sendTaskFailure(taskToken, 'ImportFailed', importJob.result);
|
|
58
|
+
}
|
|
52
59
|
}
|
|
53
60
|
else {
|
|
54
61
|
this.logger.log('No task token found in import job attributes. Nothing to do.');
|
|
@@ -71,6 +78,20 @@ let ImportStatusHandler = ImportStatusHandler_1 = class ImportStatusHandler {
|
|
|
71
78
|
output: JSON.stringify(output),
|
|
72
79
|
}));
|
|
73
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Sends a failure signal to a waiting Step Function task.
|
|
83
|
+
* @param taskToken The unique token of the paused task.
|
|
84
|
+
* @param error The error code to send back to the state machine.
|
|
85
|
+
* @param cause The detailed cause of the failure (will be JSON stringified).
|
|
86
|
+
*/
|
|
87
|
+
async sendTaskFailure(taskToken, error, cause) {
|
|
88
|
+
this.logger.log(`Sending task failure for token: ${taskToken}`);
|
|
89
|
+
return this.sfnService.client.send(new client_sfn_1.SendTaskFailureCommand({
|
|
90
|
+
taskToken: taskToken,
|
|
91
|
+
error: error,
|
|
92
|
+
cause: JSON.stringify(cause),
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
74
95
|
};
|
|
75
96
|
exports.ImportStatusHandler = ImportStatusHandler;
|
|
76
97
|
exports.ImportStatusHandler = ImportStatusHandler = ImportStatusHandler_1 = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-status.queue.event.handler.js","sourceRoot":"","sources":["../../src/event/import-status.queue.event.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"import-status.queue.event.handler.js","sourceRoot":"","sources":["../../src/event/import-status.queue.event.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,oDAG4B;AAC5B,oDAMkC;AAClC,2CAAmD;AAEnD,0CAAkD;AAClD,sDAAiD;AACjD,2EAAoE;AACpE,kCAA0C;AAInC,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAK9B,YACmB,aAA4B,EAC5B,UAA+B;QAD/B,kBAAa,GAAb,aAAa,CAAe;QAC5B,eAAU,GAAV,UAAU,CAAqB;QAJjC,WAAM,GAAG,IAAI,eAAM,CAAC,qBAAmB,CAAC,IAAI,CAAC,CAAA;IAK3D,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,KAA6B;QACzC,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAE3C,sEAAsE;QACtE,MAAM,EAAE,GAAG,YAAY,CAAC,EAAY,CAAA;QACpC,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,EAAE,MAAM,CAAA;QAE3C,8DAA8D;QAC9D,MAAM,gBAAgB,GACpB,MAAM,KAAK,uBAAgB,CAAC,SAAS;YACrC,MAAM,KAAK,uBAAgB,CAAC,MAAM,CAAA;QACpC,MAAM,cAAc,GAAG,EAAE,EAAE,UAAU,CACnC,GAAG,+BAAoB,GAAG,oBAAa,EAAE,CAC1C,CAAA;QAED,IAAI,CAAC,gBAAgB,IAAI,CAAC,cAAc,EAAE,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AAC;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,eAAe,CAAC,SAAiB,EAAE,MAAW;QAClD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,mCAAmC,SAAS,EAAE,CAAC,CAAA;QAC/D,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAChC,IAAI,mCAAsB,CAAC;YACzB,SAAS,EAAE,SAAS;YACpB,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;SAC/B,CAAC,CACH,CAAA;IACH,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,eAAe,CAAC,SAAiB,EAAE,KAAa,EAAE,KAAU;QAChE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,mCAAmC,SAAS,EAAE,CAAC,CAAA;QAC/D,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAChC,IAAI,mCAAsB,CAAC;YACzB,SAAS,EAAE,SAAS;YACpB,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;SAC7B,CAAC,CACH,CAAA;IACH,CAAC;CACF,CAAA;AAtGY,kDAAmB;8BAAnB,mBAAmB;IAF/B,IAAA,mBAAU,GAAE;IACZ,IAAA,mBAAY,EAAC,kDAAsB,CAAC;qCAOD,8BAAa;QAChB,0BAAmB;GAPvC,mBAAmB,CAsG/B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mbc-cqrs-serverless/import",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
4
4
|
"description": "Import module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mbc",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@mbc-cqrs-serverless/core": "1.0.
|
|
44
|
+
"@mbc-cqrs-serverless/core": "1.0.18",
|
|
45
45
|
"csv-parser": "^3.2.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "f94a747c55ac4b09a643a5201dc89e4edda19c76"
|
|
48
48
|
}
|