@webiny/tasks 0.0.0-unstable.e53eceafb5 → 0.0.0-unstable.e6f0dc8ca7
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 +50 -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/cleanupTaskSubtree.d.ts +8 -0
- package/crud/cleanupTaskSubtree.js +76 -0
- package/crud/cleanupTaskSubtree.js.map +1 -0
- package/crud/crud.tasks.d.ts +1 -1
- package/crud/crud.tasks.js +213 -105
- 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 +32 -0
- package/decorators/RunnableTaskDecorator.js +85 -0
- package/decorators/RunnableTaskDecorator.js.map +1 -0
- package/decorators/SelfCleaningTaskDecorator.d.ts +30 -0
- package/decorators/SelfCleaningTaskDecorator.js +98 -0
- package/decorators/SelfCleaningTaskDecorator.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 +5 -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/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.d.ts +7 -0
- package/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js +10 -0
- package/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js.map +1 -0
- package/features/CleanupTaskSubtree/abstractions.d.ts +7 -0
- package/features/CleanupTaskSubtree/abstractions.js +4 -0
- package/features/CleanupTaskSubtree/abstractions.js.map +1 -0
- package/features/CleanupTaskSubtree/index.d.ts +2 -0
- package/features/CleanupTaskSubtree/index.js +4 -0
- package/features/CleanupTaskSubtree/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 +5 -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 +4 -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 +4 -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 +5 -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 +4 -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 +5 -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 +67 -83
- package/graphql/index.js.map +1 -1
- package/graphql/utils.d.ts +3 -3
- 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 +27 -28
- 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 +41 -214
- package/types.js +7 -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/utils/normalizeSelfCleanup.d.ts +2 -0
- package/utils/normalizeSelfCleanup.js +15 -0
- package/utils/normalizeSelfCleanup.js.map +1 -0
- 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 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["GetTaskDefinitionUseCase","ListTaskDefinitionsUseCase","createDefinitionCrud","context","getDefinition","id","useCase","container","resolve","result","execute","isOk","value","listDefinitions"],"sources":["definition.tasks.ts"],"sourcesContent":["import type { Context, ITasksContextDefinitionObject } from \"~/types.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { GetTaskDefinitionUseCase } from \"~/features/GetTaskDefinition/index.js\";\nimport { ListTaskDefinitionsUseCase } from \"~/features/ListTaskDefinitions/index.js\";\n\nexport const createDefinitionCrud = (context: Context): ITasksContextDefinitionObject => {\n return {\n getDefinition: <\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput\n >(\n id: string\n ) => {\n const useCase = context.container.resolve(GetTaskDefinitionUseCase);\n const result = useCase.execute<I, O>(id);\n\n if (result.isOk()) {\n return result.value;\n }\n\n return null;\n },\n listDefinitions: () => {\n const useCase = context.container.resolve(ListTaskDefinitionsUseCase);\n return useCase.execute();\n }\n };\n};\n"],"mappings":"AAEA,SAASA,wBAAwB;AACjC,SAASC,0BAA0B;AAEnC,OAAO,MAAMC,oBAAoB,GAAIC,OAAgB,IAAoC;EACrF,OAAO;IACHC,aAAa,EAITC,EAAU,IACT;MACD,MAAMC,OAAO,GAAGH,OAAO,CAACI,SAAS,CAACC,OAAO,CAACR,wBAAwB,CAAC;MACnE,MAAMS,MAAM,GAAGH,OAAO,CAACI,OAAO,CAAOL,EAAE,CAAC;MAExC,IAAII,MAAM,CAACE,IAAI,CAAC,CAAC,EAAE;QACf,OAAOF,MAAM,CAACG,KAAK;MACvB;MAEA,OAAO,IAAI;IACf,CAAC;IACDC,eAAe,EAAEA,CAAA,KAAM;MACnB,MAAMP,OAAO,GAAGH,OAAO,CAACI,SAAS,CAACC,OAAO,CAACP,0BAA0B,CAAC;MACrE,OAAOK,OAAO,CAACI,OAAO,CAAC,CAAC;IAC5B;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
|
package/crud/service.tasks.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Context, ITasksContextServiceObject } from "../types";
|
|
1
|
+
import type { Context, ITasksContextServiceObject } from "../types.js";
|
|
2
2
|
export declare const createServiceCrud: (context: Context) => ITasksContextServiceObject;
|
package/crud/service.tasks.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
exports.createServiceCrud = void 0;
|
|
8
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
-
var _types = require("../types");
|
|
10
|
-
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
11
|
-
var _service = require("../service");
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { TaskDataStatus, TaskLogItemType } from "../types.js";
|
|
3
|
+
import { NotFoundError } from "@webiny/handler-graphql";
|
|
4
|
+
import { createService } from "../service/index.js";
|
|
5
|
+
import { Result } from "@webiny/feature/api";
|
|
6
|
+
import { TaskAbortError, TaskDefinitionNotFoundError, TaskNotFoundError, TaskServiceInfoError } from "../domain/errors.js";
|
|
12
7
|
const MAX_DELAY_DAYS = 355;
|
|
13
8
|
const MAX_DELAY_SECONDS = MAX_DELAY_DAYS * 24 * 60 * 60;
|
|
14
9
|
const validateDelay = ({
|
|
@@ -20,13 +15,13 @@ const validateDelay = ({
|
|
|
20
15
|
} else if (delay < MAX_DELAY_SECONDS) {
|
|
21
16
|
return;
|
|
22
17
|
}
|
|
23
|
-
throw new
|
|
18
|
+
throw new WebinyError(`The maximum delay for a task is ${MAX_DELAY_DAYS} days.`, "MAX_DELAY_ERROR", {
|
|
24
19
|
...input,
|
|
25
20
|
delay
|
|
26
21
|
});
|
|
27
22
|
};
|
|
28
|
-
const createServiceCrud = context => {
|
|
29
|
-
const service =
|
|
23
|
+
export const createServiceCrud = context => {
|
|
24
|
+
const service = createService({
|
|
30
25
|
context
|
|
31
26
|
});
|
|
32
27
|
return {
|
|
@@ -40,7 +35,7 @@ const createServiceCrud = context => {
|
|
|
40
35
|
} = params;
|
|
41
36
|
const definition = context.tasks.getDefinition(id);
|
|
42
37
|
if (!definition) {
|
|
43
|
-
throw new
|
|
38
|
+
throw new WebinyError(`Task definition was not found!`, "TASK_DEFINITION_ERROR", {
|
|
44
39
|
id
|
|
45
40
|
});
|
|
46
41
|
}
|
|
@@ -52,7 +47,6 @@ const createServiceCrud = context => {
|
|
|
52
47
|
};
|
|
53
48
|
if (definition.onBeforeTrigger) {
|
|
54
49
|
await definition.onBeforeTrigger({
|
|
55
|
-
context,
|
|
56
50
|
data: input
|
|
57
51
|
});
|
|
58
52
|
}
|
|
@@ -71,7 +65,7 @@ const createServiceCrud = context => {
|
|
|
71
65
|
try {
|
|
72
66
|
result = await service.send(task, delay);
|
|
73
67
|
if (!result) {
|
|
74
|
-
throw new
|
|
68
|
+
throw new WebinyError(`Could not trigger the step function!`, "TRIGGER_STEP_FUNCTION_ERROR", {
|
|
75
69
|
task
|
|
76
70
|
});
|
|
77
71
|
}
|
|
@@ -85,51 +79,54 @@ const createServiceCrud = context => {
|
|
|
85
79
|
await context.tasks.deleteTask(task.id);
|
|
86
80
|
throw ex;
|
|
87
81
|
}
|
|
88
|
-
|
|
82
|
+
const updatedTask = await context.tasks.updateTask(task.id, {
|
|
89
83
|
eventResponse: result
|
|
90
84
|
});
|
|
85
|
+
return Result.ok(updatedTask);
|
|
91
86
|
},
|
|
92
87
|
fetchServiceInfo: async input => {
|
|
93
88
|
const task = typeof input === "object" ? input : await context.tasks.getTask(input);
|
|
94
89
|
if (!task && typeof input === "string") {
|
|
95
|
-
throw new
|
|
90
|
+
throw new NotFoundError(`Task "${input}" was not found!`);
|
|
96
91
|
} else if (!task) {
|
|
97
|
-
throw new
|
|
92
|
+
throw new WebinyError(`Task was not found!`, "TASK_FETCH_ERROR", {
|
|
98
93
|
input
|
|
99
94
|
});
|
|
100
95
|
}
|
|
101
96
|
try {
|
|
102
|
-
|
|
97
|
+
const info = await service.fetch(task);
|
|
98
|
+
if (info) {
|
|
99
|
+
return Result.ok(info);
|
|
100
|
+
}
|
|
101
|
+
return Result.fail(new TaskServiceInfoError());
|
|
103
102
|
} catch (ex) {
|
|
104
103
|
console.log("Service fetch error.");
|
|
105
104
|
console.error(ex);
|
|
106
|
-
return
|
|
105
|
+
return Result.fail(new TaskServiceInfoError());
|
|
107
106
|
}
|
|
108
107
|
},
|
|
109
108
|
abort: async params => {
|
|
110
109
|
const task = await context.tasks.getTask(params.id);
|
|
111
110
|
if (!task) {
|
|
112
|
-
|
|
111
|
+
return Result.fail(new TaskNotFoundError());
|
|
113
112
|
}
|
|
114
113
|
const definition = context.tasks.getDefinition(task.definitionId);
|
|
115
114
|
if (!definition) {
|
|
116
|
-
|
|
117
|
-
id: task.id
|
|
118
|
-
});
|
|
115
|
+
return Result.fail(new TaskDefinitionNotFoundError(task.definitionId));
|
|
119
116
|
}
|
|
120
117
|
/**
|
|
121
118
|
* We should only be able to abort a task which is pending or running
|
|
122
119
|
*/
|
|
123
|
-
if ([
|
|
124
|
-
|
|
120
|
+
if ([TaskDataStatus.PENDING, TaskDataStatus.RUNNING].includes(task.taskStatus) === false) {
|
|
121
|
+
return Result.fail(new TaskAbortError({
|
|
125
122
|
id: params.id,
|
|
126
123
|
status: task.taskStatus
|
|
127
|
-
});
|
|
124
|
+
}));
|
|
128
125
|
}
|
|
129
126
|
let taskLog = null;
|
|
130
127
|
try {
|
|
131
128
|
taskLog = await context.tasks.getLatestLog(task.id);
|
|
132
|
-
} catch
|
|
129
|
+
} catch {}
|
|
133
130
|
if (!taskLog) {
|
|
134
131
|
taskLog = await context.tasks.createLog(task, {
|
|
135
132
|
iteration: 1,
|
|
@@ -138,12 +135,12 @@ const createServiceCrud = context => {
|
|
|
138
135
|
}
|
|
139
136
|
try {
|
|
140
137
|
const updatedTask = await context.tasks.updateTask(task.id, {
|
|
141
|
-
taskStatus:
|
|
138
|
+
taskStatus: TaskDataStatus.ABORTED
|
|
142
139
|
});
|
|
143
140
|
await context.tasks.updateLog(taskLog.id, {
|
|
144
141
|
items: taskLog.items.concat([{
|
|
145
142
|
message: params.message || "Task aborted.",
|
|
146
|
-
type:
|
|
143
|
+
type: TaskLogItemType.INFO,
|
|
147
144
|
createdOn: new Date().toISOString()
|
|
148
145
|
}])
|
|
149
146
|
});
|
|
@@ -152,13 +149,12 @@ const createServiceCrud = context => {
|
|
|
152
149
|
*/
|
|
153
150
|
if (definition.onAbort) {
|
|
154
151
|
await definition.onAbort({
|
|
155
|
-
context,
|
|
156
152
|
task: updatedTask
|
|
157
153
|
});
|
|
158
154
|
}
|
|
159
|
-
return updatedTask;
|
|
155
|
+
return Result.ok(updatedTask);
|
|
160
156
|
} catch (ex) {
|
|
161
|
-
throw new
|
|
157
|
+
throw new WebinyError(`Could not abort the task!`, "TASK_ABORT_ERROR", {
|
|
162
158
|
id: params.id,
|
|
163
159
|
message: ex.message
|
|
164
160
|
});
|
|
@@ -166,6 +162,5 @@ const createServiceCrud = context => {
|
|
|
166
162
|
}
|
|
167
163
|
};
|
|
168
164
|
};
|
|
169
|
-
exports.createServiceCrud = createServiceCrud;
|
|
170
165
|
|
|
171
166
|
//# sourceMappingURL=service.tasks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_error","_interopRequireDefault","require","_types","_handlerGraphql","_service","MAX_DELAY_DAYS","MAX_DELAY_SECONDS","validateDelay","input","delay","Number","isInteger","WebinyError","createServiceCrud","context","service","createService","trigger","params","definition","id","inputValues","name","parent","tasks","getDefinition","title","definitionId","parentId","onBeforeTrigger","data","task","createTask","ex","console","log","result","send","error","deleteTask","updateTask","eventResponse","fetchServiceInfo","getTask","NotFoundError","fetch","abort","TaskDataStatus","PENDING","RUNNING","includes","taskStatus","status","taskLog","getLatestLog","createLog","iteration","executionName","updatedTask","ABORTED","updateLog","items","concat","message","type","TaskLogItemType","INFO","createdOn","Date","toISOString","onAbort","exports"],"sources":["service.tasks.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n Context,\n ITask,\n ITaskAbortParams,\n ITaskCreateData,\n ITaskDataInput,\n ITaskLog,\n ITaskResponseDoneResultOutput,\n ITasksContextServiceObject,\n ITaskTriggerParams\n} from \"~/types\";\nimport { TaskDataStatus, TaskLogItemType } from \"~/types\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { createService } from \"~/service\";\nimport type { IStepFunctionServiceFetchResult } from \"~/service/StepFunctionServicePlugin\";\n\nconst MAX_DELAY_DAYS = 355;\nconst MAX_DELAY_SECONDS = MAX_DELAY_DAYS * 24 * 60 * 60;\n\ninterface ValidateDelayParams<T> {\n input: ITaskCreateData<T>;\n delay?: number;\n}\n\nconst validateDelay = <T = ITaskDataInput>({ input, delay }: ValidateDelayParams<T>): void => {\n if (!delay || delay < 0 || typeof delay !== \"number\" || Number.isInteger(delay) === false) {\n return;\n } else if (delay < MAX_DELAY_SECONDS) {\n return;\n }\n throw new WebinyError(\n `The maximum delay for a task is ${MAX_DELAY_DAYS} days.`,\n \"MAX_DELAY_ERROR\",\n {\n ...input,\n delay\n }\n );\n};\n\nexport const createServiceCrud = (context: Context): ITasksContextServiceObject => {\n const service = createService({\n context\n });\n\n return {\n trigger: async <\n T = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n >(\n params: ITaskTriggerParams<T>\n ): Promise<ITask<T, O>> => {\n const { definition: id, input: inputValues, name, parent, delay = 0 } = params;\n const definition = context.tasks.getDefinition(id);\n if (!definition) {\n throw new WebinyError(`Task definition was not found!`, \"TASK_DEFINITION_ERROR\", {\n id\n });\n }\n const input: ITaskCreateData<T> = {\n name: name || definition.title,\n definitionId: id,\n input: inputValues || ({} as T),\n parentId: parent?.id\n };\n if (definition.onBeforeTrigger) {\n await definition.onBeforeTrigger<T>({\n context,\n data: input\n });\n }\n validateDelay<T>({\n input,\n delay\n });\n\n let task: ITask<T>;\n try {\n task = await context.tasks.createTask<T>(input);\n } catch (ex) {\n console.log(\"Could not create the task.\", ex);\n throw ex;\n }\n\n let result: Awaited<ReturnType<typeof service.send>> | null = null;\n try {\n result = await service.send(task, delay);\n\n if (!result) {\n throw new WebinyError(\n `Could not trigger the step function!`,\n \"TRIGGER_STEP_FUNCTION_ERROR\",\n {\n task\n }\n );\n }\n } catch (ex) {\n console.log(\"Could not trigger the step function.\");\n console.error(ex);\n /**\n * In case of failure to create the Event Bridge Event, we need to delete the task that was meant to be created.\n * TODO maybe we can leave the task and update it as failed - with event bridge error?\n */\n await context.tasks.deleteTask(task.id);\n throw ex;\n }\n return await context.tasks.updateTask<T, O>(task.id, {\n eventResponse: result\n });\n },\n fetchServiceInfo: async (\n input: ITask | string\n ): Promise<IStepFunctionServiceFetchResult | null> => {\n const task = typeof input === \"object\" ? input : await context.tasks.getTask(input);\n if (!task && typeof input === \"string\") {\n throw new NotFoundError(`Task \"${input}\" was not found!`);\n } else if (!task) {\n throw new WebinyError(`Task was not found!`, \"TASK_FETCH_ERROR\", {\n input\n });\n }\n\n try {\n return (await service.fetch(task)) as IStepFunctionServiceFetchResult | null;\n } catch (ex) {\n console.log(\"Service fetch error.\");\n console.error(ex);\n return null;\n }\n },\n abort: async <\n T = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n >(\n params: ITaskAbortParams\n ): Promise<ITask<T, O>> => {\n const task = await context.tasks.getTask<T, O>(params.id);\n if (!task) {\n throw new NotFoundError(`Task \"${params.id}\" was not found!`);\n }\n\n const definition = context.tasks.getDefinition<Context, T, O>(task.definitionId);\n if (!definition) {\n throw new WebinyError(`Task definition was not found!`, \"TASK_DEFINITION_ERROR\", {\n id: task.id\n });\n }\n /**\n * We should only be able to abort a task which is pending or running\n */\n if (\n [TaskDataStatus.PENDING, TaskDataStatus.RUNNING].includes(task.taskStatus) === false\n ) {\n throw new WebinyError(\n `Cannot abort a task that is not pending or running!`,\n \"TASK_ABORT_ERROR\",\n {\n id: params.id,\n status: task.taskStatus\n }\n );\n }\n let taskLog: ITaskLog | null = null;\n try {\n taskLog = await context.tasks.getLatestLog(task.id);\n } catch (ex) {}\n if (!taskLog) {\n taskLog = await context.tasks.createLog(task, {\n iteration: 1,\n executionName: task.executionName\n });\n }\n try {\n const updatedTask = await context.tasks.updateTask<T, O>(task.id, {\n taskStatus: TaskDataStatus.ABORTED\n });\n await context.tasks.updateLog(taskLog.id, {\n items: taskLog.items.concat([\n {\n message: params.message || \"Task aborted.\",\n type: TaskLogItemType.INFO,\n createdOn: new Date().toISOString()\n }\n ])\n });\n /**\n * TODO: determine when to kick off the onAbort hook\n */\n if (definition.onAbort) {\n await definition.onAbort({\n context,\n task: updatedTask\n });\n }\n\n return updatedTask;\n } catch (ex) {\n throw new WebinyError(`Could not abort the task!`, \"TASK_ABORT_ERROR\", {\n id: params.id,\n message: ex.message\n });\n }\n }\n };\n};\n"],"m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EAAE,EAAE;QACT,MAAM,IAAIrB,cAAW,CAAC,2BAA2B,EAAE,kBAAkB,EAAE;UACnEQ,EAAE,EAAEF,MAAM,CAACE,EAAE;UACb2C,OAAO,EAAE9B,EAAE,CAAC8B;QAChB,CAAC,CAAC;MACN;IACJ;EACJ,CAAC;AACL,CAAC;AAACQ,OAAA,CAAA1D,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["WebinyError","TaskDataStatus","TaskLogItemType","NotFoundError","createService","Result","TaskAbortError","TaskDefinitionNotFoundError","TaskNotFoundError","TaskServiceInfoError","MAX_DELAY_DAYS","MAX_DELAY_SECONDS","validateDelay","input","delay","Number","isInteger","createServiceCrud","context","service","trigger","params","definition","id","inputValues","name","parent","tasks","getDefinition","title","definitionId","parentId","onBeforeTrigger","data","task","createTask","ex","console","log","result","send","error","deleteTask","updatedTask","updateTask","eventResponse","ok","fetchServiceInfo","getTask","info","fetch","fail","abort","PENDING","RUNNING","includes","taskStatus","status","taskLog","getLatestLog","createLog","iteration","executionName","ABORTED","updateLog","items","concat","message","type","INFO","createdOn","Date","toISOString","onAbort"],"sources":["service.tasks.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n Context,\n ITaskAbortParams,\n ITaskCreateData,\n ITaskLog,\n ITasksContextServiceObject,\n ITaskTriggerParams\n} from \"~/types.js\";\nimport { TaskDataStatus, TaskLogItemType } from \"~/types.js\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { createService } from \"~/service/index.js\";\nimport type { IStepFunctionServiceFetchResult } from \"~/service/StepFunctionServicePlugin.js\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { BaseError, Result } from \"@webiny/feature/api\";\nimport {\n TaskAbortError,\n TaskDefinitionNotFoundError,\n TaskNotFoundError,\n TaskServiceInfoError\n} from \"~/domain/errors.js\";\n\nconst MAX_DELAY_DAYS = 355;\nconst MAX_DELAY_SECONDS = MAX_DELAY_DAYS * 24 * 60 * 60;\n\ninterface ValidateDelayParams<T extends TaskService.TaskInput> {\n input: ITaskCreateData<T>;\n delay?: number;\n}\n\nconst validateDelay = <T extends TaskService.TaskInput = TaskService.TaskInput>({\n input,\n delay\n}: ValidateDelayParams<T>): void => {\n if (!delay || delay < 0 || typeof delay !== \"number\" || Number.isInteger(delay) === false) {\n return;\n } else if (delay < MAX_DELAY_SECONDS) {\n return;\n }\n throw new WebinyError(\n `The maximum delay for a task is ${MAX_DELAY_DAYS} days.`,\n \"MAX_DELAY_ERROR\",\n {\n ...input,\n delay\n }\n );\n};\n\nexport const createServiceCrud = (context: Context): ITasksContextServiceObject => {\n const service = createService({\n context\n });\n\n return {\n trigger: async <\n T extends TaskService.TaskInput = TaskService.TaskInput,\n O extends TaskService.GenericOutput = TaskService.GenericOutput\n >(\n params: ITaskTriggerParams<T>\n ): Promise<Result<TaskService.Task<T, O>, BaseError>> => {\n const { definition: id, input: inputValues, name, parent, delay = 0 } = params;\n const definition = context.tasks.getDefinition(id);\n if (!definition) {\n throw new WebinyError(`Task definition was not found!`, \"TASK_DEFINITION_ERROR\", {\n id\n });\n }\n const input: TaskDefinition.TaskCreateData<T> = {\n name: name || definition.title,\n definitionId: id,\n input: inputValues || ({} as T),\n parentId: parent?.id\n };\n\n if (definition.onBeforeTrigger) {\n await definition.onBeforeTrigger({ data: input });\n }\n validateDelay<T>({\n input,\n delay\n });\n\n let task: TaskService.Task<T>;\n try {\n task = await context.tasks.createTask<T>(input);\n } catch (ex) {\n console.log(\"Could not create the task.\", ex);\n throw ex;\n }\n\n let result: Awaited<ReturnType<typeof service.send>> | null = null;\n try {\n result = await service.send(task, delay);\n\n if (!result) {\n throw new WebinyError(\n `Could not trigger the step function!`,\n \"TRIGGER_STEP_FUNCTION_ERROR\",\n {\n task\n }\n );\n }\n } catch (ex) {\n console.log(\"Could not trigger the step function.\");\n console.error(ex);\n /**\n * In case of failure to create the Event Bridge Event, we need to delete the task that was meant to be created.\n * TODO maybe we can leave the task and update it as failed - with event bridge error?\n */\n await context.tasks.deleteTask(task.id);\n throw ex;\n }\n\n const updatedTask = await context.tasks.updateTask<T, O>(task.id, {\n eventResponse: result\n });\n\n return Result.ok(updatedTask);\n },\n fetchServiceInfo: async (\n input: TaskService.Task | string\n ): Promise<Result<IStepFunctionServiceFetchResult, BaseError<any>>> => {\n const task = typeof input === \"object\" ? input : await context.tasks.getTask(input);\n if (!task && typeof input === \"string\") {\n throw new NotFoundError(`Task \"${input}\" was not found!`);\n } else if (!task) {\n throw new WebinyError(`Task was not found!`, \"TASK_FETCH_ERROR\", {\n input\n });\n }\n\n try {\n const info = (await service.fetch(task)) as IStepFunctionServiceFetchResult | null;\n if (info) {\n return Result.ok(info);\n }\n\n return Result.fail(new TaskServiceInfoError());\n } catch (ex) {\n console.log(\"Service fetch error.\");\n console.error(ex);\n return Result.fail(new TaskServiceInfoError());\n }\n },\n abort: async <\n T extends TaskService.TaskInput = TaskService.TaskInput,\n O extends TaskService.GenericOutput = TaskService.GenericOutput\n >(\n params: ITaskAbortParams\n ): Promise<Result<TaskService.Task<T, O>, BaseError<any>>> => {\n const task = await context.tasks.getTask<T, O>(params.id);\n if (!task) {\n return Result.fail(new TaskNotFoundError());\n }\n\n const definition = context.tasks.getDefinition<T, O>(task.definitionId);\n if (!definition) {\n return Result.fail(new TaskDefinitionNotFoundError(task.definitionId));\n }\n /**\n * We should only be able to abort a task which is pending or running\n */\n if (\n [TaskDataStatus.PENDING, TaskDataStatus.RUNNING].includes(task.taskStatus) === false\n ) {\n return Result.fail(\n new TaskAbortError({\n id: params.id,\n status: task.taskStatus\n })\n );\n }\n let taskLog: ITaskLog | null = null;\n try {\n taskLog = await context.tasks.getLatestLog(task.id);\n } catch {}\n if (!taskLog) {\n taskLog = await context.tasks.createLog(task, {\n iteration: 1,\n executionName: task.executionName\n });\n }\n try {\n const updatedTask = await context.tasks.updateTask<T, O>(task.id, {\n taskStatus: TaskDataStatus.ABORTED\n });\n await context.tasks.updateLog(taskLog.id, {\n items: taskLog.items.concat([\n {\n message: params.message || \"Task aborted.\",\n type: TaskLogItemType.INFO,\n createdOn: new Date().toISOString()\n }\n ])\n });\n /**\n * TODO: determine when to kick off the onAbort hook\n */\n if (definition.onAbort) {\n await definition.onAbort({\n task: updatedTask\n });\n }\n\n return Result.ok(updatedTask);\n } catch (ex) {\n throw new WebinyError(`Could not abort the task!`, \"TASK_ABORT_ERROR\", {\n id: params.id,\n message: ex.message\n });\n }\n }\n };\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AASvC,SAASC,cAAc,EAAEC,eAAe;AACxC,SAASC,aAAa,QAAQ,yBAAyB;AACvD,SAASC,aAAa;AAItB,SAAoBC,MAAM,QAAQ,qBAAqB;AACvD,SACIC,cAAc,EACdC,2BAA2B,EAC3BC,iBAAiB,EACjBC,oBAAoB;AAGxB,MAAMC,cAAc,GAAG,GAAG;AAC1B,MAAMC,iBAAiB,GAAGD,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;AAOvD,MAAME,aAAa,GAAGA,CAA0D;EAC5EC,KAAK;EACLC;AACoB,CAAC,KAAW;EAChC,IAAI,CAACA,KAAK,IAAIA,KAAK,GAAG,CAAC,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIC,MAAM,CAACC,SAAS,CAACF,KAAK,CAAC,KAAK,KAAK,EAAE;IACvF;EACJ,CAAC,MAAM,IAAIA,KAAK,GAAGH,iBAAiB,EAAE;IAClC;EACJ;EACA,MAAM,IAAIX,WAAW,CACjB,mCAAmCU,cAAc,QAAQ,EACzD,iBAAiB,EACjB;IACI,GAAGG,KAAK;IACRC;EACJ,CACJ,CAAC;AACL,CAAC;AAED,OAAO,MAAMG,iBAAiB,GAAIC,OAAgB,IAAiC;EAC/E,MAAMC,OAAO,GAAGf,aAAa,CAAC;IAC1Bc;EACJ,CAAC,CAAC;EAEF,OAAO;IACHE,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AC;MACN;MACA,IAAI;QACA,MAAMnB,WAAW,GAAG,MAAMzB,OAAO,CAACS,KAAK,CAACiB,UAAU,CAAOV,IAAI,CAACX,EAAE,EAAE;UAC9DiC,UAAU,EAAEvD,cAAc,CAAC8D;QAC/B,CAAC,CAAC;QACF,MAAM7C,OAAO,CAACS,KAAK,CAACqC,SAAS,CAACN,OAAO,CAACnC,EAAE,EAAE;UACtC0C,KAAK,EAAEP,OAAO,CAACO,KAAK,CAACC,MAAM,CAAC,CACxB;YACIC,OAAO,EAAE9C,MAAM,CAAC8C,OAAO,IAAI,eAAe;YAC1CC,IAAI,EAAElE,eAAe,CAACmE,IAAI;YAC1BC,SAAS,EAAE,IAAIC,IAAI,CAAC,CAAC,CAACC,WAAW,CAAC;UACtC,CAAC,CACJ;QACL,CAAC,CAAC;QACF;AAChB;AACA;QACgB,IAAIlD,UAAU,CAACmD,OAAO,EAAE;UACpB,MAAMnD,UAAU,CAACmD,OAAO,CAAC;YACrBvC,IAAI,EAAES;UACV,CAAC,CAAC;QACN;QAEA,OAAOtC,MAAM,CAACyC,EAAE,CAACH,WAAW,CAAC;MACjC,CAAC,CAAC,OAAOP,EAAE,EAAE;QACT,MAAM,IAAIpC,WAAW,CAAC,2BAA2B,EAAE,kBAAkB,EAAE;UACnEuB,EAAE,EAAEF,MAAM,CAACE,EAAE;UACb4C,OAAO,EAAE/B,EAAE,CAAC+B;QAChB,CAAC,CAAC;MACN;IACJ;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
2
|
+
import type { ITaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* RunnableTaskDecorator adds runtime behavior to TaskDefinition:
|
|
5
|
+
* - Applies default values (maxIterations, isPrivate, databaseLogs, fields)
|
|
6
|
+
* - Validates task ID (must be camelCase)
|
|
7
|
+
* - Provides field management methods
|
|
8
|
+
*/
|
|
9
|
+
declare class RunnableTaskDecoratorImpl implements TaskDefinition.Interface {
|
|
10
|
+
private decoratee;
|
|
11
|
+
constructor(decoratee: TaskDefinition.Interface);
|
|
12
|
+
get id(): string;
|
|
13
|
+
get title(): string;
|
|
14
|
+
get description(): string | undefined;
|
|
15
|
+
get isPrivate(): boolean;
|
|
16
|
+
get databaseLogs(): boolean;
|
|
17
|
+
get maxIterations(): number;
|
|
18
|
+
get selfCleanup(): import("@webiny/api-core/features/task/TaskDefinition/abstractions").ISelfCleanup | undefined;
|
|
19
|
+
get createInputValidation(): ((params: import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskCreateInputValidationParams) => import("zod").ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>> | import("@webiny/api/types").GenericRecord<PropertyKey, import("zod").ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>) | undefined;
|
|
20
|
+
get run(): (params: import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskRunParams<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>) => Promise<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskResult<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>>;
|
|
21
|
+
get onBeforeTrigger(): ((params: import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskBeforeTriggerParams<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput>) => Promise<void>) | undefined;
|
|
22
|
+
get onDone(): ((params: import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskLifecycleHook<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>) => Promise<void>) | undefined;
|
|
23
|
+
get onError(): ((params: import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskLifecycleHook<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>) => Promise<void>) | undefined;
|
|
24
|
+
get onAbort(): ((params: import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskLifecycleHook<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>) => Promise<void>) | undefined;
|
|
25
|
+
get onMaxIterations(): ((params: import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskLifecycleHook<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>) => Promise<void>) | undefined;
|
|
26
|
+
private validate;
|
|
27
|
+
getTask(): ITaskDefinition;
|
|
28
|
+
}
|
|
29
|
+
export declare const RunnableTaskDecorator: typeof RunnableTaskDecoratorImpl & {
|
|
30
|
+
__abstraction: import("@webiny/di").Abstraction<ITaskDefinition<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>>;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import camelCase from "lodash/camelCase.js";
|
|
2
|
+
import WebinyError from "@webiny/error";
|
|
3
|
+
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
4
|
+
const DEFAULT_MAX_ITERATIONS = 50;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* RunnableTaskDecorator adds runtime behavior to TaskDefinition:
|
|
8
|
+
* - Applies default values (maxIterations, isPrivate, databaseLogs, fields)
|
|
9
|
+
* - Validates task ID (must be camelCase)
|
|
10
|
+
* - Provides field management methods
|
|
11
|
+
*/
|
|
12
|
+
class RunnableTaskDecoratorImpl {
|
|
13
|
+
constructor(decoratee) {
|
|
14
|
+
this.decoratee = decoratee;
|
|
15
|
+
this.validate();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Delegate simple properties
|
|
19
|
+
get id() {
|
|
20
|
+
return this.decoratee.id;
|
|
21
|
+
}
|
|
22
|
+
get title() {
|
|
23
|
+
return this.decoratee.title;
|
|
24
|
+
}
|
|
25
|
+
get description() {
|
|
26
|
+
return this.decoratee.description;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Apply default values
|
|
30
|
+
get isPrivate() {
|
|
31
|
+
return this.decoratee.isPrivate ?? false;
|
|
32
|
+
}
|
|
33
|
+
get databaseLogs() {
|
|
34
|
+
return this.decoratee.databaseLogs ?? false;
|
|
35
|
+
}
|
|
36
|
+
get maxIterations() {
|
|
37
|
+
return this.decoratee.maxIterations || DEFAULT_MAX_ITERATIONS;
|
|
38
|
+
}
|
|
39
|
+
get selfCleanup() {
|
|
40
|
+
return this.decoratee.selfCleanup;
|
|
41
|
+
}
|
|
42
|
+
get createInputValidation() {
|
|
43
|
+
return this.decoratee.createInputValidation;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Delegate lifecycle methods (bind to preserve context)
|
|
47
|
+
get run() {
|
|
48
|
+
return this.decoratee.run.bind(this.decoratee);
|
|
49
|
+
}
|
|
50
|
+
get onBeforeTrigger() {
|
|
51
|
+
return this.decoratee.onBeforeTrigger?.bind(this.decoratee);
|
|
52
|
+
}
|
|
53
|
+
get onDone() {
|
|
54
|
+
return this.decoratee.onDone?.bind(this.decoratee);
|
|
55
|
+
}
|
|
56
|
+
get onError() {
|
|
57
|
+
return this.decoratee.onError?.bind(this.decoratee);
|
|
58
|
+
}
|
|
59
|
+
get onAbort() {
|
|
60
|
+
return this.decoratee.onAbort?.bind(this.decoratee);
|
|
61
|
+
}
|
|
62
|
+
get onMaxIterations() {
|
|
63
|
+
return this.decoratee.onMaxIterations?.bind(this.decoratee);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Validation logic
|
|
67
|
+
validate() {
|
|
68
|
+
if (camelCase(this.decoratee.id) !== this.decoratee.id) {
|
|
69
|
+
const message = `Task ID "${this.decoratee.id}" is invalid. It must be in camelCase format, for example: "myCustomTask".`;
|
|
70
|
+
console.log(message);
|
|
71
|
+
throw new WebinyError(message);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Method to get the underlying task (for compatibility with existing code)
|
|
76
|
+
getTask() {
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export const RunnableTaskDecorator = TaskDefinition.createDecorator({
|
|
81
|
+
decorator: RunnableTaskDecoratorImpl,
|
|
82
|
+
dependencies: []
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=RunnableTaskDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["camelCase","WebinyError","TaskDefinition","DEFAULT_MAX_ITERATIONS","RunnableTaskDecoratorImpl","constructor","decoratee","validate","id","title","description","isPrivate","databaseLogs","maxIterations","selfCleanup","createInputValidation","run","bind","onBeforeTrigger","onDone","onError","onAbort","onMaxIterations","message","console","log","getTask","RunnableTaskDecorator","createDecorator","decorator","dependencies"],"sources":["RunnableTaskDecorator.ts"],"sourcesContent":["import camelCase from \"lodash/camelCase.js\";\nimport WebinyError from \"@webiny/error\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport type { ITaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\n\nconst DEFAULT_MAX_ITERATIONS = 50;\n\n/**\n * RunnableTaskDecorator adds runtime behavior to TaskDefinition:\n * - Applies default values (maxIterations, isPrivate, databaseLogs, fields)\n * - Validates task ID (must be camelCase)\n * - Provides field management methods\n */\nclass RunnableTaskDecoratorImpl implements TaskDefinition.Interface {\n constructor(private decoratee: TaskDefinition.Interface) {\n this.validate();\n }\n\n // Delegate simple properties\n get id() {\n return this.decoratee.id;\n }\n\n get title() {\n return this.decoratee.title;\n }\n\n get description() {\n return this.decoratee.description;\n }\n\n // Apply default values\n get isPrivate() {\n return this.decoratee.isPrivate ?? false;\n }\n\n get databaseLogs() {\n return this.decoratee.databaseLogs ?? false;\n }\n\n get maxIterations() {\n return this.decoratee.maxIterations || DEFAULT_MAX_ITERATIONS;\n }\n\n get selfCleanup() {\n return this.decoratee.selfCleanup;\n }\n\n get createInputValidation() {\n return this.decoratee.createInputValidation;\n }\n\n // Delegate lifecycle methods (bind to preserve context)\n get run() {\n return this.decoratee.run.bind(this.decoratee);\n }\n\n get onBeforeTrigger() {\n return this.decoratee.onBeforeTrigger?.bind(this.decoratee);\n }\n\n get onDone() {\n return this.decoratee.onDone?.bind(this.decoratee);\n }\n\n get onError() {\n return this.decoratee.onError?.bind(this.decoratee);\n }\n\n get onAbort() {\n return this.decoratee.onAbort?.bind(this.decoratee);\n }\n\n get onMaxIterations() {\n return this.decoratee.onMaxIterations?.bind(this.decoratee);\n }\n\n // Validation logic\n private validate(): void {\n if (camelCase(this.decoratee.id) !== this.decoratee.id) {\n const message = `Task ID \"${this.decoratee.id}\" is invalid. It must be in camelCase format, for example: \"myCustomTask\".`;\n console.log(message);\n throw new WebinyError(message);\n }\n }\n\n // Method to get the underlying task (for compatibility with existing code)\n public getTask(): ITaskDefinition {\n return this;\n }\n}\n\nexport const RunnableTaskDecorator = TaskDefinition.createDecorator({\n decorator: RunnableTaskDecoratorImpl,\n dependencies: []\n});\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,qBAAqB;AAC3C,OAAOC,WAAW,MAAM,eAAe;AACvC,SAASC,cAAc,QAAQ,wDAAwD;AAGvF,MAAMC,sBAAsB,GAAG,EAAE;;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,yBAAyB,CAAqC;EAChEC,WAAWA,CAASC,SAAmC,EAAE;IAAA,KAArCA,SAAmC,GAAnCA,SAAmC;IACnD,IAAI,CAACC,QAAQ,CAAC,CA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AAA,EAAG;IACV,OAAO,IAAI,CAACf,SAAS,CAACe,OAAO,EAAEJ,IAAI,CAAC,IAAI,CAACX,SAAS,CAAC;EACvD;EAEA,IAAIgB,eAAeA,CAAA,EAAG;IAClB,OAAO,IAAI,CAAChB,SAAS,CAACgB,eAAe,EAAEL,IAAI,CAAC,IAAI,CAACX,SAAS,CAAC;EAC/D;;EAEA;EACQC,QAAQA,CAAA,EAAS;IACrB,IAAIP,SAAS,CAAC,IAAI,CAACM,SAAS,CAACE,EAAE,CAAC,KAAK,IAAI,CAACF,SAAS,CAACE,EAAE,EAAE;MACpD,MAAMe,OAAO,GAAG,YAAY,IAAI,CAACjB,SAAS,CAACE,EAAE,4EAA4E;MACzHgB,OAAO,CAACC,GAAG,CAACF,OAAO,CAAC;MACpB,MAAM,IAAItB,WAAW,CAACsB,OAAO,CAAC;IAClC;EACJ;;EAEA;EACOG,OAAOA,CAAA,EAAoB;IAC9B,OAAO,IAAI;EACf;AACJ;AAEA,OAAO,MAAMC,qBAAqB,GAAGzB,cAAc,CAAC0B,eAAe,CAAC;EAChEC,SAAS,EAAEzB,yBAAyB;EACpC0B,YAAY,EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
2
|
+
import { CleanupTaskSubtreeUseCase } from "../features/CleanupTaskSubtree/index.js";
|
|
3
|
+
type LifecycleHook = TaskDefinition.Interface["onDone"];
|
|
4
|
+
type HookParams = Parameters<NonNullable<LifecycleHook>>[0];
|
|
5
|
+
export declare class SelfCleaningTaskDecoratorImpl implements TaskDefinition.Interface {
|
|
6
|
+
private readonly cleanupTaskSubtree;
|
|
7
|
+
private decoratee;
|
|
8
|
+
private readonly events;
|
|
9
|
+
constructor(cleanupTaskSubtree: CleanupTaskSubtreeUseCase.Interface, decoratee: TaskDefinition.Interface);
|
|
10
|
+
get id(): string;
|
|
11
|
+
get title(): string;
|
|
12
|
+
get description(): string | undefined;
|
|
13
|
+
get isPrivate(): boolean | undefined;
|
|
14
|
+
get maxIterations(): number | undefined;
|
|
15
|
+
get selfCleanup(): import("@webiny/api-core/features/task/TaskDefinition/abstractions").ISelfCleanup | undefined;
|
|
16
|
+
get createInputValidation(): ((params: import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskCreateInputValidationParams) => import("zod").ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>> | import("@webiny/api/types").GenericRecord<PropertyKey, import("zod").ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>) | undefined;
|
|
17
|
+
get run(): (params: import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskRunParams<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>) => Promise<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskResult<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>>;
|
|
18
|
+
get onBeforeTrigger(): ((params: import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskBeforeTriggerParams<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput>) => Promise<void>) | undefined;
|
|
19
|
+
get onMaxIterations(): ((params: import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskLifecycleHook<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>) => Promise<void>) | undefined;
|
|
20
|
+
get databaseLogs(): boolean | undefined;
|
|
21
|
+
get onDone(): (params: HookParams) => Promise<void>;
|
|
22
|
+
get onError(): (params: HookParams) => Promise<void>;
|
|
23
|
+
get onAbort(): (params: HookParams) => Promise<void>;
|
|
24
|
+
private runCleanup;
|
|
25
|
+
private safeCall;
|
|
26
|
+
}
|
|
27
|
+
export declare const SelfCleaningTaskDecorator: typeof SelfCleaningTaskDecoratorImpl & {
|
|
28
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskDefinition<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>>;
|
|
29
|
+
};
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
2
|
+
import { normalizeSelfCleanup } from "../utils/normalizeSelfCleanup.js";
|
|
3
|
+
import { CleanupTaskSubtreeUseCase } from "../features/CleanupTaskSubtree/index.js";
|
|
4
|
+
import { getErrorProperties } from "../utils/getErrorProperties.js";
|
|
5
|
+
export class SelfCleaningTaskDecoratorImpl {
|
|
6
|
+
constructor(cleanupTaskSubtree, decoratee) {
|
|
7
|
+
this.cleanupTaskSubtree = cleanupTaskSubtree;
|
|
8
|
+
this.decoratee = decoratee;
|
|
9
|
+
this.events = normalizeSelfCleanup(decoratee.selfCleanup);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Pass-through properties.
|
|
13
|
+
get id() {
|
|
14
|
+
return this.decoratee.id;
|
|
15
|
+
}
|
|
16
|
+
get title() {
|
|
17
|
+
return this.decoratee.title;
|
|
18
|
+
}
|
|
19
|
+
get description() {
|
|
20
|
+
return this.decoratee.description;
|
|
21
|
+
}
|
|
22
|
+
get isPrivate() {
|
|
23
|
+
return this.decoratee.isPrivate;
|
|
24
|
+
}
|
|
25
|
+
get maxIterations() {
|
|
26
|
+
return this.decoratee.maxIterations;
|
|
27
|
+
}
|
|
28
|
+
get selfCleanup() {
|
|
29
|
+
return this.decoratee.selfCleanup;
|
|
30
|
+
}
|
|
31
|
+
get createInputValidation() {
|
|
32
|
+
return this.decoratee.createInputValidation;
|
|
33
|
+
}
|
|
34
|
+
get run() {
|
|
35
|
+
return this.decoratee.run.bind(this.decoratee);
|
|
36
|
+
}
|
|
37
|
+
get onBeforeTrigger() {
|
|
38
|
+
return this.decoratee.onBeforeTrigger?.bind(this.decoratee);
|
|
39
|
+
}
|
|
40
|
+
get onMaxIterations() {
|
|
41
|
+
return this.decoratee.onMaxIterations?.bind(this.decoratee);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// databaseLogs override — any non-empty event set forces false.
|
|
45
|
+
get databaseLogs() {
|
|
46
|
+
if (this.events.size > 0) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return this.decoratee.databaseLogs;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Always-defined lifecycle hooks. Each runs the user's hook first, then
|
|
53
|
+
// triggers cleanup if the matching event is in the set.
|
|
54
|
+
get onDone() {
|
|
55
|
+
return async params => {
|
|
56
|
+
await this.safeCall(this.decoratee.onDone, params, "onDone");
|
|
57
|
+
if (this.events.has("onSuccess")) {
|
|
58
|
+
await this.runCleanup(params);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
get onError() {
|
|
63
|
+
return async params => {
|
|
64
|
+
await this.safeCall(this.decoratee.onError, params, "onError");
|
|
65
|
+
if (this.events.has("onError")) {
|
|
66
|
+
await this.runCleanup(params);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
get onAbort() {
|
|
71
|
+
return async params => {
|
|
72
|
+
await this.safeCall(this.decoratee.onAbort, params, "onAbort");
|
|
73
|
+
if (this.events.has("onAbort")) {
|
|
74
|
+
await this.runCleanup(params);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async runCleanup(params) {
|
|
79
|
+
await this.cleanupTaskSubtree.execute(params.task.id);
|
|
80
|
+
}
|
|
81
|
+
async safeCall(hook, params, name) {
|
|
82
|
+
if (!hook) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
await hook.call(this.decoratee, params);
|
|
87
|
+
} catch (ex) {
|
|
88
|
+
console.error(`Error executing ${name} hook for task "${params.task.id}".`);
|
|
89
|
+
console.log(getErrorProperties(ex));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export const SelfCleaningTaskDecorator = TaskDefinition.createDecorator({
|
|
94
|
+
decorator: SelfCleaningTaskDecoratorImpl,
|
|
95
|
+
dependencies: [CleanupTaskSubtreeUseCase]
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
//# sourceMappingURL=SelfCleaningTaskDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TaskDefinition","normalizeSelfCleanup","CleanupTaskSubtreeUseCase","getErrorProperties","SelfCleaningTaskDecoratorImpl","constructor","cleanupTaskSubtree","decoratee","events","selfCleanup","id","title","description","isPrivate","maxIterations","createInputValidation","run","bind","onBeforeTrigger","onMaxIterations","databaseLogs","size","onDone","params","safeCall","has","runCleanup","onError","onAbort","execute","task","hook","name","call","ex","console","error","log","SelfCleaningTaskDecorator","createDecorator","decorator","dependencies"],"sources":["SelfCleaningTaskDecorator.ts"],"sourcesContent":["import { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport type { ISelfCleanupEvent } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { normalizeSelfCleanup } from \"~/utils/normalizeSelfCleanup.js\";\nimport { CleanupTaskSubtreeUseCase } from \"~/features/CleanupTaskSubtree/index.js\";\nimport { getErrorProperties } from \"~/utils/getErrorProperties.js\";\n\ntype LifecycleHook = TaskDefinition.Interface[\"onDone\"];\ntype HookParams = Parameters<NonNullable<LifecycleHook>>[0];\n\nexport class SelfCleaningTaskDecoratorImpl implements TaskDefinition.Interface {\n private readonly events: ReadonlySet<ISelfCleanupEvent>;\n\n public constructor(\n private readonly cleanupTaskSubtree: CleanupTaskSubtreeUseCase.Interface,\n private decoratee: TaskDefinition.Interface\n ) {\n this.events = normalizeSelfCleanup(decoratee.selfCleanup);\n }\n\n // Pass-through properties.\n get id() {\n return this.decoratee.id;\n }\n get title() {\n return this.decoratee.title;\n }\n get description() {\n return this.decoratee.description;\n }\n get isPrivate() {\n return this.decoratee.isPrivate;\n }\n get maxIterations() {\n return this.decoratee.maxIterations;\n }\n get selfCleanup() {\n return this.decoratee.selfCleanup;\n }\n get createInputValidation() {\n return this.decoratee.createInputValidation;\n }\n get run() {\n return this.decoratee.run.bind(this.decoratee);\n }\n get onBeforeTrigger() {\n return this.decoratee.onBeforeTrigger?.bind(this.decoratee);\n }\n get onMaxIterations() {\n return this.decoratee.onMaxIterations?.bind(this.decoratee);\n }\n\n // databaseLogs override — any non-empty event set forces false.\n get databaseLogs() {\n if (this.events.size > 0) {\n return false;\n }\n return this.decoratee.databaseLogs;\n }\n\n // Always-defined lifecycle hooks. Each runs the user's hook first, then\n // triggers cleanup if the matching event is in the set.\n get onDone() {\n return async (params: HookParams) => {\n await this.safeCall(this.decoratee.onDone, params, \"onDone\");\n if (this.events.has(\"onSuccess\")) {\n await this.runCleanup(params);\n }\n };\n }\n\n get onError() {\n return async (params: HookParams) => {\n await this.safeCall(this.decoratee.onError, params, \"onError\");\n if (this.events.has(\"onError\")) {\n await this.runCleanup(params);\n }\n };\n }\n\n get onAbort() {\n return async (params: HookParams) => {\n await this.safeCall(this.decoratee.onAbort, params, \"onAbort\");\n if (this.events.has(\"onAbort\")) {\n await this.runCleanup(params);\n }\n };\n }\n\n private async runCleanup(params: HookParams): Promise<void> {\n await this.cleanupTaskSubtree.execute(params.task.id);\n }\n\n private async safeCall(\n hook: LifecycleHook | undefined,\n params: HookParams,\n name: string\n ): Promise<void> {\n if (!hook) {\n return;\n }\n try {\n await hook.call(this.decoratee, params);\n } catch (ex) {\n console.error(`Error executing ${name} hook for task \"${params.task.id}\".`);\n console.log(getErrorProperties(ex));\n }\n }\n}\n\nexport const SelfCleaningTaskDecorator = TaskDefinition.createDecorator({\n decorator: SelfCleaningTaskDeco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iB;IACxD,MAAM,IAAI,CAACjB,kBAAkB,CAACuB,OAAO,CAACN,MAAM,CAACO,IAAI,CAACpB,EAAE,CAAC;EACzD;EAEA,MAAcc,QAAQA,CAClBO,IAA+B,EAC/BR,MAAkB,EAClBS,IAAY,EACC;IACb,IAAI,CAACD,IAAI,EAAE;MACP;IACJ;IACA,IAAI;MACA,MAAMA,IAAI,CAACE,IAAI,CAAC,IAAI,CAAC1B,SAAS,EAAEgB,MAAM,CAAC;IAC3C,CAAC,CAAC,OAAOW,EAAE,EAAE;MACTC,OAAO,CAACC,KAAK,CAAC,mBAAmBJ,IAAI,mBAAmBT,MAAM,CAACO,IAAI,CAACpB,EAAE,IAAI,CAAC;MAC3EyB,OAAO,CAACE,GAAG,CAAClC,kBAAkB,CAAC+B,EAAE,CAAC,CAAC;IACvC;EACJ;AACJ;AAEA,OAAO,MAAMI,yBAAyB,GAAGtC,cAAc,CAACuC,eAAe,CAAC;EACpEC,SAAS,EAAEpC,6BAA6B;EACxCqC,YAAY,EAAE,CAACvC,yBAAyB;AAC5C,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BaseError } from "@webiny/feature/api";
|
|
2
|
+
export declare class TaskDefinitionNotFoundError extends BaseError<{
|
|
3
|
+
id: string;
|
|
4
|
+
}> {
|
|
5
|
+
readonly code: "BackgroundTasks/TaskDefinition/NotFoundError";
|
|
6
|
+
constructor(id: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class TaskNotFoundError extends BaseError {
|
|
9
|
+
readonly code: "BackgroundTasks/Task/NotFoundError";
|
|
10
|
+
constructor();
|
|
11
|
+
}
|
|
12
|
+
export declare class TaskAbortError extends BaseError<{
|
|
13
|
+
id: string;
|
|
14
|
+
status: string;
|
|
15
|
+
}> {
|
|
16
|
+
readonly code: "BackgroundTasks/Task/Abort";
|
|
17
|
+
constructor(data: {
|
|
18
|
+
id: string;
|
|
19
|
+
status: string;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export declare class TaskLogNotFoundError extends BaseError {
|
|
23
|
+
readonly code: "BackgroundTasks/Log/NotFoundError";
|
|
24
|
+
constructor();
|
|
25
|
+
}
|
|
26
|
+
export declare class TaskServiceInfoError extends BaseError {
|
|
27
|
+
readonly code: "BackgroundTasks/Service/InfoUnavailable";
|
|
28
|
+
constructor();
|
|
29
|
+
}
|
package/domain/errors.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { BaseError } from "@webiny/feature/api";
|
|
2
|
+
export class TaskDefinitionNotFoundError extends BaseError {
|
|
3
|
+
code = "BackgroundTasks/TaskDefinition/NotFoundError";
|
|
4
|
+
constructor(id) {
|
|
5
|
+
super({
|
|
6
|
+
message: "Task definition not found.",
|
|
7
|
+
data: {
|
|
8
|
+
id
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class TaskNotFoundError extends BaseError {
|
|
14
|
+
code = "BackgroundTasks/Task/NotFoundError";
|
|
15
|
+
constructor() {
|
|
16
|
+
super({
|
|
17
|
+
message: "Task not found."
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class TaskAbortError extends BaseError {
|
|
22
|
+
code = "BackgroundTasks/Task/Abort";
|
|
23
|
+
constructor(data) {
|
|
24
|
+
super({
|
|
25
|
+
message: "Cannot abort a task that is not pending or running!",
|
|
26
|
+
data
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export class TaskLogNotFoundError extends BaseError {
|
|
31
|
+
code = "BackgroundTasks/Log/NotFoundError";
|
|
32
|
+
constructor() {
|
|
33
|
+
super({
|
|
34
|
+
message: "Task log not found."
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export class TaskServiceInfoError extends BaseError {
|
|
39
|
+
code = "BackgroundTasks/Service/InfoUnavailable";
|
|
40
|
+
constructor() {
|
|
41
|
+
super({
|
|
42
|
+
message: "Unable to fetch service info."
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["BaseError","TaskDefinitionNotFoundError","code","constructor","id","message","data","TaskNotFoundError","TaskAbortError","TaskLogNotFoundError","TaskServiceInfoError"],"sources":["errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\nexport class TaskDefinitionNotFoundError extends BaseError<{ id: string }> {\n override readonly code = \"BackgroundTasks/TaskDefinition/NotFoundError\" as const;\n\n constructor(id: string) {\n super({\n message: \"Task definition not found.\",\n data: {\n id\n }\n });\n }\n}\n\nexport class TaskNotFoundError extends BaseError {\n override readonly code = \"BackgroundTasks/Task/NotFoundError\" as const;\n\n constructor() {\n super({\n message: \"Task not found.\"\n });\n }\n}\n\nexport class TaskAbortError extends BaseError<{ id: string; status: string }> {\n override readonly code = \"BackgroundTasks/Task/Abort\" as const;\n\n constructor(data: { id: string; status: string }) {\n super({\n message: \"Cannot abort a task that is not pending or running!\",\n data\n });\n }\n}\n\nexport class TaskLogNotFoundError extends BaseError {\n override readonly code = \"BackgroundTasks/Log/NotFoundError\" as const;\n\n constructor() {\n super({\n message: \"Task log not found.\"\n });\n }\n}\n\nexport class TaskServiceInfoError extends BaseError {\n override readonly code = \"BackgroundTasks/Service/InfoUnavailable\" as const;\n\n constructor() {\n super({\n message: \"Unable to fetch service info.\"\n });\n }\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,qBAAqB;AAE/C,OAAO,MAAMC,2BAA2B,SAASD,SAAS,CAAiB;EACrDE,IAAI,GAAG,8CAA8C;EAEvEC,WAAWA,CAACC,EAAU,EAAE;IACpB,KAAK,CAAC;MACFC,OAAO,EAAE,4BAA4B;MACrCC,IAAI,EAAE;QACFF;MACJ;IACJ,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAMG,iBAAiB,SAASP,SAAS,CAAC;EAC3BE,IAAI,GAAG,oCAAoC;EAE7DC,WAAWA,CAAA,EAAG;IACV,KAAK,CAAC;MACFE,OAAO,EAAE;IACb,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAMG,cAAc,SAASR,SAAS,CAAiC;EACxDE,IAAI,GAAG,4BAA4B;EAErDC,WAAWA,CAACG,IAAoC,EAAE;IAC9C,KAAK,CAAC;MACFD,OAAO,EAAE,qDAAqD;MAC9DC;IACJ,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAMG,oBAAoB,SAAST,SAAS,CAAC;EAC9BE,IAAI,GAAG,mCAAmC;EAE5DC,WAAWA,CAAA,EAAG;IACV,KAAK,CAAC;MACFE,OAAO,EAAE;IACb,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAMK,oBAAoB,SAASV,SAAS,CAAC;EAC9BE,IAAI,GAAG,yCAAyC;EAElEC,WAAWA,CAAA,EAAG;IACV,KAAK,CAAC;MACFE,OAAO,EAAE;IACb,CAAC,CAAC;EACN;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DomainEvent } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
2
|
+
import { TaskAfterCreatePayload } from "./abstractions.js";
|
|
3
|
+
export declare class TaskAfterCreateEvent extends DomainEvent<TaskAfterCreatePayload> {
|
|
4
|
+
eventType: "task.afterCreate";
|
|
5
|
+
getHandlerAbstraction(): import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher/abstractions.js").IEventHandler<DomainEvent<TaskAfterCreatePayload>>>;
|
|
6
|
+
}
|