@mbc-cqrs-serverless/task 0.1.52-beta.0 → 0.1.53-beta.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/dist/entity/index.d.ts +1 -0
- package/dist/entity/index.js +1 -0
- package/dist/entity/index.js.map +1 -1
- package/dist/entity/sub-task.entity.d.ts +22 -0
- package/dist/entity/sub-task.entity.js +24 -0
- package/dist/entity/sub-task.entity.js.map +1 -0
- package/dist/entity/task.entity.d.ts +5 -0
- package/dist/entity/task.entity.js.map +1 -1
- package/dist/enums/index.d.ts +1 -0
- package/dist/enums/index.js +1 -0
- package/dist/enums/index.js.map +1 -1
- package/dist/enums/types.enum.d.ts +4 -0
- package/dist/enums/types.enum.js +9 -0
- package/dist/enums/types.enum.js.map +1 -0
- package/dist/event/index.d.ts +4 -0
- package/dist/event/index.js +4 -0
- package/dist/event/index.js.map +1 -1
- package/dist/event/sub-task.queue.event.d.ts +18 -0
- package/dist/event/sub-task.queue.event.handler.d.ts +9 -0
- package/dist/event/sub-task.queue.event.handler.js +45 -0
- package/dist/event/sub-task.queue.event.handler.js.map +1 -0
- package/dist/event/sub-task.queue.event.js +25 -0
- package/dist/event/sub-task.queue.event.js.map +1 -0
- package/dist/event/task.queue.event-factory.interface.d.ts +6 -2
- package/dist/event/task.queue.event-factory.interface.js +19 -2
- package/dist/event/task.queue.event-factory.interface.js.map +1 -1
- package/dist/event/task.queue.event.handler.d.ts +8 -2
- package/dist/event/task.queue.event.handler.js +53 -2
- package/dist/event/task.queue.event.handler.js.map +1 -1
- package/dist/event/task.sfn.event.d.ts +16 -0
- package/dist/event/task.sfn.event.handler.d.ts +16 -0
- package/dist/event/task.sfn.event.handler.js +70 -0
- package/dist/event/task.sfn.event.handler.js.map +1 -0
- package/dist/event/task.sfn.event.js +19 -0
- package/dist/event/task.sfn.event.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.ts +1 -0
- package/dist/interfaces/index.js +18 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/task-service.interface.d.ts +52 -0
- package/dist/interfaces/task-service.interface.js +3 -0
- package/dist/interfaces/task-service.interface.js.map +1 -0
- package/dist/task.controller.d.ts +2 -1
- package/dist/task.controller.js +17 -3
- package/dist/task.controller.js.map +1 -1
- package/dist/task.module.js +10 -2
- package/dist/task.module.js.map +1 -1
- package/dist/task.service.d.ts +29 -4
- package/dist/task.service.js +131 -9
- package/dist/task.service.js.map +1 -1
- package/package.json +3 -3
package/dist/entity/index.d.ts
CHANGED
package/dist/entity/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./sub-task.entity"), exports);
|
|
17
18
|
__exportStar(require("./task.entity"), exports);
|
|
18
19
|
__exportStar(require("./task-list.entity"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
package/dist/entity/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entity/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B;AAC7B,qDAAkC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entity/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,gDAA6B;AAC7B,qDAAkC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CommandEntity } from '@mbc-cqrs-serverless/core';
|
|
2
|
+
import { TaskStatusEnum } from '../enums/status.enum';
|
|
3
|
+
/**
|
|
4
|
+
* Task data structure
|
|
5
|
+
* - pk: TASK#tenantCode
|
|
6
|
+
* - sk: taskType#uuid#order
|
|
7
|
+
* - code: taskType#uuid
|
|
8
|
+
* - name: name || taskType
|
|
9
|
+
* - tenant_code: tenantCode
|
|
10
|
+
* - status: TASK_STATUS
|
|
11
|
+
* - attributes
|
|
12
|
+
* - result
|
|
13
|
+
* - error
|
|
14
|
+
*/
|
|
15
|
+
export declare class SubTaskEntity extends CommandEntity {
|
|
16
|
+
status?: TaskStatusEnum;
|
|
17
|
+
attributes?: {
|
|
18
|
+
result?: any;
|
|
19
|
+
error?: any;
|
|
20
|
+
};
|
|
21
|
+
constructor(partial: Partial<SubTaskEntity>);
|
|
22
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SubTaskEntity = void 0;
|
|
4
|
+
const core_1 = require("@mbc-cqrs-serverless/core");
|
|
5
|
+
/**
|
|
6
|
+
* Task data structure
|
|
7
|
+
* - pk: TASK#tenantCode
|
|
8
|
+
* - sk: taskType#uuid#order
|
|
9
|
+
* - code: taskType#uuid
|
|
10
|
+
* - name: name || taskType
|
|
11
|
+
* - tenant_code: tenantCode
|
|
12
|
+
* - status: TASK_STATUS
|
|
13
|
+
* - attributes
|
|
14
|
+
* - result
|
|
15
|
+
* - error
|
|
16
|
+
*/
|
|
17
|
+
class SubTaskEntity extends core_1.CommandEntity {
|
|
18
|
+
constructor(partial) {
|
|
19
|
+
super();
|
|
20
|
+
Object.assign(this, partial);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.SubTaskEntity = SubTaskEntity;
|
|
24
|
+
//# sourceMappingURL=sub-task.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sub-task.entity.js","sourceRoot":"","sources":["../../src/entity/sub-task.entity.ts"],"names":[],"mappings":";;;AAAA,oDAAyD;AAIzD;;;;;;;;;;;GAWG;AACH,MAAa,aAAc,SAAQ,oBAAa;IAO9C,YAAY,OAA+B;QACzC,KAAK,EAAE,CAAA;QACP,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC9B,CAAC;CACF;AAXD,sCAWC"}
|
|
@@ -20,6 +20,11 @@ export declare class TaskEntity extends CommandEntity {
|
|
|
20
20
|
attributes?: {
|
|
21
21
|
result?: any;
|
|
22
22
|
error?: any;
|
|
23
|
+
subTaskCount?: number;
|
|
24
|
+
subTaskFailedCount?: number;
|
|
25
|
+
subTaskRunningCount?: number;
|
|
26
|
+
subTaskSucceedCount?: number;
|
|
27
|
+
subTasks?: any;
|
|
23
28
|
};
|
|
24
29
|
constructor(partial: Partial<TaskEntity>);
|
|
25
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task.entity.js","sourceRoot":"","sources":["../../src/entity/task.entity.ts"],"names":[],"mappings":";;;AAAA,oDAAyD;AAIzD;;;;;;;;;;;;;GAaG;AACH,MAAa,UAAW,SAAQ,oBAAa;
|
|
1
|
+
{"version":3,"file":"task.entity.js","sourceRoot":"","sources":["../../src/entity/task.entity.ts"],"names":[],"mappings":";;;AAAA,oDAAyD;AAIzD;;;;;;;;;;;;;GAaG;AACH,MAAa,UAAW,SAAQ,oBAAa;IAa3C,YAAY,OAA4B;QACtC,KAAK,EAAE,CAAA;QACP,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC9B,CAAC;CACF;AAjBD,gCAiBC"}
|
package/dist/enums/index.d.ts
CHANGED
package/dist/enums/index.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./status.enum"), exports);
|
|
18
|
+
__exportStar(require("./types.enum"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
package/dist/enums/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/enums/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/enums/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B;AAC7B,+CAA4B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaskTypesEnum = void 0;
|
|
4
|
+
var TaskTypesEnum;
|
|
5
|
+
(function (TaskTypesEnum) {
|
|
6
|
+
TaskTypesEnum["TASK"] = "TASK";
|
|
7
|
+
TaskTypesEnum["SFN_TASK"] = "SFN_TASK";
|
|
8
|
+
})(TaskTypesEnum || (exports.TaskTypesEnum = TaskTypesEnum = {}));
|
|
9
|
+
//# sourceMappingURL=types.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.enum.js","sourceRoot":"","sources":["../../src/enums/types.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,8BAAa,CAAA;IACb,sCAAqB,CAAA;AACvB,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB"}
|
package/dist/event/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
export * from './sub-task.queue.event';
|
|
2
|
+
export * from './sub-task.queue.event.handler';
|
|
1
3
|
export * from './task.event';
|
|
2
4
|
export * from './task.event.handler';
|
|
3
5
|
export * from './task.queue.event';
|
|
4
6
|
export * from './task.queue.event.handler';
|
|
5
7
|
export * from './task.queue.event-factory.interface';
|
|
8
|
+
export * from './task.sfn.event';
|
|
9
|
+
export * from './task.sfn.event.handler';
|
package/dist/event/index.js
CHANGED
|
@@ -14,9 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./sub-task.queue.event"), exports);
|
|
18
|
+
__exportStar(require("./sub-task.queue.event.handler"), exports);
|
|
17
19
|
__exportStar(require("./task.event"), exports);
|
|
18
20
|
__exportStar(require("./task.event.handler"), exports);
|
|
19
21
|
__exportStar(require("./task.queue.event"), exports);
|
|
20
22
|
__exportStar(require("./task.queue.event.handler"), exports);
|
|
21
23
|
__exportStar(require("./task.queue.event-factory.interface"), exports);
|
|
24
|
+
__exportStar(require("./task.sfn.event"), exports);
|
|
25
|
+
__exportStar(require("./task.sfn.event.handler"), exports);
|
|
22
26
|
//# sourceMappingURL=index.js.map
|
package/dist/event/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/event/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,uDAAoC;AACpC,qDAAkC;AAClC,6DAA0C;AAC1C,uEAAoD"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/event/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAsC;AACtC,iEAA8C;AAC9C,+CAA4B;AAC5B,uDAAoC;AACpC,qDAAkC;AAClC,6DAA0C;AAC1C,uEAAoD;AACpD,mDAAgC;AAChC,2DAAwC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IEvent } from '@mbc-cqrs-serverless/core';
|
|
2
|
+
import { SQSMessageAttributes, SQSRecord, SQSRecordAttributes } from 'aws-lambda';
|
|
3
|
+
import { SubTaskEntity } from '../entity';
|
|
4
|
+
export declare class SubTaskQueueEvent implements IEvent, SQSRecord {
|
|
5
|
+
source: string;
|
|
6
|
+
messageId: string;
|
|
7
|
+
receiptHandle: string;
|
|
8
|
+
body: string;
|
|
9
|
+
attributes: SQSRecordAttributes;
|
|
10
|
+
messageAttributes: SQSMessageAttributes;
|
|
11
|
+
md5OfBody: string;
|
|
12
|
+
eventSource: string;
|
|
13
|
+
eventSourceARN: string;
|
|
14
|
+
awsRegion: string;
|
|
15
|
+
private _subTaskEntity?;
|
|
16
|
+
fromSqsRecord(record: SQSRecord): SubTaskQueueEvent;
|
|
17
|
+
get subTaskEvent(): SubTaskEntity;
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IEventHandler } from '@mbc-cqrs-serverless/core';
|
|
2
|
+
import { TaskService } from '../task.service';
|
|
3
|
+
import { SubTaskQueueEvent } from './sub-task.queue.event';
|
|
4
|
+
export declare class SubTaskQueueEventHandler implements IEventHandler<SubTaskQueueEvent> {
|
|
5
|
+
private readonly taskService;
|
|
6
|
+
private readonly logger;
|
|
7
|
+
constructor(taskService: TaskService);
|
|
8
|
+
execute(event: SubTaskQueueEvent): Promise<any>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var SubTaskQueueEventHandler_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.SubTaskQueueEventHandler = void 0;
|
|
14
|
+
const core_1 = require("@mbc-cqrs-serverless/core");
|
|
15
|
+
const common_1 = require("@nestjs/common");
|
|
16
|
+
const status_enum_1 = require("../enums/status.enum");
|
|
17
|
+
const task_service_1 = require("../task.service");
|
|
18
|
+
const sub_task_queue_event_1 = require("./sub-task.queue.event");
|
|
19
|
+
let SubTaskQueueEventHandler = SubTaskQueueEventHandler_1 = class SubTaskQueueEventHandler {
|
|
20
|
+
constructor(taskService) {
|
|
21
|
+
this.taskService = taskService;
|
|
22
|
+
this.logger = new common_1.Logger(SubTaskQueueEventHandler_1.name);
|
|
23
|
+
}
|
|
24
|
+
async execute(event) {
|
|
25
|
+
this.logger.debug('sub task queue event executing::', event);
|
|
26
|
+
const task = event.subTaskEvent;
|
|
27
|
+
const subTasks = await this.taskService.getAllSubTask(task); // children key
|
|
28
|
+
console.log('subTasks', subTasks);
|
|
29
|
+
const taskStatus = await this.taskService.formatTaskStatus(subTasks);
|
|
30
|
+
console.log('taskStatus', taskStatus);
|
|
31
|
+
await this.taskService.updateStepFunctionTask({
|
|
32
|
+
pk: task.pk,
|
|
33
|
+
sk: task.sk.split(core_1.KEY_SEPARATOR).slice(0, -1).join(core_1.KEY_SEPARATOR),
|
|
34
|
+
}, taskStatus, taskStatus.subTaskSucceedCount + taskStatus.subTaskFailedCount ===
|
|
35
|
+
taskStatus.subTaskCount
|
|
36
|
+
? status_enum_1.TaskStatusEnum.COMPLETED
|
|
37
|
+
: status_enum_1.TaskStatusEnum.PROCESSING);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.SubTaskQueueEventHandler = SubTaskQueueEventHandler;
|
|
41
|
+
exports.SubTaskQueueEventHandler = SubTaskQueueEventHandler = SubTaskQueueEventHandler_1 = __decorate([
|
|
42
|
+
(0, core_1.EventHandler)(sub_task_queue_event_1.SubTaskQueueEvent),
|
|
43
|
+
__metadata("design:paramtypes", [task_service_1.TaskService])
|
|
44
|
+
], SubTaskQueueEventHandler);
|
|
45
|
+
//# sourceMappingURL=sub-task.queue.event.handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sub-task.queue.event.handler.js","sourceRoot":"","sources":["../../src/event/sub-task.queue.event.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,oDAIkC;AAClC,2CAAuC;AAEvC,sDAAqD;AACrD,kDAA6C;AAC7C,iEAA0D;AAGnD,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IAKnC,YAA6B,WAAwB;QAAxB,gBAAW,GAAX,WAAW,CAAa;QAFpC,WAAM,GAAG,IAAI,eAAM,CAAC,0BAAwB,CAAC,IAAI,CAAC,CAAA;IAEX,CAAC;IAEzD,KAAK,CAAC,OAAO,CAAC,KAAwB;QACpC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAA;QAE5D,MAAM,IAAI,GAAG,KAAK,CAAC,YAAY,CAAA;QAE/B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA,CAAC,eAAe;QAE3E,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;QAEjC,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAA;QAEpE,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;QAErC,MAAM,IAAI,CAAC,WAAW,CAAC,sBAAsB,CAC3C;YACE,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,oBAAa,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,oBAAa,CAAC;SAClE,EACD,UAAU,EACV,UAAU,CAAC,mBAAmB,GAAG,UAAU,CAAC,kBAAkB;YAC5D,UAAU,CAAC,YAAY;YACvB,CAAC,CAAC,4BAAc,CAAC,SAAS;YAC1B,CAAC,CAAC,4BAAc,CAAC,UAAU,CAC9B,CAAA;IACH,CAAC;CACF,CAAA;AAhCY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAY,EAAC,wCAAiB,CAAC;qCAMY,0BAAW;GAL1C,wBAAwB,CAgCpC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SubTaskQueueEvent = void 0;
|
|
4
|
+
const entity_1 = require("../entity");
|
|
5
|
+
class SubTaskQueueEvent {
|
|
6
|
+
fromSqsRecord(record) {
|
|
7
|
+
Object.assign(this, record, {
|
|
8
|
+
source: record.eventSourceARN,
|
|
9
|
+
});
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
get subTaskEvent() {
|
|
13
|
+
if (!this._subTaskEntity) {
|
|
14
|
+
const body = JSON.parse(this.body);
|
|
15
|
+
this._subTaskEntity = new entity_1.SubTaskEntity({
|
|
16
|
+
...body,
|
|
17
|
+
attributes: body.content.attributes,
|
|
18
|
+
status: body.content.status,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return this._subTaskEntity;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.SubTaskQueueEvent = SubTaskQueueEvent;
|
|
25
|
+
//# sourceMappingURL=sub-task.queue.event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sub-task.queue.event.js","sourceRoot":"","sources":["../../src/event/sub-task.queue.event.ts"],"names":[],"mappings":";;;AAOA,sCAAyC;AAEzC,MAAa,iBAAiB;IAc5B,aAAa,CAAC,MAAiB;QAC7B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE;YAC1B,MAAM,EAAE,MAAM,CAAC,cAAc;SAC9B,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,YAAY;QACd,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAClC,IAAI,CAAC,cAAc,GAAG,IAAI,sBAAa,CAAC;gBACtC,GAAG,IAAI;gBACP,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU;gBACnC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;aAC5B,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,cAAc,CAAA;IAC5B,CAAC;CACF;AAjCD,8CAiCC"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { DefaultEventFactory, IEvent } from '@mbc-cqrs-serverless/core';
|
|
1
|
+
import { DefaultEventFactory, IEvent, StepFunctionsEvent } from '@mbc-cqrs-serverless/core';
|
|
2
2
|
import { SQSEvent } from 'aws-lambda';
|
|
3
3
|
import { TaskQueueEvent } from './task.queue.event';
|
|
4
|
+
import { StepFunctionTaskEvent } from './task.sfn.event';
|
|
4
5
|
export declare const DEFAULT_TASK_ACTION_QUEUE = "task-action-queue";
|
|
6
|
+
export declare const DEFAULT_SUB_TASK_STATUS_QUEUE = "sub-task-status-queue";
|
|
5
7
|
export interface ITaskQueueEventFactory<TEvent extends IEvent = any> {
|
|
6
|
-
transformTask(event: TaskQueueEvent): Promise<TEvent[]>;
|
|
8
|
+
transformTask?(event: TaskQueueEvent): Promise<TEvent[]>;
|
|
9
|
+
transformStepFunctionTask?(event: StepFunctionTaskEvent): Promise<TEvent[]>;
|
|
7
10
|
}
|
|
8
11
|
export declare class EventFactoryAddedTask extends DefaultEventFactory {
|
|
9
12
|
transformSqs(event: SQSEvent): Promise<IEvent[]>;
|
|
13
|
+
transformStepFunction(event: StepFunctionsEvent<any>): Promise<IEvent[]>;
|
|
10
14
|
}
|
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventFactoryAddedTask = exports.DEFAULT_TASK_ACTION_QUEUE = void 0;
|
|
3
|
+
exports.EventFactoryAddedTask = exports.DEFAULT_SUB_TASK_STATUS_QUEUE = exports.DEFAULT_TASK_ACTION_QUEUE = void 0;
|
|
4
4
|
const core_1 = require("@mbc-cqrs-serverless/core");
|
|
5
|
+
const sub_task_queue_event_1 = require("./sub-task.queue.event");
|
|
5
6
|
const task_queue_event_1 = require("./task.queue.event");
|
|
7
|
+
const task_sfn_event_1 = require("./task.sfn.event");
|
|
6
8
|
exports.DEFAULT_TASK_ACTION_QUEUE = 'task-action-queue';
|
|
9
|
+
exports.DEFAULT_SUB_TASK_STATUS_QUEUE = 'sub-task-status-queue';
|
|
7
10
|
class EventFactoryAddedTask extends core_1.DefaultEventFactory {
|
|
8
11
|
async transformSqs(event) {
|
|
9
12
|
const curEvents = await super.transformSqs(event);
|
|
10
13
|
const taskEvents = event.Records.map((record) => {
|
|
11
14
|
if (record.eventSourceARN.endsWith(exports.DEFAULT_TASK_ACTION_QUEUE)) {
|
|
12
|
-
|
|
15
|
+
const task = new task_queue_event_1.TaskQueueEvent().fromSqsRecord(record);
|
|
16
|
+
// do not handle sub task
|
|
17
|
+
if (task.taskEvent.taskEntity.sk.split(core_1.KEY_SEPARATOR).length > 2)
|
|
18
|
+
return undefined;
|
|
19
|
+
return task;
|
|
20
|
+
}
|
|
21
|
+
if (record.eventSourceARN.endsWith(exports.DEFAULT_SUB_TASK_STATUS_QUEUE)) {
|
|
22
|
+
return new sub_task_queue_event_1.SubTaskQueueEvent().fromSqsRecord(record);
|
|
13
23
|
}
|
|
14
24
|
return undefined;
|
|
15
25
|
}).filter((event) => !!event);
|
|
16
26
|
return [...taskEvents, ...curEvents];
|
|
17
27
|
}
|
|
28
|
+
async transformStepFunction(event) {
|
|
29
|
+
if (event.context.StateMachine.Name.includes('sfn-task')) {
|
|
30
|
+
const sfnTaskEvents = new task_sfn_event_1.StepFunctionTaskEvent(event);
|
|
31
|
+
return [sfnTaskEvents];
|
|
32
|
+
}
|
|
33
|
+
return super.transformStepFunction(event);
|
|
34
|
+
}
|
|
18
35
|
}
|
|
19
36
|
exports.EventFactoryAddedTask = EventFactoryAddedTask;
|
|
20
37
|
//# sourceMappingURL=task.queue.event-factory.interface.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task.queue.event-factory.interface.js","sourceRoot":"","sources":["../../src/event/task.queue.event-factory.interface.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"task.queue.event-factory.interface.js","sourceRoot":"","sources":["../../src/event/task.queue.event-factory.interface.ts"],"names":[],"mappings":";;;AAAA,oDAKkC;AAGlC,iEAA0D;AAC1D,yDAAmD;AACnD,qDAAwD;AAE3C,QAAA,yBAAyB,GAAG,mBAAmB,CAAA;AAC/C,QAAA,6BAA6B,GAAG,uBAAuB,CAAA;AAOpE,MAAa,qBAAsB,SAAQ,0BAAmB;IAC5D,KAAK,CAAC,YAAY,CAAC,KAAe;QAChC,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;QACjD,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YAC9C,IAAI,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,iCAAyB,CAAC,EAAE,CAAC;gBAC9D,MAAM,IAAI,GAAG,IAAI,iCAAc,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;gBACvD,yBAAyB;gBACzB,IAAI,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,CAAC,oBAAa,CAAC,CAAC,MAAM,GAAG,CAAC;oBAC9D,OAAO,SAAS,CAAA;gBAClB,OAAO,IAAI,CAAA;YACb,CAAC;YACD,IAAI,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,qCAA6B,CAAC,EAAE,CAAC;gBAClE,OAAO,IAAI,wCAAiB,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;YACtD,CAAC;YACD,OAAO,SAAS,CAAA;QAClB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;QAE7B,OAAO,CAAC,GAAG,UAAU,EAAE,GAAG,SAAS,CAAC,CAAA;IACtC,CAAC;IAED,KAAK,CAAC,qBAAqB,CACzB,KAA8B;QAE9B,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YACzD,MAAM,aAAa,GAAG,IAAI,sCAAqB,CAAC,KAAK,CAAC,CAAA;YACtD,OAAO,CAAC,aAAa,CAAC,CAAA;QACxB,CAAC;QACD,OAAO,KAAK,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAA;IAC3C,CAAC;CACF;AA7BD,sDA6BC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { IEventHandler } from '@mbc-cqrs-serverless/core';
|
|
1
|
+
import { IEventHandler, StepFunctionService } from '@mbc-cqrs-serverless/core';
|
|
2
2
|
import { OnModuleInit } from '@nestjs/common';
|
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
4
|
import { ModuleRef } from '@nestjs/core';
|
|
4
5
|
import { TaskService } from '../task.service';
|
|
5
6
|
import { TaskQueueEvent } from './task.queue.event';
|
|
@@ -8,9 +9,14 @@ export declare class TaskQueueEventHandler implements IEventHandler<TaskQueueEve
|
|
|
8
9
|
private readonly moduleRef;
|
|
9
10
|
private readonly taskService;
|
|
10
11
|
private readonly eventFactory;
|
|
12
|
+
private readonly configService;
|
|
13
|
+
private readonly sfnService;
|
|
11
14
|
private readonly logger;
|
|
12
15
|
private eventBus;
|
|
13
|
-
|
|
16
|
+
private readonly sfnTaskArn;
|
|
17
|
+
constructor(moduleRef: ModuleRef, taskService: TaskService, eventFactory: ITaskQueueEventFactory, configService: ConfigService, sfnService: StepFunctionService);
|
|
14
18
|
onModuleInit(): void;
|
|
15
19
|
execute(event: TaskQueueEvent): Promise<any>;
|
|
20
|
+
handleTask(event: TaskQueueEvent): Promise<any>;
|
|
21
|
+
handleStepFunctionTask(event: TaskQueueEvent): Promise<any>;
|
|
16
22
|
}
|
|
@@ -16,17 +16,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
exports.TaskQueueEventHandler = void 0;
|
|
17
17
|
const core_1 = require("@mbc-cqrs-serverless/core");
|
|
18
18
|
const common_1 = require("@nestjs/common");
|
|
19
|
+
const config_1 = require("@nestjs/config");
|
|
19
20
|
const core_2 = require("@nestjs/core");
|
|
21
|
+
const enums_1 = require("../enums");
|
|
20
22
|
const status_enum_1 = require("../enums/status.enum");
|
|
21
23
|
const task_module_definition_1 = require("../task.module-definition");
|
|
22
24
|
const task_service_1 = require("../task.service");
|
|
23
25
|
const task_queue_event_1 = require("./task.queue.event");
|
|
24
26
|
let TaskQueueEventHandler = TaskQueueEventHandler_1 = class TaskQueueEventHandler {
|
|
25
|
-
constructor(moduleRef, taskService, eventFactory) {
|
|
27
|
+
constructor(moduleRef, taskService, eventFactory, configService, sfnService) {
|
|
26
28
|
this.moduleRef = moduleRef;
|
|
27
29
|
this.taskService = taskService;
|
|
28
30
|
this.eventFactory = eventFactory;
|
|
31
|
+
this.configService = configService;
|
|
32
|
+
this.sfnService = sfnService;
|
|
29
33
|
this.logger = new common_1.Logger(TaskQueueEventHandler_1.name);
|
|
34
|
+
this.sfnTaskArn = this.configService.get('SFN_TASK_ARN', '');
|
|
30
35
|
}
|
|
31
36
|
onModuleInit() {
|
|
32
37
|
const enableEventSourceModule = process.env.EVENT_SOURCE_DISABLED !== 'true';
|
|
@@ -36,6 +41,14 @@ let TaskQueueEventHandler = TaskQueueEventHandler_1 = class TaskQueueEventHandle
|
|
|
36
41
|
}
|
|
37
42
|
async execute(event) {
|
|
38
43
|
this.logger.debug('task queue event executing::', event);
|
|
44
|
+
if (event.taskEvent.taskKey.pk.startsWith(enums_1.TaskTypesEnum.SFN_TASK)) {
|
|
45
|
+
this.handleStepFunctionTask(event);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this.handleTask(event);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async handleTask(event) {
|
|
39
52
|
const taskKey = event.taskEvent.taskKey;
|
|
40
53
|
this.logger.debug('task key: ', taskKey);
|
|
41
54
|
try {
|
|
@@ -59,12 +72,50 @@ let TaskQueueEventHandler = TaskQueueEventHandler_1 = class TaskQueueEventHandle
|
|
|
59
72
|
throw error;
|
|
60
73
|
}
|
|
61
74
|
}
|
|
75
|
+
async handleStepFunctionTask(event) {
|
|
76
|
+
const taskKey = event.taskEvent.taskKey;
|
|
77
|
+
this.logger.debug('step function task key: ', taskKey);
|
|
78
|
+
try {
|
|
79
|
+
await this.taskService.updateStepFunctionTask(taskKey, {}, status_enum_1.TaskStatusEnum.PROCESSING);
|
|
80
|
+
const subTasks = await this.taskService.createSubTask(event);
|
|
81
|
+
await this.taskService.updateStepFunctionTask(taskKey, {
|
|
82
|
+
subTaskCount: subTasks.length,
|
|
83
|
+
subTaskSucceedCount: 0,
|
|
84
|
+
subTaskFailedCount: 0,
|
|
85
|
+
subTaskRunningCount: 0,
|
|
86
|
+
subTasks: subTasks.map((subTask) => ({
|
|
87
|
+
pk: subTask.pk,
|
|
88
|
+
sk: subTask.sk,
|
|
89
|
+
status: subTask.status,
|
|
90
|
+
})),
|
|
91
|
+
}, status_enum_1.TaskStatusEnum.PROCESSING);
|
|
92
|
+
const ddbKey = event.taskEvent.taskKey;
|
|
93
|
+
const ddbRecordId = `${ddbKey.pk || 'pk'}-${ddbKey.sk || 'sk'}`
|
|
94
|
+
.replaceAll('#', '-')
|
|
95
|
+
.replace('@', '-v')
|
|
96
|
+
.replace(/[^0-9A-Za-z_-]+/g, `__${Math.random().toString(36).substring(2, 4)}__`);
|
|
97
|
+
const sfnExecName = `${ddbRecordId}-${Date.now()}`;
|
|
98
|
+
await this.sfnService.startExecution(this.sfnTaskArn, subTasks, sfnExecName);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
// update status failed
|
|
102
|
+
this.logger.error(error);
|
|
103
|
+
await Promise.all([
|
|
104
|
+
this.taskService.updateStatus(taskKey, status_enum_1.TaskStatusEnum.FAILED, {
|
|
105
|
+
error: error.stack,
|
|
106
|
+
}),
|
|
107
|
+
this.taskService.publishAlarm(event, error.stack),
|
|
108
|
+
]);
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
62
112
|
};
|
|
63
113
|
exports.TaskQueueEventHandler = TaskQueueEventHandler;
|
|
64
114
|
exports.TaskQueueEventHandler = TaskQueueEventHandler = TaskQueueEventHandler_1 = __decorate([
|
|
65
115
|
(0, core_1.EventHandler)(task_queue_event_1.TaskQueueEvent),
|
|
66
116
|
__param(2, (0, common_1.Inject)(task_module_definition_1.TASK_QUEUE_EVENT_FACTORY)),
|
|
67
117
|
__metadata("design:paramtypes", [core_2.ModuleRef,
|
|
68
|
-
task_service_1.TaskService, Object
|
|
118
|
+
task_service_1.TaskService, Object, config_1.ConfigService,
|
|
119
|
+
core_1.StepFunctionService])
|
|
69
120
|
], TaskQueueEventHandler);
|
|
70
121
|
//# sourceMappingURL=task.queue.event.handler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task.queue.event.handler.js","sourceRoot":"","sources":["../../src/event/task.queue.event.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"task.queue.event.handler.js","sourceRoot":"","sources":["../../src/event/task.queue.event.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAKkC;AAClC,2CAA6D;AAC7D,2CAA8C;AAC9C,uCAAwC;AAExC,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I,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YACxB,MAAM,OAAO,CAAC,GAAG,CAAC;gBAChB,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,OAAO,EAAE,4BAAc,CAAC,MAAM,EAAE;oBAC5D,KAAK,EAAG,KAAe,CAAC,KAAK;iBAC9B,CAAC;gBACF,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,EAAG,KAAe,CAAC,KAAK,CAAC;aAC7D,CAAC,CAAA;YACF,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;CACF,CAAA;AAxHY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAY,EAAC,iCAAc,CAAC;IAYxB,WAAA,IAAA,eAAM,EAAC,iDAAwB,CAAC,CAAA;qCAFL,gBAAS;QACP,0BAAW,UAGT,sBAAa;QAChB,0BAAmB;GAdvC,qBAAqB,CAwHjC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DetailKey, IEvent, StepFunctionsContext } from '@mbc-cqrs-serverless/core';
|
|
2
|
+
import { TaskEntity } from '../entity';
|
|
3
|
+
export interface StepFunctionStateInput {
|
|
4
|
+
prevStateName?: string;
|
|
5
|
+
result?: unknown;
|
|
6
|
+
error?: string;
|
|
7
|
+
cause?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class StepFunctionTaskEvent implements IEvent {
|
|
10
|
+
source: string;
|
|
11
|
+
context: StepFunctionsContext;
|
|
12
|
+
input?: TaskEntity;
|
|
13
|
+
taskToken?: string;
|
|
14
|
+
constructor(event?: Partial<StepFunctionTaskEvent>);
|
|
15
|
+
get taskKey(): DetailKey;
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IEventHandler } from '@mbc-cqrs-serverless/core';
|
|
2
|
+
import { OnModuleInit } from '@nestjs/common';
|
|
3
|
+
import { ModuleRef } from '@nestjs/core';
|
|
4
|
+
import { TaskService } from '../task.service';
|
|
5
|
+
import { ITaskQueueEventFactory } from './task.queue.event-factory.interface';
|
|
6
|
+
import { StepFunctionTaskEvent } from './task.sfn.event';
|
|
7
|
+
export declare class TaskSfnEventHandler implements IEventHandler<StepFunctionTaskEvent>, OnModuleInit {
|
|
8
|
+
private readonly moduleRef;
|
|
9
|
+
private readonly taskService;
|
|
10
|
+
private readonly eventFactory;
|
|
11
|
+
private readonly logger;
|
|
12
|
+
private eventBus;
|
|
13
|
+
constructor(moduleRef: ModuleRef, taskService: TaskService, eventFactory: ITaskQueueEventFactory);
|
|
14
|
+
onModuleInit(): void;
|
|
15
|
+
execute(event: StepFunctionTaskEvent): Promise<any>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var TaskSfnEventHandler_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.TaskSfnEventHandler = void 0;
|
|
17
|
+
const core_1 = require("@mbc-cqrs-serverless/core");
|
|
18
|
+
const common_1 = require("@nestjs/common");
|
|
19
|
+
const core_2 = require("@nestjs/core");
|
|
20
|
+
const enums_1 = require("../enums");
|
|
21
|
+
const task_module_definition_1 = require("../task.module-definition");
|
|
22
|
+
const task_service_1 = require("../task.service");
|
|
23
|
+
const task_sfn_event_1 = require("./task.sfn.event");
|
|
24
|
+
let TaskSfnEventHandler = TaskSfnEventHandler_1 = class TaskSfnEventHandler {
|
|
25
|
+
constructor(moduleRef, taskService, eventFactory) {
|
|
26
|
+
this.moduleRef = moduleRef;
|
|
27
|
+
this.taskService = taskService;
|
|
28
|
+
this.eventFactory = eventFactory;
|
|
29
|
+
this.logger = new common_1.Logger(TaskSfnEventHandler_1.name);
|
|
30
|
+
}
|
|
31
|
+
onModuleInit() {
|
|
32
|
+
const enableEventSourceModule = process.env.EVENT_SOURCE_DISABLED !== 'true';
|
|
33
|
+
if (enableEventSourceModule) {
|
|
34
|
+
this.eventBus = this.moduleRef.get(core_1.EventBus, { strict: false });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async execute(event) {
|
|
38
|
+
this.logger.debug('executing::', event);
|
|
39
|
+
const taskKey = event.taskKey;
|
|
40
|
+
this.logger.debug('sfn task key: ', taskKey);
|
|
41
|
+
try {
|
|
42
|
+
await this.taskService.updateSubTaskStatus(taskKey, enums_1.TaskStatusEnum.PROCESSING);
|
|
43
|
+
const events = await this.eventFactory.transformStepFunctionTask(event);
|
|
44
|
+
const result = await Promise.all(events.map((event) => this.eventBus.execute(event)));
|
|
45
|
+
// update status completed
|
|
46
|
+
await this.taskService.updateSubTaskStatus(taskKey, enums_1.TaskStatusEnum.COMPLETED, {
|
|
47
|
+
result,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
// update status failed
|
|
52
|
+
this.logger.error(error);
|
|
53
|
+
await Promise.all([
|
|
54
|
+
this.taskService.updateSubTaskStatus(taskKey, enums_1.TaskStatusEnum.FAILED, {
|
|
55
|
+
error: error.stack,
|
|
56
|
+
}),
|
|
57
|
+
this.taskService.publishAlarm(event, error.stack),
|
|
58
|
+
]);
|
|
59
|
+
// throw error // continue sfn regardless of whether they would succeed or fail
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
exports.TaskSfnEventHandler = TaskSfnEventHandler;
|
|
64
|
+
exports.TaskSfnEventHandler = TaskSfnEventHandler = TaskSfnEventHandler_1 = __decorate([
|
|
65
|
+
(0, core_1.EventHandler)(task_sfn_event_1.StepFunctionTaskEvent),
|
|
66
|
+
__param(2, (0, common_1.Inject)(task_module_definition_1.TASK_QUEUE_EVENT_FACTORY)),
|
|
67
|
+
__metadata("design:paramtypes", [core_2.ModuleRef,
|
|
68
|
+
task_service_1.TaskService, Object])
|
|
69
|
+
], TaskSfnEventHandler);
|
|
70
|
+
//# sourceMappingURL=task.sfn.event.handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task.sfn.event.handler.js","sourceRoot":"","sources":["../../src/event/task.sfn.event.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAIkC;AAClC,2CAA6D;AAC7D,uCAAwC;AAExC,oCAAyC;AACzC,sEAAoE;AACpE,kDAA6C;AAE7C,qDAAwD;AAGjD,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAO9B,YACmB,SAAoB,EACpB,WAAwB,EAEzC,YAAqD;QAHpC,cAAS,GAAT,SAAS,CAAW;QACpB,gBAAW,GAAX,WAAW,CAAa;QAExB,iBAAY,GAAZ,YAAY,CAAwB;QARtC,WAAM,GAAW,IAAI,eAAM,CAAC,qBAAmB,CAAC,IAAI,CAAC,CAAA;IASnE,CAAC;IAEJ,YAAY;QACV,MAAM,uBAAuB,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,KAAK,MAAM,CAAA;QAC5E,IAAI,uBAAuB,EAAE,CAAC;YAC5B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,eAA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F,CAAA;AAxDY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAY,EAAC,sCAAqB,CAAC;IAW/B,WAAA,IAAA,eAAM,EAAC,iDAAwB,CAAC,CAAA;qCAFL,gBAAS;QACP,0BAAW;GAThC,mBAAmB,CAwD/B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StepFunctionTaskEvent = void 0;
|
|
4
|
+
class StepFunctionTaskEvent {
|
|
5
|
+
constructor(event) {
|
|
6
|
+
Object.assign(this, event);
|
|
7
|
+
if (event?.context) {
|
|
8
|
+
this.source = event.context.StateMachine.Id;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
get taskKey() {
|
|
12
|
+
return {
|
|
13
|
+
pk: this.input.pk,
|
|
14
|
+
sk: this.input.sk,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.StepFunctionTaskEvent = StepFunctionTaskEvent;
|
|
19
|
+
//# sourceMappingURL=task.sfn.event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task.sfn.event.js","sourceRoot":"","sources":["../../src/event/task.sfn.event.ts"],"names":[],"mappings":";;;AAeA,MAAa,qBAAqB;IAMhC,YAAY,KAAsC;QAChD,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QAC1B,IAAI,KAAK,EAAE,OAAO,EAAE,CAAC;YACnB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAA;QAC7C,CAAC;IACH,CAAC;IAED,IAAI,OAAO;QACT,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE;YACjB,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE;SAClB,CAAA;IACH,CAAC;CACF;AAnBD,sDAmBC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./entity"), exports);
|
|
18
18
|
__exportStar(require("./enums"), exports);
|
|
19
19
|
__exportStar(require("./event"), exports);
|
|
20
|
+
__exportStar(require("./interfaces"), exports);
|
|
20
21
|
__exportStar(require("./task.controller"), exports);
|
|
21
22
|
__exportStar(require("./task.module"), exports);
|
|
22
23
|
__exportStar(require("./task.module-definition"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,0CAAuB;AACvB,0CAAuB;AACvB,oDAAiC;AACjC,gDAA6B;AAC7B,2DAAwC;AACxC,iDAA8B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,0CAAuB;AACvB,0CAAuB;AACvB,+CAA4B;AAC5B,oDAAiC;AACjC,gDAA6B;AAC7B,2DAAwC;AACxC,iDAA8B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './task-service.interface';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./task-service.interface"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAwC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { IInvoke } from '@mbc-cqrs-serverless/core';
|
|
2
|
+
import { CreateTaskDto } from '../dto';
|
|
3
|
+
import { TaskEntity, TaskListEntity } from '../entity';
|
|
4
|
+
import { TaskQueueEvent } from '../event';
|
|
5
|
+
export interface ITaskService {
|
|
6
|
+
/**
|
|
7
|
+
* Creates a task and stores it in DynamoDB.
|
|
8
|
+
*
|
|
9
|
+
* @param dto - The data transfer object containing task details.
|
|
10
|
+
* @param options - Additional options including invocation context.
|
|
11
|
+
* @returns A promise that resolves to the created task entity.
|
|
12
|
+
*/
|
|
13
|
+
createTask(dto: CreateTaskDto, options: {
|
|
14
|
+
invokeContext: IInvoke;
|
|
15
|
+
}): Promise<TaskEntity>;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a Step Function task and stores it in DynamoDB.
|
|
18
|
+
*
|
|
19
|
+
* @param dto - The data transfer object containing task details.
|
|
20
|
+
* @param options - Additional options including invocation context.
|
|
21
|
+
* @returns A promise that resolves to the created task entity.
|
|
22
|
+
*/
|
|
23
|
+
createStepFunctionTask(dto: CreateTaskDto, options: {
|
|
24
|
+
invokeContext: IInvoke;
|
|
25
|
+
}): Promise<TaskEntity>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates sub task for Step Function task and stores it in DynamoDB.
|
|
28
|
+
*
|
|
29
|
+
* @param event - The data transfer object containing task details.
|
|
30
|
+
* @param options - Additional options including invocation context.
|
|
31
|
+
* @returns A promise that resolves to the created task entity.
|
|
32
|
+
*/
|
|
33
|
+
createSubTask(event: TaskQueueEvent): Promise<TaskEntity[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves a list of task from DynamoDB.
|
|
36
|
+
*
|
|
37
|
+
* @param tenantCode - The tenant code used to construct the partition key.
|
|
38
|
+
* @param type - The type of task, must be either "TASK" or "SFN_TASK".
|
|
39
|
+
* @param options - Additional query parameters, including sort key conditions, pagination, and ordering.
|
|
40
|
+
* @returns A promise that resolves to a list of task entities.
|
|
41
|
+
*/
|
|
42
|
+
listItemsByPk(tenantCode: string, type?: string, options?: {
|
|
43
|
+
sk?: {
|
|
44
|
+
skExpession: string;
|
|
45
|
+
skAttributeValues: Record<string, string>;
|
|
46
|
+
skAttributeNames?: Record<string, string>;
|
|
47
|
+
};
|
|
48
|
+
startFromSk?: string;
|
|
49
|
+
limit?: number;
|
|
50
|
+
order?: 'asc' | 'desc';
|
|
51
|
+
}): Promise<TaskListEntity>;
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-service.interface.js","sourceRoot":"","sources":["../../src/interfaces/task-service.interface.ts"],"names":[],"mappings":""}
|
|
@@ -6,6 +6,7 @@ export declare class TaskController {
|
|
|
6
6
|
private readonly logger;
|
|
7
7
|
constructor(tasksService: TaskService);
|
|
8
8
|
createTask(invokeContext: IInvoke, dto: CreateTaskDto): Promise<import("./entity").TaskEntity>;
|
|
9
|
+
createStepFunctionTask(invokeContext: IInvoke, dto: CreateTaskDto): Promise<import("./entity").TaskEntity>;
|
|
9
10
|
getTask(detailDto: DetailDto): Promise<import("./entity").TaskEntity>;
|
|
10
|
-
listTaskByPk(pk: string): Promise<import("./entity").TaskListEntity>;
|
|
11
|
+
listTaskByPk(pk: string, type: string): Promise<import("./entity").TaskListEntity>;
|
|
11
12
|
}
|
package/dist/task.controller.js
CHANGED
|
@@ -27,6 +27,11 @@ let TaskController = TaskController_1 = class TaskController {
|
|
|
27
27
|
async createTask(invokeContext, dto) {
|
|
28
28
|
return await this.tasksService.createTask(dto, { invokeContext });
|
|
29
29
|
}
|
|
30
|
+
async createStepFunctionTask(invokeContext, dto) {
|
|
31
|
+
return await this.tasksService.createStepFunctionTask(dto, {
|
|
32
|
+
invokeContext,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
30
35
|
async getTask(detailDto) {
|
|
31
36
|
const item = await this.tasksService.getTask(detailDto);
|
|
32
37
|
if (!item) {
|
|
@@ -35,8 +40,8 @@ let TaskController = TaskController_1 = class TaskController {
|
|
|
35
40
|
this.logger.debug('item:', item);
|
|
36
41
|
return item;
|
|
37
42
|
}
|
|
38
|
-
async listTaskByPk(pk) {
|
|
39
|
-
return await this.tasksService.listItemsByPk(pk);
|
|
43
|
+
async listTaskByPk(pk, type) {
|
|
44
|
+
return await this.tasksService.listItemsByPk(pk, type);
|
|
40
45
|
}
|
|
41
46
|
};
|
|
42
47
|
exports.TaskController = TaskController;
|
|
@@ -48,6 +53,14 @@ __decorate([
|
|
|
48
53
|
__metadata("design:paramtypes", [Object, create_task_dto_1.CreateTaskDto]),
|
|
49
54
|
__metadata("design:returntype", Promise)
|
|
50
55
|
], TaskController.prototype, "createTask", null);
|
|
56
|
+
__decorate([
|
|
57
|
+
(0, common_1.Post)('/step-function-task'),
|
|
58
|
+
__param(0, (0, core_1.INVOKE_CONTEXT)()),
|
|
59
|
+
__param(1, (0, common_1.Body)()),
|
|
60
|
+
__metadata("design:type", Function),
|
|
61
|
+
__metadata("design:paramtypes", [Object, create_task_dto_1.CreateTaskDto]),
|
|
62
|
+
__metadata("design:returntype", Promise)
|
|
63
|
+
], TaskController.prototype, "createStepFunctionTask", null);
|
|
51
64
|
__decorate([
|
|
52
65
|
(0, common_1.Get)('/:pk/:sk'),
|
|
53
66
|
__param(0, (0, common_1.Param)()),
|
|
@@ -58,8 +71,9 @@ __decorate([
|
|
|
58
71
|
__decorate([
|
|
59
72
|
(0, common_1.Get)('/:pk'),
|
|
60
73
|
__param(0, (0, common_1.Param)('pk')),
|
|
74
|
+
__param(1, (0, common_1.Query)('type')),
|
|
61
75
|
__metadata("design:type", Function),
|
|
62
|
-
__metadata("design:paramtypes", [String]),
|
|
76
|
+
__metadata("design:paramtypes", [String, String]),
|
|
63
77
|
__metadata("design:returntype", Promise)
|
|
64
78
|
], TaskController.prototype, "listTaskByPk", null);
|
|
65
79
|
exports.TaskController = TaskController = TaskController_1 = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task.controller.js","sourceRoot":"","sources":["../src/task.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAA8E;AAC9E,
|
|
1
|
+
{"version":3,"file":"task.controller.js","sourceRoot":"","sources":["../src/task.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAA8E;AAC9E,2CASuB;AACvB,6CAAyC;AAEzC,2DAAqD;AACrD,iDAA4C;AAGrC,IAAM,cAAc,sBAApB,MAAM,cAAc;IAGzB,YAA6B,YAAyB;QAAzB,iBAAY,GAAZ,YAAY,CAAa;QAFrC,WAAM,GAAG,IAAI,eAAM,CAAC,gBAAc,CAAC,IAAI,CAAC,CAAA;IAEA,CAAC;IAGpD,AAAN,KAAK,CAAC,UAAU,CACI,aAAsB,EAChC,GAAkB;QAE1B,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,CAAC,CAAA;IACnE,CAAC;IAGK,AAAN,KAAK,CAAC,sBAAsB,CACR,aAAsB,EAChC,GAAkB;QAE1B,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,sBAAsB,CAAC,GAAG,EAAE;YACzD,aAAa;SACd,CAAC,CAAA;IACJ,CAAC;IAGK,AAAN,KAAK,CAAC,OAAO,CAAU,SAAoB;QACzC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QACvD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,0BAAiB,EAAE,CAAA;QAC/B,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAChC,OAAO,IAAI,CAAA;IACb,CAAC;IAGK,AAAN,KAAK,CAAC,YAAY,CAAc,EAAU,EAAiB,IAAY;QACrE,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;IACxD,CAAC;CACF,CAAA;AArCY,wCAAc;AAMnB;IADL,IAAA,aAAI,EAAC,GAAG,CAAC;IAEP,WAAA,IAAA,qBAAc,GAAE,CAAA;IAChB,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,+BAAa;;gDAG3B;AAGK;IADL,IAAA,aAAI,EAAC,qBAAqB,CAAC;IAEzB,WAAA,IAAA,qBAAc,GAAE,CAAA;IAChB,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,+BAAa;;4DAK3B;AAGK;IADL,IAAA,YAAG,EAAC,UAAU,CAAC;IACD,WAAA,IAAA,cAAK,GAAE,CAAA;;qCAAY,gBAAS;;6CAO1C;AAGK;IADL,IAAA,YAAG,EAAC,MAAM,CAAC;IACQ,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;IAAc,WAAA,IAAA,cAAK,EAAC,MAAM,CAAC,CAAA;;;;kDAEzD;yBApCU,cAAc;IAF1B,IAAA,iBAAO,EAAC,MAAM,CAAC;IACf,IAAA,mBAAU,EAAC,OAAO,CAAC;qCAIyB,0BAAW;GAH3C,cAAc,CAqC1B"}
|
package/dist/task.module.js
CHANGED
|
@@ -9,8 +9,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.TaskModule = void 0;
|
|
10
10
|
const core_1 = require("@mbc-cqrs-serverless/core");
|
|
11
11
|
const common_1 = require("@nestjs/common");
|
|
12
|
+
const sub_task_queue_event_handler_1 = require("./event/sub-task.queue.event.handler");
|
|
12
13
|
const task_event_handler_1 = require("./event/task.event.handler");
|
|
13
14
|
const task_queue_event_handler_1 = require("./event/task.queue.event.handler");
|
|
15
|
+
const task_sfn_event_handler_1 = require("./event/task.sfn.event.handler");
|
|
14
16
|
const task_controller_1 = require("./task.controller");
|
|
15
17
|
const task_module_definition_1 = require("./task.module-definition");
|
|
16
18
|
const task_service_1 = require("./task.service");
|
|
@@ -39,8 +41,14 @@ exports.TaskModule = TaskModule;
|
|
|
39
41
|
exports.TaskModule = TaskModule = __decorate([
|
|
40
42
|
(0, common_1.Module)({
|
|
41
43
|
imports: [core_1.DataStoreModule, core_1.QueueModule],
|
|
42
|
-
providers: [
|
|
43
|
-
|
|
44
|
+
providers: [
|
|
45
|
+
task_service_1.TaskService,
|
|
46
|
+
task_event_handler_1.TaskEventHandler,
|
|
47
|
+
task_queue_event_handler_1.TaskQueueEventHandler,
|
|
48
|
+
task_sfn_event_handler_1.TaskSfnEventHandler,
|
|
49
|
+
sub_task_queue_event_handler_1.SubTaskQueueEventHandler,
|
|
50
|
+
],
|
|
51
|
+
exports: [task_service_1.TaskService, sub_task_queue_event_handler_1.SubTaskQueueEventHandler],
|
|
44
52
|
})
|
|
45
53
|
], TaskModule);
|
|
46
54
|
//# sourceMappingURL=task.module.js.map
|
package/dist/task.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task.module.js","sourceRoot":"","sources":["../src/task.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAwE;AACxE,2CAAsD;AAEtD,mEAA6D;AAC7D,+EAAwE;AACxE,uDAAkD;AAClD,qEAIiC;AACjC,iDAA4C;
|
|
1
|
+
{"version":3,"file":"task.module.js","sourceRoot":"","sources":["../src/task.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAwE;AACxE,2CAAsD;AAEtD,uFAA+E;AAC/E,mEAA6D;AAC7D,+EAAwE;AACxE,2EAAoE;AACpE,uDAAkD;AAClD,qEAIiC;AACjC,iDAA4C;AAarC,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,gDAAuB;IACrD,MAAM,CAAC,QAAQ,CAAC,OAA4B;QAC1C,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;QAEtC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YACtB,MAAM,CAAC,SAAS,GAAG,EAAE,CAAA;QACvB,CAAC;QACD,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;YACpB,OAAO,EAAE,iDAAwB;YACjC,QAAQ,EAAE,OAAO,CAAC,qBAAqB;SACxC,CAAC,CAAA;QAEF,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;gBACxB,MAAM,CAAC,WAAW,GAAG,EAAE,CAAA;YACzB,CAAC;YACD,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,gCAAc,CAAC,CAAA;QACzC,CAAC;QAED,OAAO;YACL,GAAG,MAAM;SACV,CAAA;IACH,CAAC;CACF,CAAA;AAvBY,gCAAU;qBAAV,UAAU;IAXtB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,sBAAe,EAAE,kBAAW,CAAC;QACvC,SAAS,EAAE;YACT,0BAAW;YACX,qCAAgB;YAChB,gDAAqB;YACrB,4CAAmB;YACnB,uDAAwB;SACzB;QACD,OAAO,EAAE,CAAC,0BAAW,EAAE,uDAAwB,CAAC;KACjD,CAAC;GACW,UAAU,CAuBtB"}
|
package/dist/task.service.d.ts
CHANGED
|
@@ -3,8 +3,11 @@ import { ConfigService } from '@nestjs/config';
|
|
|
3
3
|
import { CreateTaskDto } from './dto/create-task.dto';
|
|
4
4
|
import { TaskEntity } from './entity/task.entity';
|
|
5
5
|
import { TaskListEntity } from './entity/task-list.entity';
|
|
6
|
+
import { TaskStatusEnum } from './enums/status.enum';
|
|
6
7
|
import { TaskQueueEvent } from './event';
|
|
7
|
-
|
|
8
|
+
import { StepFunctionTaskEvent } from './event/task.sfn.event';
|
|
9
|
+
import { ITaskService } from './interfaces/task-service.interface';
|
|
10
|
+
export declare class TaskService implements ITaskService {
|
|
8
11
|
private readonly dynamoDbService;
|
|
9
12
|
private readonly snsService;
|
|
10
13
|
private readonly config;
|
|
@@ -12,15 +15,25 @@ export declare class TaskService {
|
|
|
12
15
|
private readonly tableName;
|
|
13
16
|
private readonly alarmTopicArn;
|
|
14
17
|
constructor(dynamoDbService: DynamoDbService, snsService: SnsService, config: ConfigService);
|
|
15
|
-
createTask(dto: CreateTaskDto,
|
|
18
|
+
createTask(dto: CreateTaskDto, options: {
|
|
16
19
|
invokeContext: IInvoke;
|
|
17
20
|
}): Promise<TaskEntity>;
|
|
21
|
+
createStepFunctionTask(dto: CreateTaskDto, options: {
|
|
22
|
+
invokeContext: IInvoke;
|
|
23
|
+
}): Promise<TaskEntity>;
|
|
24
|
+
createSubTask(event: TaskQueueEvent): Promise<TaskEntity[]>;
|
|
25
|
+
getAllSubTask(subTask: DetailKey): Promise<TaskEntity[]>;
|
|
26
|
+
updateStepFunctionTask(key: DetailKey, attributes?: Record<string, any>, status?: string, notifyId?: string): Promise<void>;
|
|
18
27
|
getTask(key: DetailKey): Promise<TaskEntity>;
|
|
19
28
|
updateStatus(key: DetailKey, status: string, attributes?: {
|
|
20
29
|
result?: any;
|
|
21
30
|
error?: any;
|
|
22
31
|
}, notifyId?: string): Promise<void>;
|
|
23
|
-
|
|
32
|
+
updateSubTaskStatus(key: DetailKey, status: string, attributes?: {
|
|
33
|
+
result?: any;
|
|
34
|
+
error?: any;
|
|
35
|
+
}, notifyId?: string): Promise<void>;
|
|
36
|
+
listItemsByPk(tenantCode: string, type?: string, options?: {
|
|
24
37
|
sk?: {
|
|
25
38
|
skExpession: string;
|
|
26
39
|
skAttributeValues: Record<string, string>;
|
|
@@ -30,5 +43,17 @@ export declare class TaskService {
|
|
|
30
43
|
limit?: number;
|
|
31
44
|
order?: 'asc' | 'desc';
|
|
32
45
|
}): Promise<TaskListEntity>;
|
|
33
|
-
publishAlarm(event: TaskQueueEvent, errorDetails: any): Promise<void>;
|
|
46
|
+
publishAlarm(event: TaskQueueEvent | StepFunctionTaskEvent, errorDetails: any): Promise<void>;
|
|
47
|
+
formatTaskStatus(tasks: TaskEntity[]): Promise<{
|
|
48
|
+
subTaskCount: number;
|
|
49
|
+
subTaskSucceedCount: number;
|
|
50
|
+
subTaskFailedCount: number;
|
|
51
|
+
subTaskRunningCount: number;
|
|
52
|
+
subTasks: {
|
|
53
|
+
pk: string;
|
|
54
|
+
sk: string;
|
|
55
|
+
status: TaskStatusEnum;
|
|
56
|
+
}[];
|
|
57
|
+
}>;
|
|
58
|
+
private countTaskStatus;
|
|
34
59
|
}
|
package/dist/task.service.js
CHANGED
|
@@ -18,6 +18,8 @@ const ulid_1 = require("ulid");
|
|
|
18
18
|
const task_entity_1 = require("./entity/task.entity");
|
|
19
19
|
const task_list_entity_1 = require("./entity/task-list.entity");
|
|
20
20
|
const status_enum_1 = require("./enums/status.enum");
|
|
21
|
+
const event_1 = require("./event");
|
|
22
|
+
const enums_1 = require("./enums");
|
|
21
23
|
let TaskService = TaskService_1 = class TaskService {
|
|
22
24
|
constructor(dynamoDbService, snsService, config) {
|
|
23
25
|
this.dynamoDbService = dynamoDbService;
|
|
@@ -27,9 +29,9 @@ let TaskService = TaskService_1 = class TaskService {
|
|
|
27
29
|
this.tableName = dynamoDbService.getTableName('tasks');
|
|
28
30
|
this.alarmTopicArn = this.config.get('SNS_ALARM_TOPIC_ARN');
|
|
29
31
|
}
|
|
30
|
-
async createTask(dto,
|
|
31
|
-
const sourceIp =
|
|
32
|
-
const userContext = (0, core_1.getUserContext)(
|
|
32
|
+
async createTask(dto, options) {
|
|
33
|
+
const sourceIp = options.invokeContext?.event?.requestContext?.http?.sourceIp;
|
|
34
|
+
const userContext = (0, core_1.getUserContext)(options.invokeContext);
|
|
33
35
|
const taskCode = (0, ulid_1.ulid)();
|
|
34
36
|
const pk = `TASK${core_1.KEY_SEPARATOR}${dto.tenantCode}`;
|
|
35
37
|
const sk = `${dto.taskType}${core_1.KEY_SEPARATOR}${taskCode}`;
|
|
@@ -44,7 +46,7 @@ let TaskService = TaskService_1 = class TaskService {
|
|
|
44
46
|
tenantCode: dto.tenantCode,
|
|
45
47
|
status: status_enum_1.TaskStatusEnum.CREATED,
|
|
46
48
|
input: dto.input,
|
|
47
|
-
requestId:
|
|
49
|
+
requestId: options.invokeContext?.context?.awsRequestId,
|
|
48
50
|
createdAt: new Date(),
|
|
49
51
|
updatedAt: new Date(),
|
|
50
52
|
createdBy: userContext.userId,
|
|
@@ -55,6 +57,91 @@ let TaskService = TaskService_1 = class TaskService {
|
|
|
55
57
|
await this.dynamoDbService.putItem(this.tableName, item);
|
|
56
58
|
return new task_entity_1.TaskEntity(item);
|
|
57
59
|
}
|
|
60
|
+
async createStepFunctionTask(dto, options) {
|
|
61
|
+
const sourceIp = options.invokeContext?.event?.requestContext?.http?.sourceIp;
|
|
62
|
+
const userContext = (0, core_1.getUserContext)(options.invokeContext);
|
|
63
|
+
const taskCode = (0, ulid_1.ulid)();
|
|
64
|
+
const pk = `${enums_1.TaskTypesEnum.SFN_TASK}${core_1.KEY_SEPARATOR}${dto.tenantCode}`;
|
|
65
|
+
const sk = `${dto.taskType}${core_1.KEY_SEPARATOR}${taskCode}`;
|
|
66
|
+
const item = {
|
|
67
|
+
id: `${pk}${core_1.KEY_SEPARATOR}${sk}`,
|
|
68
|
+
pk,
|
|
69
|
+
sk,
|
|
70
|
+
version: 0,
|
|
71
|
+
code: taskCode,
|
|
72
|
+
type: dto.taskType,
|
|
73
|
+
name: dto.name || dto.taskType,
|
|
74
|
+
tenantCode: dto.tenantCode,
|
|
75
|
+
status: status_enum_1.TaskStatusEnum.CREATED,
|
|
76
|
+
input: dto.input,
|
|
77
|
+
requestId: options.invokeContext?.context?.awsRequestId,
|
|
78
|
+
createdAt: new Date(),
|
|
79
|
+
updatedAt: new Date(),
|
|
80
|
+
createdBy: userContext.userId,
|
|
81
|
+
updatedBy: userContext.userId,
|
|
82
|
+
createdIp: sourceIp,
|
|
83
|
+
updatedIp: sourceIp,
|
|
84
|
+
};
|
|
85
|
+
await this.dynamoDbService.putItem(this.tableName, item);
|
|
86
|
+
return new task_entity_1.TaskEntity(item);
|
|
87
|
+
}
|
|
88
|
+
async createSubTask(event) {
|
|
89
|
+
const subTasks = [];
|
|
90
|
+
await Promise.all(event.taskEvent.taskEntity.input.map((input, index) => {
|
|
91
|
+
const pk = event.taskEvent.taskKey.pk;
|
|
92
|
+
const sk = `${event.taskEvent.taskKey.sk}${core_1.KEY_SEPARATOR}${index}`;
|
|
93
|
+
const taskCode = (0, ulid_1.ulid)();
|
|
94
|
+
const item = new task_entity_1.TaskEntity({
|
|
95
|
+
id: `${pk}${core_1.KEY_SEPARATOR}${sk}`,
|
|
96
|
+
pk,
|
|
97
|
+
sk,
|
|
98
|
+
version: 0,
|
|
99
|
+
code: taskCode,
|
|
100
|
+
type: event.taskEvent.taskEntity.type,
|
|
101
|
+
name: event.taskEvent.taskEntity.name,
|
|
102
|
+
tenantCode: event.taskEvent.taskEntity.tenantCode,
|
|
103
|
+
status: status_enum_1.TaskStatusEnum.CREATED,
|
|
104
|
+
input,
|
|
105
|
+
requestId: event.taskEvent.taskEntity.requestId,
|
|
106
|
+
createdAt: new Date(),
|
|
107
|
+
updatedAt: new Date(),
|
|
108
|
+
createdBy: event.taskEvent.taskEntity.createdBy,
|
|
109
|
+
updatedBy: event.taskEvent.taskEntity.updatedBy,
|
|
110
|
+
createdIp: event.taskEvent.taskEntity.createdIp,
|
|
111
|
+
updatedIp: event.taskEvent.taskEntity.updatedIp,
|
|
112
|
+
});
|
|
113
|
+
subTasks.push(item);
|
|
114
|
+
return this.dynamoDbService.putItem(this.tableName, item);
|
|
115
|
+
}));
|
|
116
|
+
return subTasks;
|
|
117
|
+
}
|
|
118
|
+
async getAllSubTask(subTask) {
|
|
119
|
+
const parentKey = subTask.sk
|
|
120
|
+
.split(core_1.KEY_SEPARATOR)
|
|
121
|
+
.slice(0, -1)
|
|
122
|
+
.join(core_1.KEY_SEPARATOR);
|
|
123
|
+
const res = await this.dynamoDbService.listItemsByPk(this.tableName, subTask.pk, {
|
|
124
|
+
skExpession: 'begins_with(sk, :typeCode)',
|
|
125
|
+
skAttributeValues: {
|
|
126
|
+
':typeCode': `${parentKey}${core_1.KEY_SEPARATOR}`,
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
return (res?.items || []).map((item) => new task_entity_1.TaskEntity(item));
|
|
130
|
+
}
|
|
131
|
+
async updateStepFunctionTask(key, attributes, status, notifyId) {
|
|
132
|
+
await this.dynamoDbService.updateItem(this.tableName, key, {
|
|
133
|
+
set: { attributes, status },
|
|
134
|
+
});
|
|
135
|
+
// notification via SNS
|
|
136
|
+
await this.snsService.publish({
|
|
137
|
+
action: 'task-status',
|
|
138
|
+
...key,
|
|
139
|
+
table: this.tableName,
|
|
140
|
+
id: notifyId || `${key.pk}#${key.sk}`,
|
|
141
|
+
tenantCode: key.pk.substring(key.pk.indexOf('#') + 1),
|
|
142
|
+
content: { attributes, status },
|
|
143
|
+
});
|
|
144
|
+
}
|
|
58
145
|
async getTask(key) {
|
|
59
146
|
const item = await this.dynamoDbService.getItem(this.tableName, key);
|
|
60
147
|
return new task_entity_1.TaskEntity(item);
|
|
@@ -73,9 +160,26 @@ let TaskService = TaskService_1 = class TaskService {
|
|
|
73
160
|
content: { status, attributes },
|
|
74
161
|
});
|
|
75
162
|
}
|
|
76
|
-
async
|
|
77
|
-
|
|
78
|
-
|
|
163
|
+
async updateSubTaskStatus(key, status, attributes, notifyId) {
|
|
164
|
+
await this.dynamoDbService.updateItem(this.tableName, key, {
|
|
165
|
+
set: { status, attributes },
|
|
166
|
+
});
|
|
167
|
+
// notification via SNS -> insert to queue
|
|
168
|
+
await this.snsService.publish({
|
|
169
|
+
action: 'sub-task-status',
|
|
170
|
+
...key,
|
|
171
|
+
table: this.tableName,
|
|
172
|
+
id: notifyId || `${key.pk}#${key.sk}`,
|
|
173
|
+
tenantCode: key.pk.substring(key.pk.indexOf('#') + 1),
|
|
174
|
+
content: { status, attributes },
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
async listItemsByPk(tenantCode, type, options) {
|
|
178
|
+
if (!['TASK', 'SFN_TASK'].includes(type)) {
|
|
179
|
+
throw new common_1.NotFoundException(`The type of task, must be either "TASK" or "SFN_TASK"`);
|
|
180
|
+
}
|
|
181
|
+
const pk = `${type}${core_1.KEY_SEPARATOR}${tenantCode}`;
|
|
182
|
+
const { lastSk, items } = await this.dynamoDbService.listItemsByPk(this.tableName, pk, options?.sk, options?.startFromSk, options?.limit, options?.order);
|
|
79
183
|
return new task_list_entity_1.TaskListEntity({
|
|
80
184
|
lastSk,
|
|
81
185
|
items: items.map((item) => new task_entity_1.TaskEntity(item)),
|
|
@@ -83,14 +187,15 @@ let TaskService = TaskService_1 = class TaskService {
|
|
|
83
187
|
}
|
|
84
188
|
async publishAlarm(event, errorDetails) {
|
|
85
189
|
this.logger.debug('event', event);
|
|
86
|
-
const taskKey = event.taskEvent.taskKey;
|
|
190
|
+
const taskKey = event instanceof event_1.TaskQueueEvent ? event.taskEvent.taskKey : event.taskKey;
|
|
191
|
+
const tenantCode = taskKey.pk.substring(taskKey.pk.indexOf(core_1.KEY_SEPARATOR) + 1);
|
|
87
192
|
const alarm = {
|
|
88
193
|
action: 'sfn-alarm',
|
|
89
194
|
id: `${taskKey.pk}#${taskKey.sk}`,
|
|
90
195
|
table: this.tableName,
|
|
91
196
|
pk: taskKey.pk,
|
|
92
197
|
sk: taskKey.sk,
|
|
93
|
-
tenantCode
|
|
198
|
+
tenantCode,
|
|
94
199
|
content: {
|
|
95
200
|
errorMessage: errorDetails,
|
|
96
201
|
},
|
|
@@ -98,6 +203,23 @@ let TaskService = TaskService_1 = class TaskService {
|
|
|
98
203
|
this.logger.error('alarm:::', alarm);
|
|
99
204
|
await this.snsService.publish(alarm, this.alarmTopicArn);
|
|
100
205
|
}
|
|
206
|
+
async formatTaskStatus(tasks) {
|
|
207
|
+
const result = {
|
|
208
|
+
subTaskCount: tasks.length,
|
|
209
|
+
subTaskSucceedCount: this.countTaskStatus(tasks, status_enum_1.TaskStatusEnum.COMPLETED),
|
|
210
|
+
subTaskFailedCount: this.countTaskStatus(tasks, status_enum_1.TaskStatusEnum.FAILED),
|
|
211
|
+
subTaskRunningCount: this.countTaskStatus(tasks, status_enum_1.TaskStatusEnum.PROCESSING),
|
|
212
|
+
subTasks: tasks.map((task) => ({
|
|
213
|
+
pk: task.pk,
|
|
214
|
+
sk: task.sk,
|
|
215
|
+
status: task.status,
|
|
216
|
+
})),
|
|
217
|
+
};
|
|
218
|
+
return result;
|
|
219
|
+
}
|
|
220
|
+
countTaskStatus(tasks, status) {
|
|
221
|
+
return tasks.filter((task) => task.status === status).length;
|
|
222
|
+
}
|
|
101
223
|
};
|
|
102
224
|
exports.TaskService = TaskService;
|
|
103
225
|
exports.TaskService = TaskService = TaskService_1 = __decorate([
|
package/dist/task.service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task.service.js","sourceRoot":"","sources":["../src/task.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,oDAQkC;AAClC,
|
|
1
|
+
{"version":3,"file":"task.service.js","sourceRoot":"","sources":["../src/task.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,oDAQkC;AAClC,2CAAsE;AACtE,2CAA8C;AAC9C,+BAA2B;AAG3B,sDAAiD;AACjD,gEAA0D;AAC1D,qDAAoD;AACpD,mCAAwC;AAGxC,mCAAuC;AAGhC,IAAM,WAAW,mBAAjB,MAAM,WAAW;IAKtB,YACmB,eAAgC,EAChC,UAAsB,EACtB,MAAqB;QAFrB,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YACb,YAAY,EAAE,KAAK,CAAC,MAAM;YAC1B,mBAAmB,EAAE,IAAI,CAAC,eAAe,CACvC,KAAK,EACL,4BAAc,CAAC,SAAS,CACzB;YACD,kBAAkB,EAAE,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,4BAAc,CAAC,MAAM,CAAC;YACtE,mBAAmB,EAAE,IAAI,CAAC,eAAe,CACvC,KAAK,EACL,4BAAc,CAAC,UAAU,CAC1B;YACD,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBAC7B,EAAE,EAAE,IAAI,CAAC,EAAE;gBACX,EAAE,EAAE,IAAI,CAAC,EAAE;gBACX,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB,CAAC,CAAC;SACJ,CAAA;QAED,OAAO,MAAM,CAAA;IACf,CAAC;IAEO,eAAe,CAAC,KAAmB,EAAE,MAAsB;QACjE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,MAAM,CAAA;IAC9D,CAAC;CACF,CAAA;AAhTY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;qCAOyB,sBAAe;QACpB,iBAAU;QACd,sBAAa;GAR7B,WAAW,CAgTvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mbc-cqrs-serverless/task",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.53-beta.0",
|
|
4
4
|
"description": "long-running task",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mbc",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@mbc-cqrs-serverless/core": "^0.1.
|
|
44
|
+
"@mbc-cqrs-serverless/core": "^0.1.53-beta.0"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "bf6367c02f58d40e2c31874509aa42ab28b53553"
|
|
47
47
|
}
|