@webiny/tasks 6.0.0-alpha.5 → 6.0.0-rc.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/README.md +10 -9
- package/context.js +43 -21
- package/context.js.map +1 -1
- package/crud/TaskLogPrivateModel.d.ts +9 -0
- package/crud/TaskLogPrivateModel.js +34 -0
- package/crud/TaskLogPrivateModel.js.map +1 -0
- package/crud/TaskPrivateModel.d.ts +9 -0
- package/crud/TaskPrivateModel.js +46 -0
- package/crud/TaskPrivateModel.js.map +1 -0
- package/crud/crud.tasks.d.ts +1 -1
- package/crud/crud.tasks.js +209 -104
- package/crud/crud.tasks.js.map +1 -1
- package/crud/definition.tasks.d.ts +1 -1
- package/crud/definition.tasks.js +9 -18
- package/crud/definition.tasks.js.map +1 -1
- package/crud/service.tasks.d.ts +1 -1
- package/crud/service.tasks.js +31 -36
- package/crud/service.tasks.js.map +1 -1
- package/decorators/RunnableTaskDecorator.d.ts +31 -0
- package/decorators/RunnableTaskDecorator.js +82 -0
- package/decorators/RunnableTaskDecorator.js.map +1 -0
- package/domain/errors.d.ts +29 -0
- package/domain/errors.js +47 -0
- package/domain/errors.js.map +1 -0
- package/events/TaskAfterCreateEvent.d.ts +6 -0
- package/events/TaskAfterCreateEvent.js +10 -0
- package/events/TaskAfterCreateEvent.js.map +1 -0
- package/events/TaskAfterDeleteEvent.d.ts +6 -0
- package/events/TaskAfterDeleteEvent.js +10 -0
- package/events/TaskAfterDeleteEvent.js.map +1 -0
- package/events/TaskAfterUpdateEvent.d.ts +6 -0
- package/events/TaskAfterUpdateEvent.js +10 -0
- package/events/TaskAfterUpdateEvent.js.map +1 -0
- package/events/TaskBeforeCreateEvent.d.ts +6 -0
- package/events/TaskBeforeCreateEvent.js +10 -0
- package/events/TaskBeforeCreateEvent.js.map +1 -0
- package/events/TaskBeforeDeleteEvent.d.ts +6 -0
- package/events/TaskBeforeDeleteEvent.js +10 -0
- package/events/TaskBeforeDeleteEvent.js.map +1 -0
- package/events/TaskBeforeUpdateEvent.d.ts +6 -0
- package/events/TaskBeforeUpdateEvent.js +10 -0
- package/events/TaskBeforeUpdateEvent.js.map +1 -0
- package/events/abstractions.d.ts +53 -0
- package/events/abstractions.js +39 -0
- package/events/abstractions.js.map +1 -0
- package/events/index.d.ts +7 -0
- package/events/index.js +9 -0
- package/events/index.js.map +1 -0
- package/features/AbortTask/AbortTaskUseCase.d.ts +10 -0
- package/features/AbortTask/AbortTaskUseCase.js +11 -0
- package/features/AbortTask/AbortTaskUseCase.js.map +1 -0
- package/features/AbortTask/abstractions.d.ts +25 -0
- package/features/AbortTask/abstractions.js +4 -0
- package/features/AbortTask/abstractions.js.map +1 -0
- package/features/AbortTask/feature.d.ts +2 -0
- package/features/AbortTask/feature.js +11 -0
- package/features/AbortTask/feature.js.map +1 -0
- package/features/AbortTask/index.d.ts +2 -0
- package/features/AbortTask/index.js +4 -0
- package/features/AbortTask/index.js.map +1 -0
- package/features/GetTask/GetTaskUseCase.d.ts +9 -0
- package/features/GetTask/GetTaskUseCase.js +10 -0
- package/features/GetTask/GetTaskUseCase.js.map +1 -0
- package/features/GetTask/abstractions.d.ts +10 -0
- package/features/GetTask/abstractions.js +4 -0
- package/features/GetTask/abstractions.js.map +1 -0
- package/features/GetTask/feature.d.ts +2 -0
- package/features/GetTask/feature.js +11 -0
- package/features/GetTask/feature.js.map +1 -0
- package/features/GetTask/index.d.ts +2 -0
- package/features/GetTask/index.js +4 -0
- package/features/GetTask/index.js.map +1 -0
- package/features/GetTaskDefinition/GetTaskDefinitionUseCase.d.ts +12 -0
- package/features/GetTaskDefinition/GetTaskDefinitionUseCase.js +25 -0
- package/features/GetTaskDefinition/GetTaskDefinitionUseCase.js.map +1 -0
- package/features/GetTaskDefinition/abstractions.d.ts +17 -0
- package/features/GetTaskDefinition/abstractions.js +4 -0
- package/features/GetTaskDefinition/abstractions.js.map +1 -0
- package/features/GetTaskDefinition/feature.d.ts +1 -0
- package/features/GetTaskDefinition/feature.js +10 -0
- package/features/GetTaskDefinition/feature.js.map +1 -0
- package/features/GetTaskDefinition/index.d.ts +2 -0
- package/features/GetTaskDefinition/index.js +4 -0
- package/features/GetTaskDefinition/index.js.map +1 -0
- package/features/ListTaskDefinitions/ListTaskDefinitionsUseCase.d.ts +11 -0
- package/features/ListTaskDefinitions/ListTaskDefinitionsUseCase.js +18 -0
- package/features/ListTaskDefinitions/ListTaskDefinitionsUseCase.js.map +1 -0
- package/features/ListTaskDefinitions/abstractions.d.ts +9 -0
- package/features/ListTaskDefinitions/abstractions.js +4 -0
- package/features/ListTaskDefinitions/abstractions.js.map +1 -0
- package/features/ListTaskDefinitions/feature.d.ts +1 -0
- package/features/ListTaskDefinitions/feature.js +10 -0
- package/features/ListTaskDefinitions/feature.js.map +1 -0
- package/features/ListTaskDefinitions/index.d.ts +2 -0
- package/features/ListTaskDefinitions/index.js +4 -0
- package/features/ListTaskDefinitions/index.js.map +1 -0
- package/features/ListTasks/ListTasksUseCase.d.ts +9 -0
- package/features/ListTasks/ListTasksUseCase.js +10 -0
- package/features/ListTasks/ListTasksUseCase.js.map +1 -0
- package/features/ListTasks/abstractions.d.ts +13 -0
- package/features/ListTasks/abstractions.js +4 -0
- package/features/ListTasks/abstractions.js.map +1 -0
- package/features/ListTasks/feature.d.ts +2 -0
- package/features/ListTasks/feature.js +11 -0
- package/features/ListTasks/feature.js.map +1 -0
- package/features/ListTasks/index.d.ts +2 -0
- package/features/ListTasks/index.js +4 -0
- package/features/ListTasks/index.js.map +1 -0
- package/features/TaskController/TaskController.d.ts +49 -0
- package/features/TaskController/TaskController.js +71 -0
- package/features/TaskController/TaskController.js.map +1 -0
- package/features/TaskController/augmentation.d.ts +60 -0
- package/features/TaskController/augmentation.js +3 -0
- package/features/TaskController/augmentation.js.map +1 -0
- package/features/TaskController/index.d.ts +2 -0
- package/features/TaskController/index.js +7 -0
- package/features/TaskController/index.js.map +1 -0
- package/features/TaskExecutionContext/TaskExecutionContext.d.ts +24 -0
- package/features/TaskExecutionContext/TaskExecutionContext.js +50 -0
- package/features/TaskExecutionContext/TaskExecutionContext.js.map +1 -0
- package/features/TaskExecutionContext/abstractions.d.ts +26 -0
- package/features/TaskExecutionContext/abstractions.js +13 -0
- package/features/TaskExecutionContext/abstractions.js.map +1 -0
- package/features/TaskExecutionContext/feature.d.ts +1 -0
- package/features/TaskExecutionContext/feature.js +10 -0
- package/features/TaskExecutionContext/feature.js.map +1 -0
- package/features/TaskExecutionContext/index.d.ts +1 -0
- package/features/TaskExecutionContext/index.js +3 -0
- package/features/TaskExecutionContext/index.js.map +1 -0
- package/features/TriggerTask/TriggerTaskUseCase.d.ts +10 -0
- package/features/TriggerTask/TriggerTaskUseCase.js +11 -0
- package/features/TriggerTask/TriggerTaskUseCase.js.map +1 -0
- package/features/TriggerTask/abstractions.d.ts +28 -0
- package/features/TriggerTask/abstractions.js +4 -0
- package/features/TriggerTask/abstractions.js.map +1 -0
- package/features/TriggerTask/feature.d.ts +2 -0
- package/features/TriggerTask/feature.js +11 -0
- package/features/TriggerTask/feature.js.map +1 -0
- package/features/TriggerTask/index.d.ts +2 -0
- package/features/TriggerTask/index.js +4 -0
- package/features/TriggerTask/index.js.map +1 -0
- package/global.d.ts +1 -0
- package/global.js +3 -0
- package/global.js.map +1 -0
- package/graphql/checkPermissions.d.ts +1 -1
- package/graphql/checkPermissions.js +3 -9
- package/graphql/checkPermissions.js.map +1 -1
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +58 -61
- package/graphql/index.js.map +1 -1
- package/graphql/utils.d.ts +1 -1
- package/graphql/utils.js +8 -17
- package/graphql/utils.js.map +1 -1
- package/handler/index.d.ts +2 -2
- package/handler/index.js +33 -40
- package/handler/index.js.map +1 -1
- package/handler/register.js +5 -7
- package/handler/register.js.map +1 -1
- package/handler/types.d.ts +1 -3
- package/handler/types.js +1 -5
- package/handler/types.js.map +1 -1
- package/index.d.ts +5 -6
- package/index.js +5 -60
- package/index.js.map +1 -1
- package/package.json +22 -26
- package/plugins/TaskServicePlugin.d.ts +1 -2
- package/plugins/TaskServicePlugin.js +2 -9
- package/plugins/TaskServicePlugin.js.map +1 -1
- package/plugins/index.d.ts +1 -1
- package/plugins/index.js +1 -16
- package/plugins/index.js.map +1 -1
- package/response/DatabaseResponse.d.ts +3 -3
- package/response/DatabaseResponse.js +14 -20
- package/response/DatabaseResponse.js.map +1 -1
- package/response/Response.d.ts +4 -3
- package/response/Response.js +20 -31
- package/response/Response.js.map +1 -1
- package/response/ResponseAbortedResult.d.ts +3 -4
- package/response/ResponseAbortedResult.js +3 -11
- package/response/ResponseAbortedResult.js.map +1 -1
- package/response/ResponseContinueResult.d.ts +4 -5
- package/response/ResponseContinueResult.js +3 -11
- package/response/ResponseContinueResult.js.map +1 -1
- package/response/ResponseDoneResult.d.ts +4 -6
- package/response/ResponseDoneResult.js +3 -11
- package/response/ResponseDoneResult.js.map +1 -1
- package/response/ResponseErrorResult.d.ts +3 -4
- package/response/ResponseErrorResult.js +3 -11
- package/response/ResponseErrorResult.js.map +1 -1
- package/response/TaskResponse.d.ts +7 -6
- package/response/TaskResponse.js +5 -12
- package/response/TaskResponse.js.map +1 -1
- package/response/abstractions/Response.d.ts +7 -7
- package/response/abstractions/Response.js +1 -5
- package/response/abstractions/Response.js.map +1 -1
- package/response/abstractions/ResponseAbortedResult.d.ts +3 -3
- package/response/abstractions/ResponseAbortedResult.js +1 -5
- package/response/abstractions/ResponseAbortedResult.js.map +1 -1
- package/response/abstractions/ResponseBaseResult.d.ts +2 -3
- package/response/abstractions/ResponseBaseResult.js +1 -5
- package/response/abstractions/ResponseBaseResult.js.map +1 -1
- package/response/abstractions/ResponseContinueResult.d.ts +4 -4
- package/response/abstractions/ResponseContinueResult.js +1 -5
- package/response/abstractions/ResponseContinueResult.js.map +1 -1
- package/response/abstractions/ResponseDoneResult.d.ts +5 -6
- package/response/abstractions/ResponseDoneResult.js +1 -5
- package/response/abstractions/ResponseDoneResult.js.map +1 -1
- package/response/abstractions/ResponseErrorResult.d.ts +4 -5
- package/response/abstractions/ResponseErrorResult.js +1 -5
- package/response/abstractions/ResponseErrorResult.js.map +1 -1
- package/response/abstractions/TaskResponse.d.ts +8 -30
- package/response/abstractions/TaskResponse.js +1 -5
- package/response/abstractions/TaskResponse.js.map +1 -1
- package/response/abstractions/index.d.ts +7 -7
- package/response/abstractions/index.js +7 -82
- package/response/abstractions/index.js.map +1 -1
- package/response/index.d.ts +7 -7
- package/response/index.js +7 -82
- package/response/index.js.map +1 -1
- package/runner/TaskControl.d.ts +4 -4
- package/runner/TaskControl.js +61 -39
- package/runner/TaskControl.js.map +1 -1
- package/runner/TaskEventValidation.d.ts +2 -2
- package/runner/TaskEventValidation.js +11 -20
- package/runner/TaskEventValidation.js.map +1 -1
- package/runner/TaskManager.d.ts +7 -10
- package/runner/TaskManager.js +19 -39
- package/runner/TaskManager.js.map +1 -1
- package/runner/TaskManagerStore.d.ts +7 -7
- package/runner/TaskManagerStore.js +16 -25
- package/runner/TaskManagerStore.js.map +1 -1
- package/runner/TaskRunner.d.ts +5 -6
- package/runner/TaskRunner.js +9 -31
- package/runner/TaskRunner.js.map +1 -1
- package/runner/abstractions/TaskControl.d.ts +4 -4
- package/runner/abstractions/TaskControl.js +1 -5
- package/runner/abstractions/TaskControl.js.map +1 -1
- package/runner/abstractions/TaskEventValidation.d.ts +1 -1
- package/runner/abstractions/TaskEventValidation.js +1 -5
- package/runner/abstractions/TaskEventValidation.js.map +1 -1
- package/runner/abstractions/TaskManager.d.ts +4 -4
- package/runner/abstractions/TaskManager.js +1 -5
- package/runner/abstractions/TaskManager.js.map +1 -1
- package/runner/abstractions/TaskManagerStore.d.ts +11 -11
- package/runner/abstractions/TaskManagerStore.js +1 -5
- package/runner/abstractions/TaskManagerStore.js.map +1 -1
- package/runner/abstractions/TaskRunner.d.ts +3 -3
- package/runner/abstractions/TaskRunner.js +1 -5
- package/runner/abstractions/TaskRunner.js.map +1 -1
- package/runner/abstractions/index.d.ts +5 -5
- package/runner/abstractions/index.js +5 -60
- package/runner/abstractions/index.js.map +1 -1
- package/runner/index.d.ts +1 -1
- package/runner/index.js +1 -16
- package/runner/index.js.map +1 -1
- package/service/EventBridgeEventTransportPlugin.d.ts +4 -5
- package/service/EventBridgeEventTransportPlugin.js +8 -17
- package/service/EventBridgeEventTransportPlugin.js.map +1 -1
- package/service/StepFunctionServicePlugin.d.ts +4 -5
- package/service/StepFunctionServicePlugin.js +11 -21
- package/service/StepFunctionServicePlugin.js.map +1 -1
- package/service/createService.d.ts +2 -2
- package/service/createService.js +7 -18
- package/service/createService.js.map +1 -1
- package/service/index.d.ts +3 -3
- package/service/index.js +6 -27
- package/service/index.js.map +1 -1
- package/tasks/testingRunTask.d.ts +10 -1
- package/tasks/testingRunTask.js +13 -18
- package/tasks/testingRunTask.js.map +1 -1
- package/types.d.ts +32 -214
- package/types.js +5 -56
- package/types.js.map +1 -1
- package/utils/ObjectUpdater.js +4 -11
- package/utils/ObjectUpdater.js.map +1 -1
- package/utils/getErrorProperties.d.ts +1 -1
- package/utils/getErrorProperties.js +3 -10
- package/utils/getErrorProperties.js.map +1 -1
- package/utils/getObjectProperties.js +1 -8
- package/utils/getObjectProperties.js.map +1 -1
- package/utils/index.d.ts +3 -3
- package/utils/index.js +3 -38
- package/utils/index.js.map +1 -1
- package/crud/model.d.ts +0 -5
- package/crud/model.js +0 -216
- package/crud/model.js.map +0 -1
- package/crud/where.d.ts +0 -1
- package/crud/where.js +0 -33
- package/crud/where.js.map +0 -1
- package/task/index.d.ts +0 -2
- package/task/index.js +0 -29
- package/task/index.js.map +0 -1
- package/task/input.d.ts +0 -15
- package/task/input.js +0 -21
- package/task/input.js.map +0 -1
- package/task/plugin.d.ts +0 -36
- package/task/plugin.js +0 -106
- package/task/plugin.js.map +0 -1
|
@@ -1,30 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const validation = _zod.default.object({
|
|
11
|
-
webinyTaskId: _zod.default.string(),
|
|
12
|
-
webinyTaskDefinitionId: _zod.default.string(),
|
|
13
|
-
endpoint: _zod.default.string(),
|
|
14
|
-
tenant: _zod.default.string(),
|
|
15
|
-
locale: _zod.default.string(),
|
|
16
|
-
executionName: _zod.default.string(),
|
|
17
|
-
stateMachineId: _zod.default.string()
|
|
1
|
+
import zod from "zod";
|
|
2
|
+
import { createZodError } from "@webiny/utils";
|
|
3
|
+
const validation = zod.object({
|
|
4
|
+
webinyTaskId: zod.string(),
|
|
5
|
+
webinyTaskDefinitionId: zod.string(),
|
|
6
|
+
endpoint: zod.string(),
|
|
7
|
+
tenant: zod.string(),
|
|
8
|
+
executionName: zod.string(),
|
|
9
|
+
stateMachineId: zod.string()
|
|
18
10
|
}).required();
|
|
19
|
-
class TaskEventValidation {
|
|
11
|
+
export class TaskEventValidation {
|
|
20
12
|
validate(event) {
|
|
21
13
|
const result = validation.safeParse(event);
|
|
22
14
|
if (result.success) {
|
|
23
15
|
return result.data;
|
|
24
16
|
}
|
|
25
|
-
throw
|
|
17
|
+
throw createZodError(result.error);
|
|
26
18
|
}
|
|
27
19
|
}
|
|
28
|
-
exports.TaskEventValidation = TaskEventValidation;
|
|
29
20
|
|
|
30
21
|
//# sourceMappingURL=TaskEventValidation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["zod","createZodError","validation","object","webinyTaskId","string","webinyTaskDefinitionId","endpoint","tenant","executionName","stateMachineId","required","TaskEventValidation","validate","event","result","safeParse","success","data","error"],"sources":["TaskEventValidation.ts"],"sourcesContent":["import zod from \"zod\";\nimport { createZodError } from \"@webiny/utils\";\nimport type { ITaskEventValidation, ITaskEventValidationResult } from \"./abstractions/index.js\";\nimport type { ITaskEvent } from \"~/handler/types.js\";\n\nconst validation = zod\n .object({\n webinyTaskId: zod.string(),\n webinyTaskDefinitionId: zod.string(),\n endpoint: zod.string(),\n tenant: zod.string(),\n executionName: zod.string(),\n stateMachineId: zod.string()\n })\n .required();\n\nexport class TaskEventValidation implements ITaskEventValidation {\n public validate(event: Partial<ITaskEvent>): ITaskEventValidationResult {\n const result = validation.safeParse(event);\n if (result.success) {\n return result.data;\n }\n throw createZodError(result.error);\n }\n}\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AACrB,SAASC,cAAc,QAAQ,eAAe;AAI9C,MAAMC,UAAU,GAAGF,GAAG,CACjBG,MAAM,CAAC;EACJC,YAAY,EAAEJ,GAAG,CAACK,MAAM,CAAC,CAAC;EAC1BC,sBAAsB,EAAEN,GAAG,CAACK,MAAM,CAAC,CAAC;EACpCE,QAAQ,EAAEP,GAAG,CAACK,MAAM,CAAC,CAAC;EACtBG,MAAM,EAAER,GAAG,CAACK,MAAM,CAAC,CAAC;EACpBI,aAAa,EAAET,GAAG,CAACK,MAAM,CAAC,CAAC;EAC3BK,cAAc,EAAEV,GAAG,CAACK,MAAM,CAAC;AAC/B,CAAC,CAAC,CACDM,QAAQ,CAAC,CAAC;AAEf,OAAO,MAAMC,mBAAmB,CAAiC;EACtDC,QAAQA,CAACC,KAA0B,EAA8B;IACpE,MAAMC,MAAM,GAAGb,UAAU,CAACc,SAAS,CAACF,KAAK,CAAC;IAC1C,IAAIC,MAAM,CAACE,OAAO,EAAE;MAChB,OAAOF,MAAM,CAACG,IAAI;IACtB;IACA,MAAMjB,cAAc,CAACc,MAAM,CAACI,KAAK,CAAC;EACtC;AACJ","ignoreList":[]}
|
package/runner/TaskManager.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import type { ITaskManager, ITaskManagerStorePrivate
|
|
2
|
-
import type { Context
|
|
3
|
-
import type { IResponse, IResponseResult
|
|
4
|
-
|
|
5
|
-
export declare class TaskManager
|
|
6
|
-
private readonly runner;
|
|
1
|
+
import type { ITaskManager, ITaskManagerStorePrivate } from "./abstractions/index.js";
|
|
2
|
+
import type { Context } from "../types.js";
|
|
3
|
+
import type { IResponse, IResponseResult } from "../response/abstractions/index.js";
|
|
4
|
+
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
5
|
+
export declare class TaskManager implements ITaskManager {
|
|
7
6
|
private readonly context;
|
|
8
7
|
private readonly response;
|
|
9
|
-
private readonly taskResponse;
|
|
10
8
|
private readonly store;
|
|
11
|
-
constructor(
|
|
12
|
-
run(definition:
|
|
9
|
+
constructor(context: Context, response: IResponse, store: ITaskManagerStorePrivate);
|
|
10
|
+
run(definition: TaskDefinition.Runnable): Promise<IResponseResult>;
|
|
13
11
|
}
|
|
14
|
-
export {};
|
package/runner/TaskManager.js
CHANGED
|
@@ -1,34 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _types = require("../types");
|
|
8
|
-
var _getErrorProperties = require("../utils/getErrorProperties");
|
|
9
|
-
class TaskManager {
|
|
10
|
-
constructor(runner, context, response, taskResponse, store) {
|
|
11
|
-
this.runner = runner;
|
|
1
|
+
import { TaskDataStatus } from "../types.js";
|
|
2
|
+
import { getErrorProperties } from "../utils/getErrorProperties.js";
|
|
3
|
+
import { TaskResultStatus } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
4
|
+
import { TaskController } from "@webiny/api-core/features/task/TaskController/abstractions.js";
|
|
5
|
+
export class TaskManager {
|
|
6
|
+
constructor(context, response, store) {
|
|
12
7
|
this.context = context;
|
|
13
8
|
this.response = response;
|
|
14
|
-
this.taskResponse = taskResponse;
|
|
15
9
|
this.store = store;
|
|
16
10
|
}
|
|
17
11
|
async run(definition) {
|
|
18
12
|
/**
|
|
19
13
|
* If task was aborted, do not run it again, return as it was done.
|
|
20
14
|
*/
|
|
21
|
-
if (this.store.getStatus() ===
|
|
15
|
+
if (this.store.getStatus() === TaskDataStatus.ABORTED) {
|
|
22
16
|
return this.response.aborted();
|
|
23
17
|
}
|
|
24
18
|
/**
|
|
25
19
|
* If the task status is pending, update it to running and add a log.
|
|
26
20
|
*/
|
|
27
21
|
//
|
|
28
|
-
else if (this.store.getStatus() ===
|
|
22
|
+
else if (this.store.getStatus() === TaskDataStatus.PENDING) {
|
|
29
23
|
try {
|
|
30
24
|
await this.store.updateTask({
|
|
31
|
-
taskStatus:
|
|
25
|
+
taskStatus: TaskDataStatus.RUNNING,
|
|
32
26
|
startedOn: new Date().toISOString(),
|
|
33
27
|
executionName: this.response.event.executionName,
|
|
34
28
|
iterations: 1
|
|
@@ -49,8 +43,7 @@ class TaskManager {
|
|
|
49
43
|
try {
|
|
50
44
|
if (definition.onMaxIterations) {
|
|
51
45
|
await definition.onMaxIterations({
|
|
52
|
-
task: this.store.getTask()
|
|
53
|
-
context: this.context
|
|
46
|
+
task: this.store.getTask()
|
|
54
47
|
});
|
|
55
48
|
}
|
|
56
49
|
return this.response.error({
|
|
@@ -62,7 +55,7 @@ class TaskManager {
|
|
|
62
55
|
return this.response.error({
|
|
63
56
|
error: {
|
|
64
57
|
message: "Failed to execute onMaxIterations handler.",
|
|
65
|
-
data:
|
|
58
|
+
data: getErrorProperties(ex)
|
|
66
59
|
}
|
|
67
60
|
});
|
|
68
61
|
}
|
|
@@ -87,45 +80,33 @@ class TaskManager {
|
|
|
87
80
|
let result;
|
|
88
81
|
try {
|
|
89
82
|
const input = structuredClone(this.store.getInput());
|
|
83
|
+
const controller = this.context.container.resolve(TaskController);
|
|
90
84
|
/**
|
|
91
85
|
* We always run the task without authorization because we are running a task without a user - nothing to authorize against.
|
|
92
86
|
*/
|
|
93
87
|
result = await this.context.security.withoutAuthorization(async () => {
|
|
94
88
|
return await definition.run({
|
|
95
89
|
input,
|
|
96
|
-
|
|
97
|
-
response: this.taskResponse,
|
|
98
|
-
isCloseToTimeout: seconds => {
|
|
99
|
-
return this.runner.isCloseToTimeout(seconds);
|
|
100
|
-
},
|
|
101
|
-
isAborted: () => {
|
|
102
|
-
return this.store.getStatus() === _types.TaskDataStatus.ABORTED;
|
|
103
|
-
},
|
|
104
|
-
store: this.store,
|
|
105
|
-
trigger: async params => {
|
|
106
|
-
return this.context.tasks.trigger({
|
|
107
|
-
...params,
|
|
108
|
-
parent: this.store.getTask()
|
|
109
|
-
});
|
|
110
|
-
},
|
|
111
|
-
timer: this.runner.timer
|
|
90
|
+
controller
|
|
112
91
|
});
|
|
113
92
|
});
|
|
114
93
|
} catch (ex) {
|
|
115
94
|
return this.response.error({
|
|
116
|
-
error:
|
|
95
|
+
error: getErrorProperties(ex)
|
|
117
96
|
});
|
|
118
97
|
}
|
|
119
|
-
|
|
98
|
+
|
|
99
|
+
// Convert TaskDefinition.Result to IResponseResult
|
|
100
|
+
if (result.status === TaskResultStatus.CONTINUE) {
|
|
120
101
|
return this.response.continue({
|
|
121
102
|
input: result.input,
|
|
122
103
|
wait: result.wait
|
|
123
104
|
});
|
|
124
|
-
} else if (result.status ===
|
|
105
|
+
} else if (result.status === TaskResultStatus.ERROR) {
|
|
125
106
|
return this.response.error({
|
|
126
107
|
error: result.error
|
|
127
108
|
});
|
|
128
|
-
} else if (result.status ===
|
|
109
|
+
} else if (result.status === TaskResultStatus.ABORTED) {
|
|
129
110
|
return this.response.aborted();
|
|
130
111
|
}
|
|
131
112
|
return this.response.done({
|
|
@@ -134,6 +115,5 @@ class TaskManager {
|
|
|
134
115
|
});
|
|
135
116
|
}
|
|
136
117
|
}
|
|
137
|
-
exports.TaskManager = TaskManager;
|
|
138
118
|
|
|
139
119
|
//# sourceMappingURL=TaskManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_types","require","_getErrorProperties","TaskManager","constructor","runner","context","response","taskResponse","store","run","definition","getStatus","TaskDataStatus","ABORTED","aborted","PENDING","updateTask","taskStatus","RUNNING","startedOn","Date","toISOString","executionName","event","iterations","save","error","getTask","maxIterations","onMaxIterations","task","message","ex","data","getErrorProperties","result","input","structuredClone","getInput","security","withoutAuthorization","isCloseToTimeout","seconds","isAborted","trigger","params","tasks","parent","timer","status","TaskResponseStatus","CONTINUE","continue","wait","ERROR","done","output","exports"],"sources":["TaskManager.ts"],"sourcesContent":["import type { ITaskManager, ITaskManagerStorePrivate, ITaskRunner } from \"./abstractions\";\nimport type { Context, ITask, ITaskDataInput, ITaskDefinition, ITaskTriggerParams } from \"~/types\";\nimport { TaskDataStatus, TaskResponseStatus } from \"~/types\";\nimport type {\n IResponse,\n IResponseResult,\n ITaskResponse,\n ITaskResponseResult\n} from \"~/response/abstractions\";\nimport { getErrorProperties } from \"~/utils/getErrorProperties\";\n\ntype ITaskManagerRunner = Pick<ITaskRunner, \"isCloseToTimeout\" | \"timer\">;\n\nexport class TaskManager<T = ITaskDataInput> implements ITaskManager<T> {\n private readonly runner: ITaskManagerRunner;\n private readonly context: Context;\n private readonly response: IResponse;\n private readonly taskResponse: ITaskResponse;\n private readonly store: ITaskManagerStorePrivate;\n\n public constructor(\n runner: ITaskManagerRunner,\n context: Context,\n response: IResponse,\n taskResponse: ITaskResponse,\n store: ITaskManagerStorePrivate\n ) {\n this.runner = runner;\n this.context = context;\n this.response = response;\n this.taskResponse = taskResponse;\n this.store = store;\n }\n\n public async run(definition: ITaskDefinition): Promise<IResponseResult> {\n /**\n * If task was aborted, do not run it again, return as it was done.\n */\n if (this.store.getStatus() === TaskDataStatus.ABORTED) {\n return this.response.aborted();\n }\n /**\n * If the task status is pending, update it to running and add a log.\n */\n //\n else if (this.store.getStatus() === TaskDataStatus.PENDING) {\n try {\n await this.store.updateTask({\n taskStatus: TaskDataStatus.RUNNING,\n startedOn: new Date().toISOString(),\n executionName: this.response.event.executionName,\n iterations: 1\n });\n await this.store.save();\n } catch (error) {\n return this.response.error({\n error\n });\n }\n }\n /**\n * We do not want to run the task indefinitely.\n * If the task has reached the max iterations, we will stop it and execute the onMaxIterations handler, if any.\n */\n //\n else if (this.store.getTask().iterations >= definition.maxIterations) {\n try {\n if (definition.onMaxIterations) {\n await definition.onMaxIterations({\n task: this.store.getTask(),\n context: this.context\n });\n }\n return this.response.error({\n error: {\n message: \"Task reached max iterations.\"\n }\n });\n } catch (ex) {\n return this.response.error({\n error: {\n message: \"Failed to execute onMaxIterations handler.\",\n data: getErrorProperties(ex)\n }\n });\n }\n }\n /**\n * Always update the task iteration.\n */\n //\n else {\n try {\n await this.store.updateTask(task => {\n return {\n iterations: task.iterations + 1\n };\n });\n } catch (error) {\n return this.response.error({\n error\n });\n }\n }\n\n let result: ITaskResponseResult;\n\n try {\n const input = structuredClone(this.store.getInput());\n /**\n * We always run the task without authorization because we are running a task without a user - nothing to authorize against.\n */\n result = await this.context.security.withoutAuthorization(async () => {\n return await definition.run({\n input,\n context: this.context,\n response: this.taskResponse,\n isCloseToTimeout: seconds => {\n return this.runner.isCloseToTimeout(seconds);\n },\n isAborted: () => {\n return this.store.getStatus() === TaskDataStatus.ABORTED;\n },\n store: this.store,\n trigger: async <I = ITaskDataInput>(\n params: Omit<ITaskTriggerParams<I>, \"parent\">\n ): Promise<ITask<I>> => {\n return this.context.tasks.trigger({\n ...params,\n parent: this.store.getTask()\n });\n },\n timer: this.runner.timer\n });\n });\n } catch (ex) {\n return this.response.error({\n error: getErrorProperties(ex)\n });\n }\n\n if (result.status === TaskResponseStatus.CONTINUE) {\n return this.response.continue({\n input: result.input,\n wait: result.wait\n });\n } else if (result.status === TaskResponseStatus.ERROR) {\n return this.response.error({\n error: result.error\n });\n } else if (result.status === TaskResponseStatus.ABORTED) {\n return this.response.aborted();\n }\n return this.response.done({\n message: result.message,\n output: result.output\n });\n }\n}\n"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAOA,IAAAC,mBAAA,GAAAD,OAAA;AAIO,MAAME,WAAW,CAAgD;EAO7DC,WAAWA,CACdC,MAA0B,EAC1BC,OAAgB,EAChBC,QAAmB,EACnBC,YAA2B,EAC3BC,KAA+B,EACjC;IACE,IAAI,CAACJ,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,OAAO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AAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["TaskDataStatus","getErrorProperties","TaskResultStatus","TaskController","TaskManager","constructor","context","response","store","run","definition","getStatus","ABORTED","aborted","PENDING","updateTask","taskStatus","RUNNING","startedOn","Date","toISOString","executionName","event","iterations","save","error","getTask","maxIterations","onMaxIterations","task","message","ex","data","result","input","structuredClone","getInput","controller","container","resolve","security","withoutAuthorization","status","CONTINUE","continue","wait","ERROR","done","output"],"sources":["TaskManager.ts"],"sourcesContent":["import type { ITaskManager, ITaskManagerStorePrivate } from \"./abstractions/index.js\";\nimport type { Context } from \"~/types.js\";\nimport { TaskDataStatus } from \"~/types.js\";\nimport type { IResponse, IResponseResult } from \"~/response/abstractions/index.js\";\nimport { getErrorProperties } from \"~/utils/getErrorProperties.js\";\nimport {\n TaskDefinition,\n TaskResultStatus\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { TaskController } from \"@webiny/api-core/features/task/TaskController/abstractions.js\";\n\nexport class TaskManager implements ITaskManager {\n private readonly context: Context;\n private readonly response: IResponse;\n private readonly store: ITaskManagerStorePrivate;\n\n public constructor(context: Context, response: IResponse, store: ITaskManagerStorePrivate) {\n this.context = context;\n this.response = response;\n this.store = store;\n }\n\n public async run(definition: TaskDefinition.Runnable): Promise<IResponseResult> {\n /**\n * If task was aborted, do not run it again, return as it was done.\n */\n if (this.store.getStatus() === TaskDataStatus.ABORTED) {\n return this.response.aborted();\n }\n /**\n * If the task status is pending, update it to running and add a log.\n */\n //\n else if (this.store.getStatus() === TaskDataStatus.PENDING) {\n try {\n await this.store.updateTask({\n taskStatus: TaskDataStatus.RUNNING,\n startedOn: new Date().toISOString(),\n executionName: this.response.event.executionName,\n iterations: 1\n });\n await this.store.save();\n } catch (error) {\n return this.response.error({\n error\n });\n }\n }\n /**\n * We do not want to run the task indefinitely.\n * If the task has reached the max iterations, we will stop it and execute the onMaxIterations handler, if any.\n */\n //\n else if (this.store.getTask().iterations >= definition.maxIterations) {\n try {\n if (definition.onMaxIterations) {\n await definition.onMaxIterations({\n task: this.store.getTask()\n });\n }\n return this.response.error({\n error: {\n message: \"Task reached max iterations.\"\n }\n });\n } catch (ex) {\n return this.response.error({\n error: {\n message: \"Failed to execute onMaxIterations handler.\",\n data: getErrorProperties(ex)\n }\n });\n }\n }\n /**\n * Always update the task iteration.\n */\n //\n else {\n try {\n await this.store.updateTask(task => {\n return {\n iterations: task.iterations + 1\n };\n });\n } catch (error) {\n return this.response.error({\n error\n });\n }\n }\n\n let result: TaskDefinition.Result;\n\n try {\n const input = structuredClone(this.store.getInput());\n const controller = this.context.container.resolve(TaskController);\n /**\n * We always run the task without authorization because we are running a task without a user - nothing to authorize against.\n */\n result = await this.context.security.withoutAuthorization(async () => {\n return await definition.run({\n input,\n controller\n });\n });\n } catch (ex) {\n return this.response.error({\n error: getErrorProperties(ex)\n });\n }\n\n // Convert TaskDefinition.Result to IResponseResult\n if (result.status === TaskResultStatus.CONTINUE) {\n return this.response.continue({\n input: result.input,\n wait: result.wait\n });\n } else if (result.status === TaskResultStatus.ERROR) {\n return this.response.error({\n error: result.error\n });\n } else if (result.status === TaskResultStatus.ABORTED) {\n return this.response.aborted();\n }\n return this.response.done({\n message: result.message,\n output: result.output\n });\n }\n}\n"],"mappings":"AAEA,SAASA,cAAc;AAEvB,SAASC,kBAAkB;AAC3B,SAEIC,gBAAgB,QACb,wDAAwD;AAC/D,SAASC,cAAc,QAAQ,+DAA+D;AAE9F,OAAO,MAAMC,WAAW,CAAyB;EAKtCC,WAAWA,CAACC,OAAgB,EAAEC,QAAmB,EAAEC,KAA+B,EAAE;IACvF,IAAI,CAACF,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,QAAQ,GAAGA,QAAQ;IACxB,IAAI,CAACC,KAAK,GAAGA,KAAK;EACtB;EAEA,MAAaC,GAAGA,CAACC,UAAmC,EAA4B;IAC5E;AACR;AACA;IACQ,IAAI,IAAI,CAACF,KAAK,CAACG,SAAS,CAAC,CAAC,KAAK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AAO,IAAI,CAACvC,QAAQ,CAACkB,KAAK,CAAC;QACvBA,KAAK,EAAEQ,MAAM,CAACR;MAClB,CAAC,CAAC;IACN,CAAC,MAAM,IAAIQ,MAAM,CAACS,MAAM,KAAKxC,gBAAgB,CAACU,OAAO,EAAE;MACnD,OAAO,IAAI,CAACL,QAAQ,CAACM,OAAO,CAAC,CAAC;IAClC;IACA,OAAO,IAAI,CAACN,QAAQ,CAACwC,IAAI,CAAC;MACtBjB,OAAO,EAAEG,MAAM,CAACH,OAAO;MACvBkB,MAAM,EAAEf,MAAM,CAACe;IACnB,CAAC,CAAC;EACN;AACJ","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ITask, ITaskDataInput, ITaskLog, ITaskManagerStoreInfoLog, ITaskManagerStorePrivate, ITaskManagerStoreSetOutputOptions, ITaskManagerStoreUpdateTaskInputOptions, ITaskManagerStoreUpdateTaskOptions,
|
|
2
|
-
import type { ITaskManagerStoreAddLogOptions, ITaskManagerStoreErrorLog, ITaskManagerStoreUpdateTaskInputParam, ITaskManagerStoreUpdateTaskParams } from "./abstractions";
|
|
3
|
-
import
|
|
1
|
+
import type { ITask, ITaskDataInput, ITaskLog, ITaskManagerStoreInfoLog, ITaskManagerStorePrivate, ITaskManagerStoreSetOutputOptions, ITaskManagerStoreUpdateTaskInputOptions, ITaskManagerStoreUpdateTaskOptions, ITasksContextObject, TaskDataStatus } from "../types.js";
|
|
2
|
+
import type { ITaskManagerStoreAddLogOptions, ITaskManagerStoreErrorLog, ITaskManagerStoreUpdateTaskInputParam, ITaskManagerStoreUpdateTaskParams } from "./abstractions/index.js";
|
|
3
|
+
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
4
4
|
export interface TaskManagerStoreContext {
|
|
5
5
|
tasks: Pick<ITasksContextObject, "updateTask" | "updateLog" | "listTasks">;
|
|
6
6
|
}
|
|
@@ -8,19 +8,19 @@ export interface ITaskManagerStoreParams {
|
|
|
8
8
|
context: TaskManagerStoreContext;
|
|
9
9
|
task: ITask;
|
|
10
10
|
log: ITaskLog;
|
|
11
|
-
|
|
11
|
+
databaseLogs: boolean;
|
|
12
12
|
}
|
|
13
|
-
export declare class TaskManagerStore<T extends ITaskDataInput = ITaskDataInput, O extends
|
|
13
|
+
export declare class TaskManagerStore<T extends ITaskDataInput = ITaskDataInput, O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput> implements ITaskManagerStorePrivate<T, O> {
|
|
14
14
|
private readonly context;
|
|
15
15
|
private task;
|
|
16
16
|
private taskLog;
|
|
17
|
-
private readonly
|
|
17
|
+
private readonly databaseLogs;
|
|
18
18
|
private readonly taskUpdater;
|
|
19
19
|
private readonly taskLogUpdater;
|
|
20
20
|
constructor(params: ITaskManagerStoreParams);
|
|
21
21
|
getStatus(): TaskDataStatus;
|
|
22
22
|
getTask(): ITask<T, O>;
|
|
23
|
-
listChildTasks<I =
|
|
23
|
+
listChildTasks<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput>(definitionId?: string): Promise<ITask<I, O>[]>;
|
|
24
24
|
updateTask(param: ITaskManagerStoreUpdateTaskParams<T, O>, options?: ITaskManagerStoreUpdateTaskOptions): Promise<void>;
|
|
25
25
|
updateInput(param: ITaskManagerStoreUpdateTaskInputParam<T>, options?: ITaskManagerStoreUpdateTaskInputOptions): Promise<void>;
|
|
26
26
|
getInput(): T;
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.TaskManagerStore = void 0;
|
|
8
|
-
var _types = require("../types");
|
|
9
|
-
var _deepEqual = _interopRequireDefault(require("deep-equal"));
|
|
10
|
-
var _getObjectProperties = require("../utils/getObjectProperties");
|
|
11
|
-
var _ObjectUpdater = require("../utils/ObjectUpdater");
|
|
1
|
+
import { TaskLogItemType } from "../types.js";
|
|
12
2
|
/**
|
|
13
3
|
* Package deep-equal does not have types.
|
|
14
4
|
*/
|
|
15
|
-
|
|
5
|
+
import deepEqual from "deep-equal";
|
|
6
|
+
import { getObjectProperties } from "../utils/getObjectProperties.js";
|
|
7
|
+
import { ObjectUpdater } from "../utils/ObjectUpdater.js";
|
|
16
8
|
const getInput = (originalInput, input) => {
|
|
17
9
|
if (typeof input === "function") {
|
|
18
10
|
return input(originalInput);
|
|
@@ -22,14 +14,14 @@ const getInput = (originalInput, input) => {
|
|
|
22
14
|
...input
|
|
23
15
|
};
|
|
24
16
|
};
|
|
25
|
-
class TaskManagerStore {
|
|
26
|
-
taskUpdater = new
|
|
27
|
-
taskLogUpdater = new
|
|
17
|
+
export class TaskManagerStore {
|
|
18
|
+
taskUpdater = new ObjectUpdater();
|
|
19
|
+
taskLogUpdater = new ObjectUpdater();
|
|
28
20
|
constructor(params) {
|
|
29
21
|
this.context = params.context;
|
|
30
22
|
this.task = params.task;
|
|
31
23
|
this.taskLog = params.log;
|
|
32
|
-
this.
|
|
24
|
+
this.databaseLogs = params.databaseLogs === true;
|
|
33
25
|
}
|
|
34
26
|
getStatus() {
|
|
35
27
|
return this.task.taskStatus;
|
|
@@ -57,7 +49,7 @@ class TaskManagerStore {
|
|
|
57
49
|
/**
|
|
58
50
|
* No need to update if nothing changed.
|
|
59
51
|
*/
|
|
60
|
-
if ((
|
|
52
|
+
if (deepEqual(data, this.task)) {
|
|
61
53
|
return;
|
|
62
54
|
}
|
|
63
55
|
this.taskUpdater.update(data);
|
|
@@ -72,7 +64,7 @@ class TaskManagerStore {
|
|
|
72
64
|
/**
|
|
73
65
|
* No need to update if nothing changed.
|
|
74
66
|
*/
|
|
75
|
-
if ((
|
|
67
|
+
if (deepEqual(input, this.task.input)) {
|
|
76
68
|
return;
|
|
77
69
|
}
|
|
78
70
|
this.taskUpdater.update({
|
|
@@ -103,14 +95,14 @@ class TaskManagerStore {
|
|
|
103
95
|
* TODO: Maybe we should wrap it into try/catch and return error if any?
|
|
104
96
|
*/
|
|
105
97
|
async addInfoLog(log, options) {
|
|
106
|
-
if (this.
|
|
98
|
+
if (!this.databaseLogs) {
|
|
107
99
|
return;
|
|
108
100
|
}
|
|
109
101
|
this.taskLogUpdater.update({
|
|
110
102
|
items: [{
|
|
111
103
|
message: log.message,
|
|
112
104
|
data: log.data,
|
|
113
|
-
type:
|
|
105
|
+
type: TaskLogItemType.INFO,
|
|
114
106
|
createdOn: new Date().toISOString()
|
|
115
107
|
}]
|
|
116
108
|
});
|
|
@@ -124,7 +116,7 @@ class TaskManagerStore {
|
|
|
124
116
|
* TODO: Maybe we should wrap it into try/catch and return error if any?
|
|
125
117
|
*/
|
|
126
118
|
async addErrorLog(log, options) {
|
|
127
|
-
if (this.
|
|
119
|
+
if (!this.databaseLogs) {
|
|
128
120
|
return;
|
|
129
121
|
}
|
|
130
122
|
/**
|
|
@@ -137,8 +129,8 @@ class TaskManagerStore {
|
|
|
137
129
|
this.taskLogUpdater.update({
|
|
138
130
|
items: [{
|
|
139
131
|
message: log.message,
|
|
140
|
-
error: log.error instanceof Error ?
|
|
141
|
-
type:
|
|
132
|
+
error: log.error instanceof Error ? getObjectProperties(log.error) : log.error,
|
|
133
|
+
type: TaskLogItemType.ERROR,
|
|
142
134
|
createdOn: new Date().toISOString()
|
|
143
135
|
}]
|
|
144
136
|
});
|
|
@@ -154,7 +146,7 @@ class TaskManagerStore {
|
|
|
154
146
|
if (this.taskUpdater.isDirty()) {
|
|
155
147
|
this.task = await this.context.tasks.updateTask(this.task.id, this.taskUpdater.fetch());
|
|
156
148
|
}
|
|
157
|
-
if (this.
|
|
149
|
+
if (!this.databaseLogs) {
|
|
158
150
|
return;
|
|
159
151
|
}
|
|
160
152
|
if (this.taskLogUpdater.isDirty()) {
|
|
@@ -162,6 +154,5 @@ class TaskManagerStore {
|
|
|
162
154
|
}
|
|
163
155
|
}
|
|
164
156
|
}
|
|
165
|
-
exports.TaskManagerStore = TaskManagerStore;
|
|
166
157
|
|
|
167
158
|
//# sourceMappingURL=TaskManagerStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_types","require","_deepEqual","_interopRequireDefault","_getObjectProperties","_ObjectUpdater","getInput","originalInput","input","TaskManagerStore","taskUpdater","ObjectUpdater","taskLogUpdater","constructor","params","context","task","taskLog","log","disableDatabaseLogs","getStatus","taskStatus","getTask","listChildTasks","definitionId","where","parentId","id","result","tasks","listTasks","sort","limit","items","updateTask","param","options","data","deepEqual","update","save","updateInput","updateOutput","values","output","getOutput","addInfoLog","message","type","TaskLogItemType","INFO","createdOn","Date","toISOString","addErrorLog","console","error","Error","getObjectProperties","ERROR","isDirty","fetch","updateLog","exports"],"sources":["TaskManagerStore.ts"],"sourcesContent":["import type {\n IListTaskParamsWhere,\n ITask,\n ITaskDataInput,\n ITaskLog,\n ITaskManagerStoreInfoLog,\n ITaskManagerStorePrivate,\n ITaskManagerStoreSetOutputOptions,\n ITaskManagerStoreUpdateTaskInputOptions,\n ITaskManagerStoreUpdateTaskOptions,\n ITaskResponseDoneResultOutput,\n ITasksContextObject,\n TaskDataStatus\n} from \"~/types\";\nimport { TaskLogItemType } from \"~/types\";\nimport type {\n ITaskManagerStoreAddLogOptions,\n ITaskManagerStoreErrorLog,\n ITaskManagerStoreUpdateTaskInputParam,\n ITaskManagerStoreUpdateTaskParams\n} from \"./abstractions\";\n/**\n * Package deep-equal does not have types.\n */\nimport deepEqual from \"deep-equal\";\nimport { getObjectProperties } from \"~/utils/getObjectProperties\";\nimport { ObjectUpdater } from \"~/utils/ObjectUpdater\";\nimport type { GenericRecord } from \"@webiny/api/types\";\n\nconst getInput = <T extends ITaskDataInput = ITaskDataInput>(\n originalInput: T,\n input: ITaskManagerStoreUpdateTaskInputParam<T>\n): T => {\n if (typeof input === \"function\") {\n return input(originalInput);\n }\n return {\n ...originalInput,\n ...input\n };\n};\n\nexport interface TaskManagerStoreContext {\n tasks: Pick<ITasksContextObject, \"updateTask\" | \"updateLog\" | \"listTasks\">;\n}\n\nexport interface ITaskManagerStoreParams {\n context: TaskManagerStoreContext;\n task: ITask;\n log: ITaskLog;\n disableDatabaseLogs?: boolean;\n}\n\nexport class TaskManagerStore<\n T extends ITaskDataInput = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> implements ITaskManagerStorePrivate<T, O>\n{\n private readonly context: TaskManagerStoreContext;\n private task: ITask<T, O>;\n private taskLog: ITaskLog;\n private readonly disableDatabaseLogs: boolean;\n\n private readonly taskUpdater = new ObjectUpdater<ITask<T, O>>();\n private readonly taskLogUpdater = new ObjectUpdater<ITaskLog>();\n\n public constructor(params: ITaskManagerStoreParams) {\n this.context = params.context;\n this.task = params.task as ITask<T, O>;\n this.taskLog = params.log;\n this.disableDatabaseLogs = !!params.disableDatabaseLogs;\n }\n\n public getStatus(): TaskDataStatus {\n return this.task.taskStatus;\n }\n\n public getTask(): ITask<T, O> {\n return this.task as ITask<T, O>;\n }\n\n public async listChildTasks<\n I = GenericRecord,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n >(definitionId?: string): Promise<ITask<I, O>[]> {\n const where: IListTaskParamsWhere = {\n parentId: this.task.id\n };\n if (definitionId) {\n where.definitionId = definitionId;\n }\n const result = await this.context.tasks.listTasks<I, O>({\n where,\n sort: [\"createdOn_ASC\"],\n limit: 1000000\n });\n return result.items;\n }\n\n public async updateTask(\n param: ITaskManagerStoreUpdateTaskParams<T, O>,\n options?: ITaskManagerStoreUpdateTaskOptions\n ): Promise<void> {\n const data = typeof param === \"function\" ? param(this.task) : param;\n\n /**\n * No need to update if nothing changed.\n */\n if (deepEqual(data, this.task)) {\n return;\n }\n\n this.taskUpdater.update(data);\n\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public async updateInput(\n param: ITaskManagerStoreUpdateTaskInputParam<T>,\n options?: ITaskManagerStoreUpdateTaskInputOptions\n ): Promise<void> {\n const input = getInput<T>(this.task.input, param);\n\n /**\n * No need to update if nothing changed.\n */\n if (deepEqual(input, this.task.input)) {\n return;\n }\n this.taskUpdater.update({\n input: input as T\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public getInput(): T {\n return this.task.input as T;\n }\n\n public async updateOutput(\n values: Partial<O>,\n options: ITaskManagerStoreSetOutputOptions = {}\n ): Promise<void> {\n this.taskUpdater.update({\n output: values as O\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public getOutput(): O {\n return this.task.output as O;\n }\n /**\n * Currently the methods throws an error if something goes wrong during the database update.\n * TODO: Maybe we should wrap it into try/catch and return error if any?\n */\n public async addInfoLog(\n log: ITaskManagerStoreInfoLog,\n options?: ITaskManagerStoreAddLogOptions\n ): Promise<void> {\n if (this.disableDatabaseLogs) {\n return;\n }\n this.taskLogUpdater.update({\n items: [\n {\n message: log.message,\n data: log.data,\n type: TaskLogItemType.INFO,\n createdOn: new Date().toISOString()\n }\n ]\n });\n if (options?.save === false) {\n return;\n }\n\n await this.save();\n }\n /**\n * Currently the methods throws an error if something goes wrong during the database update.\n * TODO: Maybe we should wrap it into try/catch and return error if any?\n */\n public async addErrorLog(\n log: ITaskManagerStoreErrorLog,\n options?: ITaskManagerStoreAddLogOptions\n ): Promise<void> {\n if (this.disableDatabaseLogs) {\n return;\n }\n /**\n * Let's log the error to the console as well.\n */\n console.error(log.error);\n /**\n * Then update the log object.\n */\n this.taskLogUpdater.update({\n items: [\n {\n message: log.message,\n error: log.error instanceof Error ? getObjectProperties(log.error) : log.error,\n type: TaskLogItemType.ERROR,\n createdOn: new Date().toISOString()\n }\n ]\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public async save(): Promise<void> {\n /**\n * Update both task and the log, if anything to update.\n */\n if (this.taskUpdater.isDirty()) {\n this.task = await this.context.tasks.updateTask<T, O>(\n this.task.id,\n this.taskUpdater.fetch()\n );\n }\n if (this.disableDatabaseLogs) {\n return;\n }\n if (this.taskLogUpdater.isDirty()) {\n this.taskLog = await this.context.tasks.updateLog(\n this.taskLog.id,\n this.taskLogUpdater.fetch()\n );\n }\n }\n}\n"],"mappings":";;;;;;;AAcA,IAAAA,MAAA,GAAAC,OAAA;AAUA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,oBAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AALA;AACA;AACA;;AAMA,MAAMK,QAAQ,GAAGA,CACbC,aAAgB,EAChBC,KAA+C,KAC3C;EACJ,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;IAC7B,OAAOA,KAAK,CAACD,aAAa,CAAC;EAC/B;EACA,OAAO;IACH,GAAGA,aAAa;IAChB,GAAGC;EACP,CAAC;AACL,CAAC;AAaM,MAAMC,gBAAgB,CAI7B;EAMqBC,WAAW,GAAG,IAAIC,4BAAa,CAAc,CAAC;EAC9CC,cAAc,GAAG,IAAID,4BAAa,CAAW,CAAC;EAExDE,WAAWA,CAACC,MAA+B,EAAE;IAChD,IAAI,CAACC,OAAO,GAAGD,MAAM,CAACC,OAAO;IAC7B,IAAI,CAACC,IAAI,GAAGF,MAAM,CAACE,IAAmB;IACtC,IAAI,CAACC,OAAO,GAAGH,MAAM,CAACI,GAAG;IACzB,IAAI,CAACC,mBAAmB,GAAG,CAAC,CAACL,MAAM,CAACK,mBAAmB;EAC3D;EAEOC,SAASA,CAAA,EAAmB;IAC/B,OAAO,IAAI,CAACJ,IAAI,CAACK,UAAU;EAC/B;EAEOC,OAAOA,CAAA,EAAgB;IAC1B,OAAO,IAAI,CAACN,IAAI;EACpB;EAEA,MAAaO,cAAcA,CAGzBC,YAAqB,EAA0B;IAC7C,MAAMC,KAA2B,GAAG;MAChCC,QAAQ,EAAE,IAAI,CAACV,IAAI,CAACW;IACxB,CAAC;IACD,IAAIH,YAAY,EAAE;MACdC,KAAK,CAACD,YAAY,G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,EAACxC,GAAG,CAACsC,KAAK,CAAC,GAAGtC,GAAG,CAACsC,KAAK;QAC9ER,IAAI,EAAEC,sBAAe,CAACU,KAAK;QAC3BR,SAAS,EAAE,IAAIC,IAAI,CAAC,CAAC,CAACC,WAAW,CAAC;MACtC,CAAC;IAET,CAAC,CAAC;IACF,IAAIjB,OAAO,EAAEI,IAAI,KAAK,KAAK,EAAE;MACzB;IACJ;IACA,MAAM,IAAI,CAACA,IAAI,CAAC,CAAC;EACrB;EAEA,MAAaA,IAAIA,CAAA,EAAkB;IAC/B;AACR;AACA;IACQ,IAAI,IAAI,CAAC9B,WAAW,CAACkD,OAAO,CAAC,CAAC,EAAE;MAC5B,IAAI,CAAC5C,IAAI,GAAG,MAAM,IAAI,CAACD,OAAO,CAACc,KAAK,CAACK,UAAU,CAC3C,IAAI,CAAClB,IAAI,CAACW,EAAE,EACZ,IAAI,CAACjB,WAAW,CAACmD,KAAK,CAAC,CAC3B,CAAC;IACL;IACA,IAAI,IAAI,CAAC1C,mBAAmB,EAAE;MAC1B;IACJ;IACA,IAAI,IAAI,CAACP,cAAc,CAACgD,OAAO,CAAC,CAAC,EAAE;MAC/B,IAAI,CAAC3C,OAAO,GAAG,MAAM,IAAI,CAACF,OAAO,CAACc,KAAK,CAACiC,SAAS,CAC7C,IAAI,CAAC7C,OAAO,CAACU,EAAE,EACf,IAAI,CAACf,cAAc,CAACiD,KAAK,CAAC,CAC9B,CAAC;IACL;EACJ;AACJ;AAACE,OAAA,CAAAtD,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["TaskLogItemType","deepEqual","getObjectProperties","ObjectUpdater","getInput","originalInput","input","TaskManagerStore","taskUpdater","taskLogUpdater","constructor","params","context","task","taskLog","log","databaseLogs","getStatus","taskStatus","getTask","listChildTasks","definitionId","where","parentId","id","result","tasks","listTasks","sort","limit","items","updateTask","param","options","data","update","save","updateInput","updateOutput","values","output","getOutput","addInfoLog","message","type","INFO","createdOn","Date","toISOString","addErrorLog","console","error","Error","ERROR","isDirty","fetch","updateLog"],"sources":["TaskManagerStore.ts"],"sourcesContent":["import type {\n IListTaskParamsWhere,\n ITask,\n ITaskDataInput,\n ITaskLog,\n ITaskManagerStoreInfoLog,\n ITaskManagerStorePrivate,\n ITaskManagerStoreSetOutputOptions,\n ITaskManagerStoreUpdateTaskInputOptions,\n ITaskManagerStoreUpdateTaskOptions,\n ITasksContextObject,\n TaskDataStatus\n} from \"~/types.js\";\nimport { TaskLogItemType } from \"~/types.js\";\nimport type {\n ITaskManagerStoreAddLogOptions,\n ITaskManagerStoreErrorLog,\n ITaskManagerStoreUpdateTaskInputParam,\n ITaskManagerStoreUpdateTaskParams\n} from \"./abstractions/index.js\";\n/**\n * Package deep-equal does not have types.\n */\nimport deepEqual from \"deep-equal\";\nimport { getObjectProperties } from \"~/utils/getObjectProperties.js\";\nimport { ObjectUpdater } from \"~/utils/ObjectUpdater.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\n\nconst getInput = <T extends ITaskDataInput = ITaskDataInput>(\n originalInput: T,\n input: ITaskManagerStoreUpdateTaskInputParam<T>\n): T => {\n if (typeof input === \"function\") {\n return input(originalInput);\n }\n return {\n ...originalInput,\n ...input\n };\n};\n\nexport interface TaskManagerStoreContext {\n tasks: Pick<ITasksContextObject, \"updateTask\" | \"updateLog\" | \"listTasks\">;\n}\n\nexport interface ITaskManagerStoreParams {\n context: TaskManagerStoreContext;\n task: ITask;\n log: ITaskLog;\n databaseLogs: boolean;\n}\n\nexport class TaskManagerStore<\n T extends ITaskDataInput = ITaskDataInput,\n O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput\n> implements ITaskManagerStorePrivate<T, O>\n{\n private readonly context: TaskManagerStoreContext;\n private task: ITask<T, O>;\n private taskLog: ITaskLog;\n private readonly databaseLogs: boolean;\n\n private readonly taskUpdater = new ObjectUpdater<ITask<T, O>>();\n private readonly taskLogUpdater = new ObjectUpdater<ITaskLog>();\n\n public constructor(params: ITaskManagerStoreParams) {\n this.context = params.context;\n this.task = params.task as ITask<T, O>;\n this.taskLog = params.log;\n this.databaseLogs = params.databaseLogs === true;\n }\n\n public getStatus(): TaskDataStatus {\n return this.task.taskStatus;\n }\n\n public getTask(): ITask<T, O> {\n return this.task as ITask<T, O>;\n }\n\n public async listChildTasks<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput\n >(definitionId?: string): Promise<ITask<I, O>[]> {\n const where: IListTaskParamsWhere = {\n parentId: this.task.id\n };\n if (definitionId) {\n where.definitionId = definitionId;\n }\n const result = await this.context.tasks.listTasks<I, O>({\n where,\n sort: [\"createdOn_ASC\"],\n limit: 1000000\n });\n return result.items;\n }\n\n public async updateTask(\n param: ITaskManagerStoreUpdateTaskParams<T, O>,\n options?: ITaskManagerStoreUpdateTaskOptions\n ): Promise<void> {\n const data = typeof param === \"function\" ? param(this.task) : param;\n\n /**\n * No need to update if nothing changed.\n */\n if (deepEqual(data, this.task)) {\n return;\n }\n\n this.taskUpdater.update(data);\n\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public async updateInput(\n param: ITaskManagerStoreUpdateTaskInputParam<T>,\n options?: ITaskManagerStoreUpdateTaskInputOptions\n ): Promise<void> {\n const input = getInput<T>(this.task.input, param);\n\n /**\n * No need to update if nothing changed.\n */\n if (deepEqual(input, this.task.input)) {\n return;\n }\n this.taskUpdater.update({\n input: input as T\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public getInput(): T {\n return this.task.input as T;\n }\n\n public async updateOutput(\n values: Partial<O>,\n options: ITaskManagerStoreSetOutputOptions = {}\n ): Promise<void> {\n this.taskUpdater.update({\n output: values as O\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public getOutput(): O {\n return this.task.output as O;\n }\n /**\n * Currently the methods throws an error if something goes wrong during the database update.\n * TODO: Maybe we should wrap it into try/catch and return error if any?\n */\n public async addInfoLog(\n log: ITaskManagerStoreInfoLog,\n options?: ITaskManagerStoreAddLogOptions\n ): Promise<void> {\n if (!this.databaseLogs) {\n return;\n }\n this.taskLogUpdater.update({\n items: [\n {\n message: log.message,\n data: log.data,\n type: TaskLogItemType.INFO,\n createdOn: new Date().toISOString()\n }\n ]\n });\n if (options?.save === false) {\n return;\n }\n\n await this.save();\n }\n /**\n * Currently the methods throws an error if something goes wrong during the database update.\n * TODO: Maybe we should wrap it into try/catch and return error if any?\n */\n public async addErrorLog(\n log: ITaskManagerStoreErrorLog,\n options?: ITaskManagerStoreAddLogOptions\n ): Promise<void> {\n if (!this.databaseLogs) {\n return;\n }\n /**\n * Let's log the error to the console as well.\n */\n console.error(log.error);\n /**\n * Then update the log object.\n */\n this.taskLogUpdater.update({\n items: [\n {\n message: log.message,\n error: log.error instanceof Error ? getObjectProperties(log.error) : log.error,\n type: TaskLogItemType.ERROR,\n createdOn: new Date().toISOString()\n }\n ]\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public async save(): Promise<void> {\n /**\n * Update both task and the log, if anything to update.\n */\n if (this.taskUpdater.isDirty()) {\n this.task = await this.context.tasks.updateTask<T, O>(\n this.task.id,\n this.taskUpdater.fetch()\n );\n }\n if (!this.databaseLogs) {\n return;\n }\n if (this.taskLogUpdater.isDirty()) {\n this.taskLog = await this.context.tasks.updateLog(\n this.taskLog.id,\n this.taskLogUpdater.fetch()\n );\n }\n }\n}\n"],"mappings":"AAaA,SAASA,eAAe;AAOxB;AACA;AACA;AACA,OAAOC,SAAS,MAAM,YAAY;AAClC,SAASC,mBAAmB;AAC5B,SAASC,aAAa;AAGtB,MAAMC,QAAQ,GAAGA,CACbC,aAAgB,EAChBC,KAA+C,KAC3C;EACJ,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;IAC7B,OAAOA,KAAK,CAACD,aAAa,CAAC;EAC/B;EACA,OAAO;IACH,GAAGA,aAAa;IAChB,GAAGC;EACP,CAAC;A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,EACZ,IAAI,CAAChB,WAAW,CAAC+C,KAAK,CAAC,CAC3B,CAAC;IACL;IACA,IAAI,CAAC,IAAI,CAACvC,YAAY,EAAE;MACpB;IACJ;IACA,IAAI,IAAI,CAACP,cAAc,CAAC6C,OAAO,CAAC,CAAC,EAAE;MAC/B,IAAI,CAACxC,OAAO,GAAG,MAAM,IAAI,CAACF,OAAO,CAACc,KAAK,CAAC8B,SAAS,CAC7C,IAAI,CAAC1C,OAAO,CAACU,EAAE,EACf,IAAI,CAACf,cAAc,CAAC8C,KAAK,CAAC,CAC9B,CAAC;IACL;EACJ;AACJ","ignoreList":[]}
|
package/runner/TaskRunner.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ITaskRawEvent } from "../handler/types";
|
|
2
|
-
import type { ITaskEventValidation, ITaskRunner } from "./abstractions";
|
|
3
|
-
import type { Context } from "../types";
|
|
4
|
-
import type { IResponseResult } from "../response/abstractions";
|
|
5
|
-
import type { ITimer } from "@webiny/handler-aws/utils";
|
|
1
|
+
import type { ITaskRawEvent } from "../handler/types.js";
|
|
2
|
+
import type { ITaskEventValidation, ITaskRunner } from "./abstractions/index.js";
|
|
3
|
+
import type { Context } from "../types.js";
|
|
4
|
+
import type { IResponseResult } from "../response/abstractions/index.js";
|
|
5
|
+
import type { ITimer } from "@webiny/handler-aws/utils/index.js";
|
|
6
6
|
export declare class TaskRunner<C extends Context = Context> implements ITaskRunner<C> {
|
|
7
7
|
/**
|
|
8
8
|
* When DI is introduced, these will get injected.
|
|
@@ -22,5 +22,4 @@ export declare class TaskRunner<C extends Context = Context> implements ITaskRun
|
|
|
22
22
|
isCloseToTimeout(seconds?: number): boolean;
|
|
23
23
|
run(rawEvent: ITaskRawEvent): Promise<IResponseResult>;
|
|
24
24
|
private getIsCloseToTimeoutMilliseconds;
|
|
25
|
-
private setLocale;
|
|
26
25
|
}
|
package/runner/TaskRunner.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.TaskRunner = void 0;
|
|
7
|
-
var _response = require("../response");
|
|
8
|
-
var _TaskControl = require("./TaskControl");
|
|
9
|
-
var _getErrorProperties = require("../utils/getErrorProperties");
|
|
1
|
+
import { Response, ResponseErrorResult } from "../response/index.js";
|
|
2
|
+
import { TaskControl } from "./TaskControl.js";
|
|
3
|
+
import { getErrorProperties } from "../utils/getErrorProperties.js";
|
|
10
4
|
const transformMinutesIntoMilliseconds = minutes => {
|
|
11
5
|
return minutes * 60000;
|
|
12
6
|
};
|
|
13
7
|
const DEFAULT_TASKS_TIMEOUT_CLOSE_MINUTES = 3;
|
|
14
|
-
class TaskRunner {
|
|
8
|
+
export class TaskRunner {
|
|
15
9
|
/**
|
|
16
10
|
* When DI is introduced, these will get injected.
|
|
17
11
|
*
|
|
@@ -34,7 +28,7 @@ class TaskRunner {
|
|
|
34
28
|
return this.timer.getRemainingMilliseconds() < milliseconds;
|
|
35
29
|
}
|
|
36
30
|
async run(rawEvent) {
|
|
37
|
-
const response = new
|
|
31
|
+
const response = new Response({
|
|
38
32
|
...rawEvent
|
|
39
33
|
});
|
|
40
34
|
let event;
|
|
@@ -42,7 +36,7 @@ class TaskRunner {
|
|
|
42
36
|
event = this.validation.validate(rawEvent);
|
|
43
37
|
} catch (ex) {
|
|
44
38
|
return response.error({
|
|
45
|
-
error:
|
|
39
|
+
error: getErrorProperties(ex)
|
|
46
40
|
});
|
|
47
41
|
}
|
|
48
42
|
response.setEvent(event);
|
|
@@ -55,15 +49,10 @@ class TaskRunner {
|
|
|
55
49
|
wait: rawEvent.delay
|
|
56
50
|
});
|
|
57
51
|
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Here we set the context locale, using the value receive from the event.
|
|
61
|
-
*/
|
|
62
|
-
this.setLocale(event);
|
|
63
|
-
const control = new _TaskControl.TaskControl(this, response, this.context);
|
|
52
|
+
const control = new TaskControl(this, response, this.context);
|
|
64
53
|
try {
|
|
65
54
|
const result = await control.run(event);
|
|
66
|
-
if (result instanceof
|
|
55
|
+
if (result instanceof ResponseErrorResult === false) {
|
|
67
56
|
return result;
|
|
68
57
|
}
|
|
69
58
|
console.error(result);
|
|
@@ -72,7 +61,7 @@ class TaskRunner {
|
|
|
72
61
|
console.error(`Failed to execute task "${event.webinyTaskId}".`);
|
|
73
62
|
console.error(ex);
|
|
74
63
|
return response.error({
|
|
75
|
-
error:
|
|
64
|
+
error: getErrorProperties(ex)
|
|
76
65
|
});
|
|
77
66
|
}
|
|
78
67
|
}
|
|
@@ -81,17 +70,6 @@ class TaskRunner {
|
|
|
81
70
|
const result = value > 0 ? value : DEFAULT_TASKS_TIMEOUT_CLOSE_MINUTES;
|
|
82
71
|
return transformMinutesIntoMilliseconds(result);
|
|
83
72
|
}
|
|
84
|
-
setLocale(event) {
|
|
85
|
-
const {
|
|
86
|
-
locale: localeCode
|
|
87
|
-
} = event;
|
|
88
|
-
const locale = this.context.i18n.getLocale(localeCode);
|
|
89
|
-
if (!locale) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
this.context.i18n.setContentLocale(locale);
|
|
93
|
-
}
|
|
94
73
|
}
|
|
95
|
-
exports.TaskRunner = TaskRunner;
|
|
96
74
|
|
|
97
75
|
//# sourceMappingURL=TaskRunner.js.map
|
package/runner/TaskRunner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["Response","ResponseErrorResult","TaskControl","getErrorProperties","transformMinutesIntoMilliseconds","minutes","DEFAULT_TASKS_TIMEOUT_CLOSE_MINUTES","TaskRunner","constructor","context","timer","validation","isCloseToTimeout","seconds","milliseconds","getIsCloseToTimeoutMilliseconds","getRemainingMilliseconds","run","rawEvent","response","event","validate","ex","error","setEvent","delay","continue","input","wait","control","result","console","webinyTaskId","value","parseInt","process","env"],"sources":["TaskRunner.ts"],"sourcesContent":["import type { ITaskEvent, ITaskRawEvent } from \"~/handler/types.js\";\nimport type { ITaskEventValidation, ITaskRunner } from \"./abstractions/index.js\";\nimport type { Context } from \"~/types.js\";\nimport { Response, ResponseErrorResult } from \"~/response/index.js\";\nimport { TaskControl } from \"./TaskControl.js\";\nimport type { IResponseResult } from \"~/response/abstractions/index.js\";\nimport { getErrorProperties } from \"~/utils/getErrorProperties.js\";\nimport type { ITimer } from \"@webiny/handler-aws/utils/index.js\";\n\nconst transformMinutesIntoMilliseconds = (minutes: number) => {\n return minutes * 60000;\n};\n\nconst DEFAULT_TASKS_TIMEOUT_CLOSE_MINUTES = 3;\n\nexport class TaskRunner<C extends Context = Context> implements ITaskRunner<C> {\n /**\n * When DI is introduced, these will get injected.\n *\n * container.bind<Request>(\"Request\").toConstantValue(request);\n * @inject(\"Request\") public readonly request: Request;\n *\n * Follow the same example for the rest of the properties.\n */\n public readonly context: C;\n public readonly timer: ITimer;\n private readonly validation: ITaskEventValidation;\n\n /**\n * We take all required variables separately because they will get injected via DI - so less refactoring is required in the future.\n */\n public constructor(context: C, timer: ITimer, validation: ITaskEventValidation) {\n this.context = context;\n this.timer = timer;\n this.validation = validation;\n }\n\n public isCloseToTimeout(seconds?: number) {\n const milliseconds = seconds ? seconds * 1000 : this.getIsCloseToTimeoutMilliseconds();\n return this.timer.getRemainingMilliseconds() < milliseconds;\n }\n\n public async run(rawEvent: ITaskRawEvent): Promise<IResponseResult> {\n const response = new Response({\n ...rawEvent\n });\n\n let event: ITaskEvent;\n try {\n event = this.validation.validate(rawEvent);\n } catch (ex) {\n return response.error({\n error: getErrorProperties(ex)\n });\n }\n response.setEvent(event);\n /**\n * If we received a delay when initiating the task, we need to send the continue response immediately.\n */\n if (rawEvent.delay && rawEvent.delay > 0) {\n return response.continue({\n input: {},\n wait: rawEvent.delay\n });\n }\n\n const control = new TaskControl(this, response, this.context);\n\n try {\n const result = await control.run(event);\n if (result instanceof ResponseErrorResult === false) {\n return result;\n }\n console.error(result);\n return result;\n } catch (ex) {\n console.error(`Failed to execute task \"${event.webinyTaskId}\".`);\n console.error(ex);\n return response.error({\n error: getErrorProperties(ex)\n });\n }\n }\n\n private getIsCloseToTimeoutMilliseconds() {\n const value = parseInt(process.env[\"WEBINY_TASKS_TIMEOUT_CLOSE_MINUTES\"] || \"\");\n const result = value > 0 ? value : DEFAULT_TASKS_TIMEOUT_CLOSE_MINUTES;\n return transformMinutesIntoMilliseconds(result);\n }\n}\n"],"mappings":"AAGA,SAASA,QAAQ,EAAEC,mBAAmB;AACtC,SAASC,WAAW;AAEpB,SAASC,kBAAkB;AAG3B,MAAMC,gCAAgC,GAAIC,OAAe,IAAK;EAC1D,OAAOA,OAAO,GAAG,KAAK;AAC1B,CAAC;AAED,MAAMC,mCAAmC,GAAG,CAAC;AAE7C,OAAO,MAAMC,UAAU,CAAwD;EAC3E;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;;EAKI;AACJ;AACA;EACWC,WAAWA,CAACC,OAAU,EAAEC,KAAa,EAAEC,UAAgC,EAAE;IAC5E,IAAI,CAACF,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,UAAU,GAAGA,UAAU;EAChC;EAEOC,gBAAgBA,CAACC,OAAgB,EAAE;IACtC,MAAMC,YAAY,GAAGD,OAAO,GAAGA,OAAO,GAAG,IAAI,GAAG,IAAI,CAACE,+BAA+B,CAAC,CAAC;IACtF,OAAO,IAAI,CAACL,KAAK,CAACM,wBAAwB,CAAC,CAAC,GAAGF,YAAY;EAC/D;EAEA,MAAaG,GAAGA,CAACC,QAAuB,EAA4B;IAChE,MAAMC,QAAQ,GAAG,IAAInB,QAAQ,CAAC;MAC1B,GAAGkB;IACP,CAAC,CAAC;IAEF,IAAIE,KAAiB;IACrB,IAAI;MACAA,KAAK,GAAG,IAAI,CAACT,UAAU,CAACU,QAAQ,CAACH,QAAQ,CAAC;IAC9C,CAAC,CAAC,OAAOI,EAAE,EAAE;MACT,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 @@
|
|
|
1
|
-
import type { ITaskRunner } from "
|
|
2
|
-
import type { IResponse, IResponseResult } from "../../response/abstractions";
|
|
3
|
-
import type { Context } from "../../types";
|
|
4
|
-
import type { ITaskEvent } from "../../handler/types";
|
|
1
|
+
import type { ITaskRunner } from "../../runner/abstractions/index.js";
|
|
2
|
+
import type { IResponse, IResponseResult } from "../../response/abstractions/index.js";
|
|
3
|
+
import type { Context } from "../../types.js";
|
|
4
|
+
import type { ITaskEvent } from "../../handler/types.js";
|
|
5
5
|
export interface ITaskControl {
|
|
6
6
|
runner: ITaskRunner;
|
|
7
7
|
response: IResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["TaskControl.ts"],"sourcesContent":["import type { ITaskRunner } from \"~/runner/abstractions\";\nimport type { IResponse, IResponseResult } from \"~/response/abstractions\";\nimport type { Context } from \"~/types\";\nimport type { ITaskEvent } from \"~/handler/types\";\n\nexport interface ITaskControl {\n runner: ITaskRunner;\n response: IResponse;\n context: Context;\n\n run(event: ITaskEvent): Promise<IResponseResult>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["TaskControl.ts"],"sourcesContent":["import type { ITaskRunner } from \"~/runner/abstractions/index.js\";\nimport type { IResponse, IResponseResult } from \"~/response/abstractions/index.js\";\nimport type { Context } from \"~/types.js\";\nimport type { ITaskEvent } from \"~/handler/types.js\";\n\nexport interface ITaskControl {\n runner: ITaskRunner;\n response: IResponse;\n context: Context;\n\n run(event: ITaskEvent): Promise<IResponseResult>;\n}\n"],"mappings":"","ignoreList":[]}
|