@webiny/background-tasks 6.6.0-alpha.1 → 6.6.0-alpha.11
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/api/BackgroundTasksFeature.js +42 -24
- package/api/BackgroundTasksFeature.js.map +1 -1
- package/api/crud/TaskLogPrivateModel.js +2 -1
- package/api/crud/TaskLogPrivateModel.js.map +1 -1
- package/api/crud/TaskPrivateModel.js +2 -1
- package/api/crud/TaskPrivateModel.js.map +1 -1
- package/api/decorators/SelfCleaningTaskHandlerDecorator.d.ts +33 -0
- package/api/decorators/{SelfCleaningTaskDecorator.js → SelfCleaningTaskHandlerDecorator.js} +15 -39
- package/api/decorators/SelfCleaningTaskHandlerDecorator.js.map +1 -0
- package/api/decorators/TaskDefinitionDefaultsDecorator.d.ts +27 -0
- package/api/decorators/{RunnableTaskDecorator.js → TaskDefinitionDefaultsDecorator.js} +11 -32
- package/api/decorators/TaskDefinitionDefaultsDecorator.js.map +1 -0
- package/api/domain/errors.d.ts +14 -10
- package/api/domain/errors.js +27 -12
- package/api/domain/errors.js.map +1 -1
- package/api/domain/task/TaskLogModelProvider.d.ts +12 -0
- package/api/domain/task/TaskLogModelProvider.js +23 -0
- package/api/domain/task/TaskLogModelProvider.js.map +1 -0
- package/api/domain/task/TaskLogsRepository.d.ts +34 -0
- package/api/domain/task/TaskLogsRepository.js +146 -0
- package/api/domain/task/TaskLogsRepository.js.map +1 -0
- package/api/domain/task/TaskModelProvider.d.ts +12 -0
- package/api/domain/task/TaskModelProvider.js +23 -0
- package/api/domain/task/TaskModelProvider.js.map +1 -0
- package/api/domain/task/TasksRepository.d.ts +37 -0
- package/api/domain/task/TasksRepository.js +126 -0
- package/api/domain/task/TasksRepository.js.map +1 -0
- package/api/domain/task/abstractions.d.ts +50 -0
- package/api/domain/task/abstractions.js +8 -0
- package/api/domain/task/abstractions.js.map +1 -0
- package/api/domain/task/createRevisionId.d.ts +1 -0
- package/api/domain/task/createRevisionId.js +8 -0
- package/api/domain/task/createRevisionId.js.map +1 -0
- package/api/domain/task/entryToTask.d.ts +3 -0
- package/api/domain/task/entryToTask.js +20 -0
- package/api/domain/task/entryToTask.js.map +1 -0
- package/api/domain/task/entryToTaskLog.d.ts +3 -0
- package/api/domain/task/entryToTaskLog.js +12 -0
- package/api/domain/task/entryToTaskLog.js.map +1 -0
- package/api/features/AbortTask/abstractions.d.ts +4 -0
- package/api/features/AbortTask/abstractions.js.map +1 -1
- package/api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.d.ts +25 -5
- package/api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js +111 -5
- package/api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js.map +1 -1
- package/api/features/CleanupTaskSubtree/feature.d.ts +4 -0
- package/api/features/CleanupTaskSubtree/feature.js +11 -0
- package/api/features/CleanupTaskSubtree/feature.js.map +1 -0
- package/api/features/CleanupTaskSubtree/index.d.ts +1 -1
- package/api/features/CleanupTaskSubtree/index.js +1 -1
- package/api/features/CreateTask/CreateTaskUseCase.d.ts +17 -0
- package/api/features/CreateTask/CreateTaskUseCase.js +56 -0
- package/api/features/CreateTask/CreateTaskUseCase.js.map +1 -0
- package/api/features/CreateTask/abstractions.d.ts +21 -0
- package/api/features/CreateTask/abstractions.js +5 -0
- package/api/features/CreateTask/abstractions.js.map +1 -0
- package/api/features/{GetTaskDefinition → CreateTask}/feature.d.ts +1 -1
- package/api/features/CreateTask/feature.js +11 -0
- package/api/features/CreateTask/feature.js.map +1 -0
- package/api/features/CreateTask/index.d.ts +2 -0
- package/api/features/CreateTask/index.js +2 -0
- package/api/features/CreateTaskLog/CreateTaskLogUseCase.d.ts +13 -0
- package/api/features/CreateTaskLog/CreateTaskLogUseCase.js +19 -0
- package/api/features/CreateTaskLog/CreateTaskLogUseCase.js.map +1 -0
- package/api/features/CreateTaskLog/abstractions.d.ts +16 -0
- package/api/features/CreateTaskLog/abstractions.js +5 -0
- package/api/features/CreateTaskLog/abstractions.js.map +1 -0
- package/api/features/CreateTaskLog/feature.d.ts +4 -0
- package/api/features/CreateTaskLog/feature.js +11 -0
- package/api/features/CreateTaskLog/feature.js.map +1 -0
- package/api/features/CreateTaskLog/index.d.ts +2 -0
- package/api/features/CreateTaskLog/index.js +2 -0
- package/api/features/DeleteTask/DeleteTaskUseCase.d.ts +14 -0
- package/api/features/DeleteTask/DeleteTaskUseCase.js +34 -0
- package/api/features/DeleteTask/DeleteTaskUseCase.js.map +1 -0
- package/api/features/DeleteTask/abstractions.d.ts +17 -0
- package/api/features/DeleteTask/abstractions.js +5 -0
- package/api/features/DeleteTask/abstractions.js.map +1 -0
- package/api/features/DeleteTask/feature.d.ts +4 -0
- package/api/features/DeleteTask/feature.js +11 -0
- package/api/features/DeleteTask/feature.js.map +1 -0
- package/api/features/DeleteTask/index.d.ts +2 -0
- package/api/features/DeleteTask/index.js +2 -0
- package/api/features/DeleteTaskLog/DeleteTaskLogUseCase.d.ts +11 -0
- package/api/features/DeleteTaskLog/DeleteTaskLogUseCase.js +19 -0
- package/api/features/DeleteTaskLog/DeleteTaskLogUseCase.js.map +1 -0
- package/api/features/DeleteTaskLog/abstractions.d.ts +14 -0
- package/api/features/DeleteTaskLog/abstractions.js +5 -0
- package/api/features/DeleteTaskLog/abstractions.js.map +1 -0
- package/api/features/DeleteTaskLog/feature.d.ts +4 -0
- package/api/features/DeleteTaskLog/feature.js +11 -0
- package/api/features/DeleteTaskLog/feature.js.map +1 -0
- package/api/features/DeleteTaskLog/index.d.ts +2 -0
- package/api/features/DeleteTaskLog/index.js +2 -0
- package/api/features/GetLatestTaskLog/GetLatestTaskLogUseCase.d.ts +11 -0
- package/api/features/GetLatestTaskLog/GetLatestTaskLogUseCase.js +19 -0
- package/api/features/GetLatestTaskLog/GetLatestTaskLogUseCase.js.map +1 -0
- package/api/features/GetLatestTaskLog/abstractions.d.ts +15 -0
- package/api/features/GetLatestTaskLog/abstractions.js +5 -0
- package/api/features/GetLatestTaskLog/abstractions.js.map +1 -0
- package/api/features/GetLatestTaskLog/feature.d.ts +4 -0
- package/api/features/GetLatestTaskLog/feature.js +11 -0
- package/api/features/GetLatestTaskLog/feature.js.map +1 -0
- package/api/features/GetLatestTaskLog/index.d.ts +2 -0
- package/api/features/GetLatestTaskLog/index.js +2 -0
- package/api/features/{GetTaskDefinition/GetTaskDefinitionUseCase.d.ts → GetRunnableTaskDefinition/GetRunnableTaskDefinitionUseCase.d.ts} +5 -7
- package/api/features/GetRunnableTaskDefinition/GetRunnableTaskDefinitionUseCase.js +51 -0
- package/api/features/GetRunnableTaskDefinition/GetRunnableTaskDefinitionUseCase.js.map +1 -0
- package/api/features/{GetTaskDefinition → GetRunnableTaskDefinition}/abstractions.d.ts +7 -8
- package/api/features/GetRunnableTaskDefinition/abstractions.js +5 -0
- package/api/features/GetRunnableTaskDefinition/abstractions.js.map +1 -0
- package/api/features/GetRunnableTaskDefinition/feature.d.ts +4 -0
- package/api/features/GetRunnableTaskDefinition/feature.js +11 -0
- package/api/features/GetRunnableTaskDefinition/feature.js.map +1 -0
- package/api/features/GetRunnableTaskDefinition/index.d.ts +2 -0
- package/api/features/GetRunnableTaskDefinition/index.js +2 -0
- package/api/features/GetTask/GetTaskUseCase.d.ts +9 -5
- package/api/features/GetTask/GetTaskUseCase.js +12 -4
- package/api/features/GetTask/GetTaskUseCase.js.map +1 -1
- package/api/features/GetTask/abstractions.d.ts +9 -2
- package/api/features/GetTask/abstractions.js.map +1 -1
- package/api/features/GetTask/feature.js +2 -4
- package/api/features/GetTask/feature.js.map +1 -1
- package/api/features/ListTaskLogs/ListTaskLogsUseCase.d.ts +12 -0
- package/api/features/ListTaskLogs/ListTaskLogsUseCase.js +19 -0
- package/api/features/ListTaskLogs/ListTaskLogsUseCase.js.map +1 -0
- package/api/features/ListTaskLogs/abstractions.d.ts +15 -0
- package/api/features/ListTaskLogs/abstractions.js +5 -0
- package/api/features/ListTaskLogs/abstractions.js.map +1 -0
- package/api/features/ListTaskLogs/feature.d.ts +4 -0
- package/api/features/ListTaskLogs/feature.js +11 -0
- package/api/features/ListTaskLogs/feature.js.map +1 -0
- package/api/features/ListTaskLogs/index.d.ts +2 -0
- package/api/features/ListTaskLogs/index.js +2 -0
- package/api/features/ListTasks/ListTasksUseCase.d.ts +9 -6
- package/api/features/ListTasks/ListTasksUseCase.js +12 -4
- package/api/features/ListTasks/ListTasksUseCase.js.map +1 -1
- package/api/features/ListTasks/abstractions.d.ts +9 -3
- package/api/features/ListTasks/abstractions.js.map +1 -1
- package/api/features/ListTasks/feature.js +2 -4
- package/api/features/ListTasks/feature.js.map +1 -1
- package/api/features/ListVisibleTaskDefinitions/ListVisibleTaskDefinitionsUseCase.d.ts +11 -0
- package/api/features/ListVisibleTaskDefinitions/ListVisibleTaskDefinitionsUseCase.js +19 -0
- package/api/features/ListVisibleTaskDefinitions/ListVisibleTaskDefinitionsUseCase.js.map +1 -0
- package/api/features/ListVisibleTaskDefinitions/abstractions.d.ts +9 -0
- package/api/features/ListVisibleTaskDefinitions/abstractions.js +5 -0
- package/api/features/ListVisibleTaskDefinitions/abstractions.js.map +1 -0
- package/api/features/ListVisibleTaskDefinitions/feature.d.ts +4 -0
- package/api/features/ListVisibleTaskDefinitions/feature.js +11 -0
- package/api/features/ListVisibleTaskDefinitions/feature.js.map +1 -0
- package/api/features/ListVisibleTaskDefinitions/index.d.ts +2 -0
- package/api/features/ListVisibleTaskDefinitions/index.js +2 -0
- package/api/features/TaskService/BackgroundTaskService.d.ts +42 -0
- package/api/features/TaskService/BackgroundTaskService.js +211 -0
- package/api/features/TaskService/BackgroundTaskService.js.map +1 -0
- package/api/features/TaskService/feature.d.ts +4 -0
- package/api/features/TaskService/feature.js +11 -0
- package/api/features/TaskService/feature.js.map +1 -0
- package/api/features/TaskService/index.d.ts +1 -0
- package/api/features/TaskService/index.js +1 -0
- package/api/features/TriggerTask/abstractions.d.ts +6 -0
- package/api/features/TriggerTask/abstractions.js.map +1 -1
- package/api/features/TriggerVisibleTask/TriggerVisibleTaskUseCase.d.ts +15 -0
- package/api/features/TriggerVisibleTask/TriggerVisibleTaskUseCase.js +26 -0
- package/api/features/TriggerVisibleTask/TriggerVisibleTaskUseCase.js.map +1 -0
- package/api/features/TriggerVisibleTask/abstractions.d.ts +17 -0
- package/api/features/TriggerVisibleTask/abstractions.js +5 -0
- package/api/features/TriggerVisibleTask/abstractions.js.map +1 -0
- package/api/features/TriggerVisibleTask/feature.d.ts +4 -0
- package/api/features/TriggerVisibleTask/feature.js +11 -0
- package/api/features/TriggerVisibleTask/feature.js.map +1 -0
- package/api/features/TriggerVisibleTask/index.d.ts +2 -0
- package/api/features/TriggerVisibleTask/index.js +2 -0
- package/api/features/UpdateBackgroundTaskSettings/UpdateBackgroundTaskSettingsRepository.js +3 -1
- package/api/features/UpdateBackgroundTaskSettings/UpdateBackgroundTaskSettingsRepository.js.map +1 -1
- package/api/features/UpdateTask/UpdateTaskUseCase.d.ts +17 -0
- package/api/features/UpdateTask/UpdateTaskUseCase.js +36 -0
- package/api/features/UpdateTask/UpdateTaskUseCase.js.map +1 -0
- package/api/features/UpdateTask/abstractions.d.ts +22 -0
- package/api/features/UpdateTask/abstractions.js +5 -0
- package/api/features/UpdateTask/abstractions.js.map +1 -0
- package/api/features/UpdateTask/feature.d.ts +4 -0
- package/api/features/UpdateTask/feature.js +11 -0
- package/api/features/UpdateTask/feature.js.map +1 -0
- package/api/features/UpdateTask/index.d.ts +2 -0
- package/api/features/UpdateTask/index.js +2 -0
- package/api/features/UpdateTaskLog/UpdateTaskLogUseCase.d.ts +12 -0
- package/api/features/UpdateTaskLog/UpdateTaskLogUseCase.js +19 -0
- package/api/features/UpdateTaskLog/UpdateTaskLogUseCase.js.map +1 -0
- package/api/features/UpdateTaskLog/abstractions.d.ts +16 -0
- package/api/features/UpdateTaskLog/abstractions.js +5 -0
- package/api/features/UpdateTaskLog/abstractions.js.map +1 -0
- package/api/features/UpdateTaskLog/feature.d.ts +4 -0
- package/api/features/UpdateTaskLog/feature.js +11 -0
- package/api/features/UpdateTaskLog/feature.js.map +1 -0
- package/api/features/UpdateTaskLog/index.d.ts +2 -0
- package/api/features/UpdateTaskLog/index.js +2 -0
- package/api/graphql/BackgroundTasksGraphQLSchema.d.ts +29 -0
- package/api/graphql/BackgroundTasksGraphQLSchema.js +462 -0
- package/api/graphql/BackgroundTasksGraphQLSchema.js.map +1 -0
- package/api/index.d.ts +11 -2
- package/api/index.js +11 -2
- package/api/runner/TaskControl.d.ts +14 -4
- package/api/runner/TaskControl.js +29 -29
- package/api/runner/TaskControl.js.map +1 -1
- package/api/runner/TaskManager.js +3 -3
- package/api/runner/TaskManager.js.map +1 -1
- package/api/runner/TaskManagerStore.d.ts +14 -5
- package/api/runner/TaskManagerStore.js +23 -7
- package/api/runner/TaskManagerStore.js.map +1 -1
- package/api/runner/TaskRunner.js +14 -4
- package/api/runner/TaskRunner.js.map +1 -1
- package/api/types.d.ts +1 -48
- package/api/types.js.map +1 -1
- package/package.json +28 -30
- package/api/TasksCrud.d.ts +0 -10
- package/api/TasksCrud.js +0 -5
- package/api/TasksCrud.js.map +0 -1
- package/api/crud/cleanupTaskSubtree.d.ts +0 -8
- package/api/crud/cleanupTaskSubtree.js +0 -63
- package/api/crud/cleanupTaskSubtree.js.map +0 -1
- package/api/crud/crud.tasks.d.ts +0 -3
- package/api/crud/crud.tasks.js +0 -318
- package/api/crud/crud.tasks.js.map +0 -1
- package/api/crud/definition.tasks.d.ts +0 -3
- package/api/crud/definition.tasks.js +0 -17
- package/api/crud/definition.tasks.js.map +0 -1
- package/api/crud/service.tasks.d.ts +0 -3
- package/api/crud/service.tasks.js +0 -134
- package/api/crud/service.tasks.js.map +0 -1
- package/api/decorators/RunnableTaskDecorator.d.ts +0 -33
- package/api/decorators/RunnableTaskDecorator.js.map +0 -1
- package/api/decorators/SelfCleaningTaskDecorator.d.ts +0 -33
- package/api/decorators/SelfCleaningTaskDecorator.js.map +0 -1
- package/api/features/GetTaskDefinition/GetTaskDefinitionUseCase.js +0 -88
- package/api/features/GetTaskDefinition/GetTaskDefinitionUseCase.js.map +0 -1
- package/api/features/GetTaskDefinition/abstractions.js +0 -5
- package/api/features/GetTaskDefinition/abstractions.js.map +0 -1
- package/api/features/GetTaskDefinition/feature.js +0 -11
- package/api/features/GetTaskDefinition/feature.js.map +0 -1
- package/api/features/GetTaskDefinition/index.d.ts +0 -2
- package/api/features/GetTaskDefinition/index.js +0 -2
- package/api/graphql/BackgroundTasksContextualSchema.d.ts +0 -21
- package/api/graphql/BackgroundTasksContextualSchema.js +0 -369
- package/api/graphql/BackgroundTasksContextualSchema.js.map +0 -1
- package/api/service/createService.d.ts +0 -6
- package/api/service/createService.js +0 -11
- package/api/service/createService.js.map +0 -1
- package/api/service/index.d.ts +0 -1
- package/api/service/index.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/ListTaskLogs/abstractions.js","sources":["../../../../src/api/features/ListTaskLogs/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { IListTaskLogParams } from \"~/api/types.js\";\nimport type { IListTaskLogsResponse } from \"~/api/types.js\";\nimport type { BackgroundTaskPersistenceError } from \"~/api/domain/errors.js\";\n\ntype UseCaseError = BackgroundTaskPersistenceError;\n\nexport interface IListTaskLogsUseCase {\n execute(params: IListTaskLogParams): Promise<Result<IListTaskLogsResponse, UseCaseError>>;\n}\n\n/** List task logs. */\nexport const ListTaskLogsUseCase = createAbstraction<IListTaskLogsUseCase>(\n \"Tasks/ListTaskLogsUseCase\"\n);\n\nexport namespace ListTaskLogsUseCase {\n export type Interface = IListTaskLogsUseCase;\n export type Error = UseCaseError;\n}\n"],"names":["ListTaskLogsUseCase","createAbstraction"],"mappings":";AAaO,MAAMA,sBAAsBC,kBAC/B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { ListTaskLogsUseCase } from "./ListTaskLogsUseCase.js";
|
|
3
|
+
const ListTaskLogsFeature = createFeature({
|
|
4
|
+
name: "ListTaskLogs",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(ListTaskLogsUseCase);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { ListTaskLogsFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/ListTaskLogs/feature.js","sources":["../../../../src/api/features/ListTaskLogs/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListTaskLogsUseCase } from \"./ListTaskLogsUseCase.js\";\n\nexport const ListTaskLogsFeature = createFeature({\n name: \"ListTaskLogs\",\n register(container) {\n container.register(ListTaskLogsUseCase);\n }\n});\n"],"names":["ListTaskLogsFeature","createFeature","container","ListTaskLogsUseCase"],"mappings":";;AAGO,MAAMA,sBAAsBC,cAAc;IAC7C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { ListTasksUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
2
2
|
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
3
3
|
import { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
execute<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskService.GenericOutput = TaskService.GenericOutput>(params?: UseCaseAbstraction.Params): Promise<IListTasksResponse<I, O>>;
|
|
4
|
+
import { TasksRepository } from "../../../api/domain/task/abstractions.js";
|
|
5
|
+
declare class ListTasksUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
6
|
+
private readonly repository;
|
|
7
|
+
constructor(repository: TasksRepository.Interface);
|
|
8
|
+
execute<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskService.GenericOutput = TaskService.GenericOutput>(params?: UseCaseAbstraction.Params): UseCaseAbstraction.Return<I, O>;
|
|
10
9
|
}
|
|
10
|
+
export declare const ListTasksUseCase: typeof ListTasksUseCaseImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IListTasksUseCase>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
+
import { ListTasksUseCase } from "./abstractions.js";
|
|
2
|
+
import { TasksRepository } from "../../domain/task/abstractions.js";
|
|
1
3
|
class ListTasksUseCaseImpl {
|
|
2
|
-
constructor(
|
|
3
|
-
this.
|
|
4
|
+
constructor(repository){
|
|
5
|
+
this.repository = repository;
|
|
4
6
|
}
|
|
5
7
|
async execute(params) {
|
|
6
|
-
return
|
|
8
|
+
return this.repository.list(params);
|
|
7
9
|
}
|
|
8
10
|
}
|
|
9
|
-
|
|
11
|
+
const ListTasksUseCase_ListTasksUseCase = ListTasksUseCase.createImplementation({
|
|
12
|
+
implementation: ListTasksUseCaseImpl,
|
|
13
|
+
dependencies: [
|
|
14
|
+
TasksRepository
|
|
15
|
+
]
|
|
16
|
+
});
|
|
17
|
+
export { ListTasksUseCase_ListTasksUseCase as ListTasksUseCase };
|
|
10
18
|
|
|
11
19
|
//# sourceMappingURL=ListTasksUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/features/ListTasks/ListTasksUseCase.js","sources":["../../../../src/api/features/ListTasks/ListTasksUseCase.ts"],"sourcesContent":["import { ListTasksUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport
|
|
1
|
+
{"version":3,"file":"api/features/ListTasks/ListTasksUseCase.js","sources":["../../../../src/api/features/ListTasks/ListTasksUseCase.ts"],"sourcesContent":["import { ListTasksUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport { TasksRepository } from \"~/api/domain/task/abstractions.js\";\n\nclass ListTasksUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(private readonly repository: TasksRepository.Interface) {}\n\n async execute<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskService.GenericOutput = TaskService.GenericOutput\n >(params?: UseCaseAbstraction.Params): UseCaseAbstraction.Return<I, O> {\n return this.repository.list<I, O>(params);\n }\n}\n\nexport const ListTasksUseCase = UseCaseAbstraction.createImplementation({\n implementation: ListTasksUseCaseImpl,\n dependencies: [TasksRepository]\n});\n"],"names":["ListTasksUseCaseImpl","repository","params","ListTasksUseCase","UseCaseAbstraction","TasksRepository"],"mappings":";;AAKA,MAAMA;IACF,YAAoCC,UAAqC,CAAE;aAAvCA,UAAU,GAAVA;IAAwC;IAE5E,MAAM,QAGJC,MAAkC,EAAmC;QACnE,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAOA;IACtC;AACJ;AAEO,MAAMC,oCAAmBC,iBAAAA,oBAAuC,CAAC;IACpE,gBAAgBJ;IAChB,cAAc;QAACK;KAAgB;AACnC"}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
+
import type { Result } from "@webiny/feature/api";
|
|
1
2
|
import { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
|
|
2
3
|
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
3
|
-
import type { IListTasksResponse
|
|
4
|
+
import type { IListTasksResponse } from "../../../api/types.js";
|
|
5
|
+
import type { IListTaskParams } from "../../../api/types.js";
|
|
6
|
+
import type { BackgroundTaskPersistenceError } from "../../../api/domain/errors.js";
|
|
7
|
+
type UseCaseError = BackgroundTaskPersistenceError;
|
|
4
8
|
export interface IListTasksUseCase {
|
|
5
|
-
execute<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskService.GenericOutput = TaskService.GenericOutput>(params?: ListTasksParams): Promise<IListTasksResponse<I, O>>;
|
|
9
|
+
execute<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskService.GenericOutput = TaskService.GenericOutput>(params?: ListTasksParams): Promise<Result<IListTasksResponse<I, O>, UseCaseError>>;
|
|
6
10
|
}
|
|
7
11
|
export type ListTasksParams = IListTaskParams;
|
|
8
12
|
export declare const ListTasksUseCase: import("@webiny/di").Abstraction<IListTasksUseCase>;
|
|
9
13
|
export declare namespace ListTasksUseCase {
|
|
10
14
|
type Interface = IListTasksUseCase;
|
|
11
15
|
type Params = ListTasksParams;
|
|
12
|
-
type
|
|
16
|
+
type Error = UseCaseError;
|
|
17
|
+
type Return<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskService.GenericOutput = TaskService.GenericOutput> = Promise<Result<IListTasksResponse<I, O>, UseCaseError>>;
|
|
13
18
|
}
|
|
19
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/features/ListTasks/abstractions.js","sources":["../../../../src/api/features/ListTasks/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport type { IListTasksResponse
|
|
1
|
+
{"version":3,"file":"api/features/ListTasks/abstractions.js","sources":["../../../../src/api/features/ListTasks/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport type { IListTasksResponse } from \"~/api/types.js\";\nimport type { IListTaskParams } from \"~/api/types.js\";\nimport type { BackgroundTaskPersistenceError } from \"~/api/domain/errors.js\";\n\ntype UseCaseError = BackgroundTaskPersistenceError;\n\nexport interface IListTasksUseCase {\n execute<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskService.GenericOutput = TaskService.GenericOutput\n >(\n params?: ListTasksParams\n ): Promise<Result<IListTasksResponse<I, O>, UseCaseError>>;\n}\n\nexport type ListTasksParams = IListTaskParams;\n\nexport const ListTasksUseCase = createAbstraction<IListTasksUseCase>(\"Tasks/ListTasksUseCase\");\n\nexport namespace ListTasksUseCase {\n export type Interface = IListTasksUseCase;\n export type Params = ListTasksParams;\n export type Error = UseCaseError;\n\n export type Return<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskService.GenericOutput = TaskService.GenericOutput\n > = Promise<Result<IListTasksResponse<I, O>, UseCaseError>>;\n}\n"],"names":["ListTasksUseCase","createAbstraction"],"mappings":";AAqBO,MAAMA,mBAAmBC,kBAAqC"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
|
-
import {
|
|
3
|
-
import { ListTasksUseCase } from "./abstractions.js";
|
|
4
|
-
import { TasksCrud } from "../../TasksCrud.js";
|
|
2
|
+
import { ListTasksUseCase } from "./ListTasksUseCase.js";
|
|
5
3
|
const ListTasksFeature = createFeature({
|
|
6
4
|
name: "ListTasks",
|
|
7
5
|
register (container) {
|
|
8
|
-
container.
|
|
6
|
+
container.register(ListTasksUseCase);
|
|
9
7
|
}
|
|
10
8
|
});
|
|
11
9
|
export { ListTasksFeature };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/features/ListTasks/feature.js","sources":["../../../../src/api/features/ListTasks/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport {
|
|
1
|
+
{"version":3,"file":"api/features/ListTasks/feature.js","sources":["../../../../src/api/features/ListTasks/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListTasksUseCase } from \"./ListTasksUseCase.js\";\n\nexport const ListTasksFeature = createFeature({\n name: \"ListTasks\",\n register(container) {\n container.register(ListTasksUseCase);\n }\n});\n"],"names":["ListTasksFeature","createFeature","container","ListTasksUseCase"],"mappings":";;AAGO,MAAMA,mBAAmBC,cAAc;IAC1C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ListVisibleTaskDefinitionsUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
2
|
+
import { ListTaskDefinitionsUseCase } from "../../../api/features/ListTaskDefinitions/abstractions.js";
|
|
3
|
+
declare class ListVisibleTaskDefinitionsUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
4
|
+
private readonly listTaskDefinitions;
|
|
5
|
+
constructor(listTaskDefinitions: ListTaskDefinitionsUseCase.Interface);
|
|
6
|
+
execute(): import("@webiny/api-core/features/task/TaskDefinition/abstractions.js").TaskDefinition.Interface<import("@webiny/api-core/features/task/TaskDefinition/abstractions.js").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions.js").ITaskOutput>[];
|
|
7
|
+
}
|
|
8
|
+
export declare const ListVisibleTaskDefinitionsUseCase: typeof ListVisibleTaskDefinitionsUseCaseImpl & {
|
|
9
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IListVisibleTaskDefinitionsUseCase>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ListVisibleTaskDefinitionsUseCase } from "./abstractions.js";
|
|
2
|
+
import { ListTaskDefinitionsUseCase } from "../ListTaskDefinitions/abstractions.js";
|
|
3
|
+
class ListVisibleTaskDefinitionsUseCaseImpl {
|
|
4
|
+
constructor(listTaskDefinitions){
|
|
5
|
+
this.listTaskDefinitions = listTaskDefinitions;
|
|
6
|
+
}
|
|
7
|
+
execute() {
|
|
8
|
+
return this.listTaskDefinitions.execute().filter((definition)=>!definition.isPrivate);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const ListVisibleTaskDefinitionsUseCase_ListVisibleTaskDefinitionsUseCase = ListVisibleTaskDefinitionsUseCase.createImplementation({
|
|
12
|
+
implementation: ListVisibleTaskDefinitionsUseCaseImpl,
|
|
13
|
+
dependencies: [
|
|
14
|
+
ListTaskDefinitionsUseCase
|
|
15
|
+
]
|
|
16
|
+
});
|
|
17
|
+
export { ListVisibleTaskDefinitionsUseCase_ListVisibleTaskDefinitionsUseCase as ListVisibleTaskDefinitionsUseCase };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=ListVisibleTaskDefinitionsUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/ListVisibleTaskDefinitions/ListVisibleTaskDefinitionsUseCase.js","sources":["../../../../src/api/features/ListVisibleTaskDefinitions/ListVisibleTaskDefinitionsUseCase.ts"],"sourcesContent":["import { ListVisibleTaskDefinitionsUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { ListTaskDefinitionsUseCase } from \"~/api/features/ListTaskDefinitions/abstractions.js\";\n\nclass ListVisibleTaskDefinitionsUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private readonly listTaskDefinitions: ListTaskDefinitionsUseCase.Interface\n ) {}\n\n public execute() {\n return this.listTaskDefinitions.execute().filter(definition => !definition.isPrivate);\n }\n}\n\nexport const ListVisibleTaskDefinitionsUseCase = UseCaseAbstraction.createImplementation({\n implementation: ListVisibleTaskDefinitionsUseCaseImpl,\n dependencies: [ListTaskDefinitionsUseCase]\n});\n"],"names":["ListVisibleTaskDefinitionsUseCaseImpl","listTaskDefinitions","definition","ListVisibleTaskDefinitionsUseCase","UseCaseAbstraction","ListTaskDefinitionsUseCase"],"mappings":";;AAGA,MAAMA;IACF,YACqBC,mBAAyD,CAC5E;aADmBA,mBAAmB,GAAnBA;IAClB;IAEI,UAAU;QACb,OAAO,IAAI,CAAC,mBAAmB,CAAC,OAAO,GAAG,MAAM,CAACC,CAAAA,aAAc,CAACA,WAAW,SAAS;IACxF;AACJ;AAEO,MAAMC,sEAAoCC,kCAAAA,oBAAuC,CAAC;IACrF,gBAAgBJ;IAChB,cAAc;QAACK;KAA2B;AAC9C"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
2
|
+
export interface IListVisibleTaskDefinitionsUseCase {
|
|
3
|
+
execute(): TaskDefinition.Interface[];
|
|
4
|
+
}
|
|
5
|
+
/** List task definitions for the GraphQL API, without the private ones. */
|
|
6
|
+
export declare const ListVisibleTaskDefinitionsUseCase: import("@webiny/di").Abstraction<IListVisibleTaskDefinitionsUseCase>;
|
|
7
|
+
export declare namespace ListVisibleTaskDefinitionsUseCase {
|
|
8
|
+
type Interface = IListVisibleTaskDefinitionsUseCase;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/ListVisibleTaskDefinitions/abstractions.js","sources":["../../../../src/api/features/ListVisibleTaskDefinitions/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\n\nexport interface IListVisibleTaskDefinitionsUseCase {\n execute(): TaskDefinition.Interface[];\n}\n\n/** List task definitions for the GraphQL API, without the private ones. */\nexport const ListVisibleTaskDefinitionsUseCase =\n createAbstraction<IListVisibleTaskDefinitionsUseCase>(\n \"Tasks/ListVisibleTaskDefinitionsUseCase\"\n );\n\nexport namespace ListVisibleTaskDefinitionsUseCase {\n export type Interface = IListVisibleTaskDefinitionsUseCase;\n}\n"],"names":["ListVisibleTaskDefinitionsUseCase","createAbstraction"],"mappings":";AAQO,MAAMA,oCACTC,kBACI"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { ListVisibleTaskDefinitionsUseCase } from "./ListVisibleTaskDefinitionsUseCase.js";
|
|
3
|
+
const ListVisibleTaskDefinitionsFeature = createFeature({
|
|
4
|
+
name: "ListVisibleTaskDefinitions",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(ListVisibleTaskDefinitionsUseCase);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { ListVisibleTaskDefinitionsFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/ListVisibleTaskDefinitions/feature.js","sources":["../../../../src/api/features/ListVisibleTaskDefinitions/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListVisibleTaskDefinitionsUseCase } from \"./ListVisibleTaskDefinitionsUseCase.js\";\n\nexport const ListVisibleTaskDefinitionsFeature = createFeature({\n name: \"ListVisibleTaskDefinitions\",\n register(container) {\n container.register(ListVisibleTaskDefinitionsUseCase);\n }\n});\n"],"names":["ListVisibleTaskDefinitionsFeature","createFeature","container","ListVisibleTaskDefinitionsUseCase"],"mappings":";;AAGO,MAAMA,oCAAoCC,cAAc;IAC3D,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { BaseError, Result } from "@webiny/feature/api";
|
|
2
|
+
import { Logger } from "@webiny/api-core/features/logger/index.js";
|
|
3
|
+
import { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
|
|
4
|
+
import type { IServiceInfo, ITaskAbortParams, ITaskTriggerParams } from "@webiny/api-core/features/task/TaskService/abstractions.js";
|
|
5
|
+
import { TaskService as TaskTransport } from "../../../api/domain/TaskService.js";
|
|
6
|
+
import { GetTaskUseCase } from "../../../api/features/GetTask/index.js";
|
|
7
|
+
import { CreateTaskLogUseCase } from "../../../api/features/CreateTaskLog/index.js";
|
|
8
|
+
import { GetLatestTaskLogUseCase } from "../../../api/features/GetLatestTaskLog/index.js";
|
|
9
|
+
import { UpdateTaskLogUseCase } from "../../../api/features/UpdateTaskLog/index.js";
|
|
10
|
+
import { CreateTaskUseCase } from "../../../api/features/CreateTask/index.js";
|
|
11
|
+
import { UpdateTaskUseCase } from "../../../api/features/UpdateTask/index.js";
|
|
12
|
+
import { DeleteTaskUseCase } from "../../../api/features/DeleteTask/index.js";
|
|
13
|
+
import { GetRunnableTaskDefinitionUseCase } from "../../../api/features/GetRunnableTaskDefinition/index.js";
|
|
14
|
+
type TaskInput = TaskService.TaskInput;
|
|
15
|
+
type TaskOutput = TaskService.GenericOutput;
|
|
16
|
+
/**
|
|
17
|
+
* The public TaskService: stores a task and hands it to the transport (Step Functions, the worker),
|
|
18
|
+
* aborts a running task, and reads what the transport knows about one. Every failure is returned,
|
|
19
|
+
* never thrown, so a caller that checks `isFail()` sees all of them.
|
|
20
|
+
*/
|
|
21
|
+
declare class BackgroundTaskServiceImpl implements TaskService.Interface {
|
|
22
|
+
private readonly getDefinition;
|
|
23
|
+
private readonly createTask;
|
|
24
|
+
private readonly updateTask;
|
|
25
|
+
private readonly deleteTask;
|
|
26
|
+
private readonly getTask;
|
|
27
|
+
private readonly getLatestTaskLog;
|
|
28
|
+
private readonly createTaskLog;
|
|
29
|
+
private readonly updateTaskLog;
|
|
30
|
+
private readonly transports;
|
|
31
|
+
private readonly logger;
|
|
32
|
+
constructor(getDefinition: GetRunnableTaskDefinitionUseCase.Interface, createTask: CreateTaskUseCase.Interface, updateTask: UpdateTaskUseCase.Interface, deleteTask: DeleteTaskUseCase.Interface, getTask: GetTaskUseCase.Interface, getLatestTaskLog: GetLatestTaskLogUseCase.Interface, createTaskLog: CreateTaskLogUseCase.Interface, updateTaskLog: UpdateTaskLogUseCase.Interface, transports: TaskTransport.Interface[], logger: Logger.Interface);
|
|
33
|
+
trigger<I extends TaskInput = TaskInput, O extends TaskOutput = TaskOutput>(params: ITaskTriggerParams<I>): Promise<Result<TaskService.Task<I, O>, BaseError<any>>>;
|
|
34
|
+
fetchServiceInfo(input: TaskService.Task | string): Promise<Result<IServiceInfo, BaseError<any>>>;
|
|
35
|
+
abort<I extends TaskInput = TaskInput, O extends TaskOutput = TaskOutput>(params: ITaskAbortParams): Promise<Result<TaskService.Task<I, O>, BaseError<any>>>;
|
|
36
|
+
private findTransport;
|
|
37
|
+
private getOrCreateLog;
|
|
38
|
+
}
|
|
39
|
+
export declare const BackgroundTaskService: typeof BackgroundTaskServiceImpl & {
|
|
40
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/task/TaskService/abstractions.js").ITaskService>;
|
|
41
|
+
};
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { Logger } from "@webiny/api-core/features/logger/index.js";
|
|
3
|
+
import { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
|
|
4
|
+
import { TaskService as TaskService_js_TaskService } from "../../domain/TaskService.js";
|
|
5
|
+
import { GetTaskUseCase } from "../GetTask/index.js";
|
|
6
|
+
import { CreateTaskLogUseCase } from "../CreateTaskLog/index.js";
|
|
7
|
+
import { GetLatestTaskLogUseCase } from "../GetLatestTaskLog/index.js";
|
|
8
|
+
import { UpdateTaskLogUseCase } from "../UpdateTaskLog/index.js";
|
|
9
|
+
import { CreateTaskUseCase } from "../CreateTask/index.js";
|
|
10
|
+
import { UpdateTaskUseCase } from "../UpdateTask/index.js";
|
|
11
|
+
import { DeleteTaskUseCase } from "../DeleteTask/index.js";
|
|
12
|
+
import { GetRunnableTaskDefinitionUseCase } from "../GetRunnableTaskDefinition/index.js";
|
|
13
|
+
import { TaskAbortError, TaskDefinitionNotFoundError, TaskServiceInfoError, TaskTriggerError } from "../../domain/errors.js";
|
|
14
|
+
import { TaskDataStatus, TaskLogItemType } from "../../types.js";
|
|
15
|
+
const MAX_DELAY_DAYS = 355;
|
|
16
|
+
const MAX_DELAY_SECONDS = 24 * MAX_DELAY_DAYS * 3600;
|
|
17
|
+
const isDelayTooLong = (delay)=>{
|
|
18
|
+
if (!delay || delay < 0 || false === Number.isInteger(delay)) return false;
|
|
19
|
+
return delay >= MAX_DELAY_SECONDS;
|
|
20
|
+
};
|
|
21
|
+
class BackgroundTaskServiceImpl {
|
|
22
|
+
constructor(getDefinition, createTask, updateTask, deleteTask, getTask, getLatestTaskLog, createTaskLog, updateTaskLog, transports, logger){
|
|
23
|
+
this.getDefinition = getDefinition;
|
|
24
|
+
this.createTask = createTask;
|
|
25
|
+
this.updateTask = updateTask;
|
|
26
|
+
this.deleteTask = deleteTask;
|
|
27
|
+
this.getTask = getTask;
|
|
28
|
+
this.getLatestTaskLog = getLatestTaskLog;
|
|
29
|
+
this.createTaskLog = createTaskLog;
|
|
30
|
+
this.updateTaskLog = updateTaskLog;
|
|
31
|
+
this.transports = transports;
|
|
32
|
+
this.logger = logger;
|
|
33
|
+
}
|
|
34
|
+
async trigger(params) {
|
|
35
|
+
const { definition: id, input: inputValues, name, parent, delay = 0 } = params;
|
|
36
|
+
const transport = this.findTransport();
|
|
37
|
+
if (!transport) return Result.fail(new TaskTriggerError({
|
|
38
|
+
message: "Missing TaskService.",
|
|
39
|
+
definitionId: id
|
|
40
|
+
}));
|
|
41
|
+
const definitionResult = this.getDefinition.execute(id);
|
|
42
|
+
if (definitionResult.isFail()) return Result.fail(new TaskDefinitionNotFoundError(id));
|
|
43
|
+
const definition = definitionResult.value;
|
|
44
|
+
const input = {
|
|
45
|
+
name: name || definition.title,
|
|
46
|
+
definitionId: id,
|
|
47
|
+
input: inputValues || {},
|
|
48
|
+
parentId: parent?.id
|
|
49
|
+
};
|
|
50
|
+
if (definition.onBeforeTrigger) try {
|
|
51
|
+
await definition.onBeforeTrigger({
|
|
52
|
+
data: input,
|
|
53
|
+
definition
|
|
54
|
+
});
|
|
55
|
+
} catch (ex) {
|
|
56
|
+
const error = TaskTriggerError.from(ex, id);
|
|
57
|
+
return Result.fail(error);
|
|
58
|
+
}
|
|
59
|
+
if (isDelayTooLong(delay)) return Result.fail(new TaskTriggerError({
|
|
60
|
+
message: `The maximum delay for a task is ${MAX_DELAY_DAYS} days.`,
|
|
61
|
+
definitionId: id
|
|
62
|
+
}));
|
|
63
|
+
const created = await this.createTask.execute(input).catch((ex)=>Result.fail(TaskTriggerError.from(ex, id)));
|
|
64
|
+
if (created.isFail()) {
|
|
65
|
+
this.logger.error({
|
|
66
|
+
error: created.error
|
|
67
|
+
}, "Could not create the task.");
|
|
68
|
+
return Result.fail(created.error);
|
|
69
|
+
}
|
|
70
|
+
const task = created.value;
|
|
71
|
+
let response = null;
|
|
72
|
+
try {
|
|
73
|
+
response = await transport.send(task, delay);
|
|
74
|
+
} catch (ex) {
|
|
75
|
+
this.logger.error({
|
|
76
|
+
error: ex
|
|
77
|
+
}, "Could not trigger the step function.");
|
|
78
|
+
await this.deleteTask.execute(task.id);
|
|
79
|
+
const error = TaskTriggerError.from(ex, id);
|
|
80
|
+
return Result.fail(error);
|
|
81
|
+
}
|
|
82
|
+
if (!response) {
|
|
83
|
+
this.logger.error({
|
|
84
|
+
task
|
|
85
|
+
}, "Could not trigger the step function.");
|
|
86
|
+
await this.deleteTask.execute(task.id);
|
|
87
|
+
return Result.fail(new TaskTriggerError({
|
|
88
|
+
message: "Could not trigger the step function!",
|
|
89
|
+
definitionId: id
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
const eventResponse = response;
|
|
93
|
+
const updated = await this.updateTask.execute(task.id, {
|
|
94
|
+
eventResponse
|
|
95
|
+
});
|
|
96
|
+
if (updated.isFail()) {
|
|
97
|
+
this.logger.error({
|
|
98
|
+
error: updated.error,
|
|
99
|
+
id: task.id
|
|
100
|
+
}, "Could not store the task's event response.");
|
|
101
|
+
const queued = {
|
|
102
|
+
...task,
|
|
103
|
+
eventResponse
|
|
104
|
+
};
|
|
105
|
+
return Result.ok(queued);
|
|
106
|
+
}
|
|
107
|
+
return updated;
|
|
108
|
+
}
|
|
109
|
+
async fetchServiceInfo(input) {
|
|
110
|
+
const transport = this.findTransport();
|
|
111
|
+
if (!transport) return Result.fail(new TaskServiceInfoError());
|
|
112
|
+
let task;
|
|
113
|
+
if ("object" == typeof input) task = input;
|
|
114
|
+
else {
|
|
115
|
+
const taskResult = await this.getTask.execute(input);
|
|
116
|
+
if (taskResult.isFail()) return Result.fail(taskResult.error);
|
|
117
|
+
task = taskResult.value;
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const info = await transport.fetch(task);
|
|
121
|
+
if (info) return Result.ok(info);
|
|
122
|
+
return Result.fail(new TaskServiceInfoError());
|
|
123
|
+
} catch (ex) {
|
|
124
|
+
this.logger.error({
|
|
125
|
+
error: ex
|
|
126
|
+
}, "Service fetch error.");
|
|
127
|
+
return Result.fail(new TaskServiceInfoError());
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async abort(params) {
|
|
131
|
+
const taskResult = await this.getTask.execute(params.id);
|
|
132
|
+
if (taskResult.isFail()) return Result.fail(taskResult.error);
|
|
133
|
+
const task = taskResult.value;
|
|
134
|
+
const definitionResult = this.getDefinition.execute(task.definitionId);
|
|
135
|
+
if (definitionResult.isFail()) return Result.fail(new TaskDefinitionNotFoundError(task.definitionId));
|
|
136
|
+
const definition = definitionResult.value;
|
|
137
|
+
if (false === [
|
|
138
|
+
TaskDataStatus.PENDING,
|
|
139
|
+
TaskDataStatus.RUNNING
|
|
140
|
+
].includes(task.taskStatus)) return Result.fail(new TaskAbortError({
|
|
141
|
+
id: params.id,
|
|
142
|
+
status: task.taskStatus
|
|
143
|
+
}));
|
|
144
|
+
const taskLog = await this.getOrCreateLog(task);
|
|
145
|
+
if (taskLog.isFail()) return Result.fail(taskLog.error);
|
|
146
|
+
const updated = await this.updateTask.execute(task.id, {
|
|
147
|
+
taskStatus: TaskDataStatus.ABORTED
|
|
148
|
+
});
|
|
149
|
+
if (updated.isFail()) return Result.fail(updated.error);
|
|
150
|
+
const items = taskLog.value.items.concat([
|
|
151
|
+
{
|
|
152
|
+
message: params.message || "Task aborted.",
|
|
153
|
+
type: TaskLogItemType.INFO,
|
|
154
|
+
createdOn: new Date().toISOString()
|
|
155
|
+
}
|
|
156
|
+
]);
|
|
157
|
+
const logUpdate = await this.updateTaskLog.execute(taskLog.value.id, {
|
|
158
|
+
items
|
|
159
|
+
});
|
|
160
|
+
if (logUpdate.isFail()) this.logger.error({
|
|
161
|
+
error: logUpdate.error,
|
|
162
|
+
id: task.id
|
|
163
|
+
}, "Could not write the abort to the task log.");
|
|
164
|
+
if (definition.onAbort) try {
|
|
165
|
+
await definition.onAbort({
|
|
166
|
+
task: updated.value,
|
|
167
|
+
definition
|
|
168
|
+
});
|
|
169
|
+
} catch (ex) {
|
|
170
|
+
this.logger.error({
|
|
171
|
+
error: ex,
|
|
172
|
+
id: task.id
|
|
173
|
+
}, "The task's onAbort hook failed.");
|
|
174
|
+
}
|
|
175
|
+
return Result.ok(updated.value);
|
|
176
|
+
}
|
|
177
|
+
findTransport() {
|
|
178
|
+
return this.transports[this.transports.length - 1];
|
|
179
|
+
}
|
|
180
|
+
async getOrCreateLog(task) {
|
|
181
|
+
const latest = await this.getLatestTaskLog.execute(task.id);
|
|
182
|
+
if (latest.isOk()) return latest;
|
|
183
|
+
return await this.createTaskLog.execute(task, {
|
|
184
|
+
iteration: 1,
|
|
185
|
+
executionName: task.executionName
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const BackgroundTaskService = TaskService.createImplementation({
|
|
190
|
+
implementation: BackgroundTaskServiceImpl,
|
|
191
|
+
dependencies: [
|
|
192
|
+
GetRunnableTaskDefinitionUseCase,
|
|
193
|
+
CreateTaskUseCase,
|
|
194
|
+
UpdateTaskUseCase,
|
|
195
|
+
DeleteTaskUseCase,
|
|
196
|
+
GetTaskUseCase,
|
|
197
|
+
GetLatestTaskLogUseCase,
|
|
198
|
+
CreateTaskLogUseCase,
|
|
199
|
+
UpdateTaskLogUseCase,
|
|
200
|
+
[
|
|
201
|
+
TaskService_js_TaskService,
|
|
202
|
+
{
|
|
203
|
+
multiple: true
|
|
204
|
+
}
|
|
205
|
+
],
|
|
206
|
+
Logger
|
|
207
|
+
]
|
|
208
|
+
});
|
|
209
|
+
export { BackgroundTaskService };
|
|
210
|
+
|
|
211
|
+
//# sourceMappingURL=BackgroundTaskService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/TaskService/BackgroundTaskService.js","sources":["../../../../src/api/features/TaskService/BackgroundTaskService.ts"],"sourcesContent":["import { BaseError, Result } from \"@webiny/feature/api\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport type {\n IServiceInfo,\n ITaskAbortParams,\n ITaskTriggerParams\n} from \"@webiny/api-core/features/task/TaskService/abstractions.js\";\nimport type { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { TaskService as TaskTransport } from \"~/api/domain/TaskService.js\";\nimport { GetTaskUseCase } from \"~/api/features/GetTask/index.js\";\nimport { CreateTaskLogUseCase } from \"~/api/features/CreateTaskLog/index.js\";\nimport { GetLatestTaskLogUseCase } from \"~/api/features/GetLatestTaskLog/index.js\";\nimport { UpdateTaskLogUseCase } from \"~/api/features/UpdateTaskLog/index.js\";\nimport { CreateTaskUseCase } from \"~/api/features/CreateTask/index.js\";\nimport { UpdateTaskUseCase } from \"~/api/features/UpdateTask/index.js\";\nimport { DeleteTaskUseCase } from \"~/api/features/DeleteTask/index.js\";\nimport { GetRunnableTaskDefinitionUseCase } from \"~/api/features/GetRunnableTaskDefinition/index.js\";\nimport {\n TaskAbortError,\n TaskDefinitionNotFoundError,\n TaskServiceInfoError\n} from \"~/api/domain/errors.js\";\nimport { TaskTriggerError } from \"~/api/domain/errors.js\";\nimport { TaskDataStatus, TaskLogItemType } from \"~/api/types.js\";\nimport type { ITaskLog } from \"~/api/types.js\";\n\ntype TaskInput = TaskService.TaskInput;\ntype TaskOutput = TaskService.GenericOutput;\n\nconst MAX_DELAY_DAYS = 355;\nconst MAX_DELAY_SECONDS = MAX_DELAY_DAYS * 24 * 60 * 60;\n\n// A delay that isn't a positive whole number is ignored, so only a too long one is rejected.\nconst isDelayTooLong = (delay: number): boolean => {\n if (!delay || delay < 0 || Number.isInteger(delay) === false) {\n return false;\n }\n return delay >= MAX_DELAY_SECONDS;\n};\n\n/**\n * The public TaskService: stores a task and hands it to the transport (Step Functions, the worker),\n * aborts a running task, and reads what the transport knows about one. Every failure is returned,\n * never thrown, so a caller that checks `isFail()` sees all of them.\n */\nclass BackgroundTaskServiceImpl implements TaskService.Interface {\n constructor(\n private readonly getDefinition: GetRunnableTaskDefinitionUseCase.Interface,\n private readonly createTask: CreateTaskUseCase.Interface,\n private readonly updateTask: UpdateTaskUseCase.Interface,\n private readonly deleteTask: DeleteTaskUseCase.Interface,\n private readonly getTask: GetTaskUseCase.Interface,\n private readonly getLatestTaskLog: GetLatestTaskLogUseCase.Interface,\n private readonly createTaskLog: CreateTaskLogUseCase.Interface,\n private readonly updateTaskLog: UpdateTaskLogUseCase.Interface,\n private readonly transports: TaskTransport.Interface[],\n private readonly logger: Logger.Interface\n ) {}\n\n async trigger<I extends TaskInput = TaskInput, O extends TaskOutput = TaskOutput>(\n params: ITaskTriggerParams<I>\n ): Promise<Result<TaskService.Task<I, O>, BaseError<any>>> {\n const { definition: id, input: inputValues, name, parent, delay = 0 } = params;\n const transport = this.findTransport();\n if (!transport) {\n return Result.fail(\n new TaskTriggerError({ message: \"Missing TaskService.\", definitionId: id })\n );\n }\n const definitionResult = this.getDefinition.execute(id);\n if (definitionResult.isFail()) {\n return Result.fail(new TaskDefinitionNotFoundError(id));\n }\n const definition = definitionResult.value;\n const input: TaskDefinition.TaskCreateData<I> = {\n name: name || definition.title,\n definitionId: id,\n input: inputValues || ({} as I),\n parentId: parent?.id\n };\n\n if (definition.onBeforeTrigger) {\n try {\n await definition.onBeforeTrigger({ data: input, definition });\n } catch (ex) {\n const error = TaskTriggerError.from(ex, id);\n return Result.fail(error);\n }\n }\n if (isDelayTooLong(delay)) {\n return Result.fail(\n new TaskTriggerError({\n message: `The maximum delay for a task is ${MAX_DELAY_DAYS} days.`,\n definitionId: id\n })\n );\n }\n\n // A task event handler can throw. That would reject the trigger, so it becomes a failure.\n const created = await this.createTask\n .execute<I>(input)\n .catch((ex: unknown) => Result.fail(TaskTriggerError.from(ex, id)));\n if (created.isFail()) {\n this.logger.error({ error: created.error }, \"Could not create the task.\");\n return Result.fail(created.error);\n }\n const task = created.value;\n\n let response: unknown = null;\n try {\n response = await transport.send(task, delay);\n } catch (ex) {\n this.logger.error({ error: ex }, \"Could not trigger the step function.\");\n // The task can't run, so don't leave it behind as pending.\n await this.deleteTask.execute(task.id);\n const error = TaskTriggerError.from(ex, id);\n return Result.fail(error);\n }\n if (!response) {\n this.logger.error({ task }, \"Could not trigger the step function.\");\n await this.deleteTask.execute(task.id);\n return Result.fail(\n new TaskTriggerError({\n message: \"Could not trigger the step function!\",\n definitionId: id\n })\n );\n }\n\n const eventResponse = response as Record<string, any>;\n const updated = await this.updateTask.execute<I, O>(task.id, { eventResponse });\n if (updated.isFail()) {\n // The transport has the task and will run it, so this is not a failed trigger. Only the\n // stored event response is missing.\n this.logger.error(\n { error: updated.error, id: task.id },\n \"Could not store the task's event response.\"\n );\n // A task that was just created has no output yet, so it fits any output type.\n const queued = { ...task, eventResponse } as TaskService.Task<I, O>;\n return Result.ok(queued);\n }\n\n return updated;\n }\n\n async fetchServiceInfo(\n input: TaskService.Task | string\n ): Promise<Result<IServiceInfo, BaseError<any>>> {\n const transport = this.findTransport();\n if (!transport) {\n return Result.fail(new TaskServiceInfoError());\n }\n let task: TaskService.Task;\n if (typeof input === \"object\") {\n task = input;\n } else {\n const taskResult = await this.getTask.execute(input);\n if (taskResult.isFail()) {\n return Result.fail(taskResult.error);\n }\n task = taskResult.value;\n }\n\n try {\n const info = (await transport.fetch(task)) as IServiceInfo | null;\n if (info) {\n return Result.ok(info);\n }\n return Result.fail(new TaskServiceInfoError());\n } catch (ex) {\n this.logger.error({ error: ex }, \"Service fetch error.\");\n return Result.fail(new TaskServiceInfoError());\n }\n }\n\n async abort<I extends TaskInput = TaskInput, O extends TaskOutput = TaskOutput>(\n params: ITaskAbortParams\n ): Promise<Result<TaskService.Task<I, O>, BaseError<any>>> {\n const taskResult = await this.getTask.execute<I, O>(params.id);\n if (taskResult.isFail()) {\n return Result.fail(taskResult.error);\n }\n const task = taskResult.value;\n\n const definitionResult = this.getDefinition.execute<I, O>(task.definitionId);\n if (definitionResult.isFail()) {\n return Result.fail(new TaskDefinitionNotFoundError(task.definitionId));\n }\n const definition = definitionResult.value;\n\n // Only a pending or running task can be aborted.\n if ([TaskDataStatus.PENDING, TaskDataStatus.RUNNING].includes(task.taskStatus) === false) {\n return Result.fail(new TaskAbortError({ id: params.id, status: task.taskStatus }));\n }\n\n const taskLog = await this.getOrCreateLog(task);\n if (taskLog.isFail()) {\n return Result.fail(taskLog.error);\n }\n const updated = await this.updateTask.execute<I, O>(task.id, {\n taskStatus: TaskDataStatus.ABORTED\n });\n if (updated.isFail()) {\n return Result.fail(updated.error);\n }\n const items = taskLog.value.items.concat([\n {\n message: params.message || \"Task aborted.\",\n type: TaskLogItemType.INFO,\n createdOn: new Date().toISOString()\n }\n ]);\n const logUpdate = await this.updateTaskLog.execute(taskLog.value.id, { items });\n if (logUpdate.isFail()) {\n // The task is aborted by now, so a missing log entry must not skip the onAbort hook.\n this.logger.error(\n { error: logUpdate.error, id: task.id },\n \"Could not write the abort to the task log.\"\n );\n }\n // TODO: determine when to kick off the onAbort hook\n if (definition.onAbort) {\n // The task is aborted by now, so a failing hook is logged and doesn't undo that.\n try {\n await definition.onAbort({ task: updated.value, definition });\n } catch (ex) {\n this.logger.error({ error: ex, id: task.id }, \"The task's onAbort hook failed.\");\n }\n }\n\n return Result.ok(updated.value);\n }\n\n private findTransport(): TaskTransport.Interface | undefined {\n // The last registration wins, so a test or a deployment can swap the transport.\n return this.transports[this.transports.length - 1];\n }\n\n private async getOrCreateLog(\n task: TaskService.Task<any, any>\n ): Promise<Result<ITaskLog, BaseError<any>>> {\n const latest = await this.getLatestTaskLog.execute(task.id);\n if (latest.isOk()) {\n return latest;\n }\n return await this.createTaskLog.execute(task, {\n iteration: 1,\n executionName: task.executionName\n });\n }\n}\n\nexport const BackgroundTaskService = TaskService.createImplementation({\n implementation: BackgroundTaskServiceImpl,\n dependencies: [\n GetRunnableTaskDefinitionUseCase,\n CreateTaskUseCase,\n UpdateTaskUseCase,\n DeleteTaskUseCase,\n GetTaskUseCase,\n GetLatestTaskLogUseCase,\n CreateTaskLogUseCase,\n UpdateTaskLogUseCase,\n [TaskTransport, { multiple: true }],\n Logger\n ]\n});\n"],"names":["MAX_DELAY_DAYS","MAX_DELAY_SECONDS","isDelayTooLong","delay","Number","BackgroundTaskServiceImpl","getDefinition","createTask","updateTask","deleteTask","getTask","getLatestTaskLog","createTaskLog","updateTaskLog","transports","logger","params","id","inputValues","name","parent","transport","Result","TaskTriggerError","definitionResult","TaskDefinitionNotFoundError","definition","input","ex","error","created","task","response","eventResponse","updated","queued","TaskServiceInfoError","taskResult","info","TaskDataStatus","TaskAbortError","taskLog","items","TaskLogItemType","Date","logUpdate","latest","BackgroundTaskService","TaskService","GetRunnableTaskDefinitionUseCase","CreateTaskUseCase","UpdateTaskUseCase","DeleteTaskUseCase","GetTaskUseCase","GetLatestTaskLogUseCase","CreateTaskLogUseCase","UpdateTaskLogUseCase","TaskTransport","Logger"],"mappings":";;;;;;;;;;;;;;AA8BA,MAAMA,iBAAiB;AACvB,MAAMC,oBAAoBD,AAAiB,KAAjBA,iBAAAA;AAG1B,MAAME,iBAAiB,CAACC;IACpB,IAAI,CAACA,SAASA,QAAQ,KAAKC,AAA4B,UAA5BA,OAAO,SAAS,CAACD,QACxC,OAAO;IAEX,OAAOA,SAASF;AAC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D;IAEA,MAAc,eACVH,IAAgC,EACS;QACzC,MAAMe,SAAS,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAACf,KAAK,EAAE;QAC1D,IAAIe,OAAO,IAAI,IACX,OAAOA;QAEX,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAACf,MAAM;YAC1C,WAAW;YACX,eAAeA,KAAK,aAAa;QACrC;IACJ;AACJ;AAEO,MAAMgB,wBAAwBC,YAAY,oBAAoB,CAAC;IAClE,gBAAgB3C;IAChB,cAAc;QACV4C;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACA;YAACC;YAAe;gBAAE,UAAU;YAAK;SAAE;QACnCC;KACH;AACL"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { BackgroundTaskService } from "./BackgroundTaskService.js";
|
|
3
|
+
const BackgroundTaskServiceFeature = createFeature({
|
|
4
|
+
name: "BackgroundTaskService",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(BackgroundTaskService);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { BackgroundTaskServiceFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/TaskService/feature.js","sources":["../../../../src/api/features/TaskService/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { BackgroundTaskService } from \"./BackgroundTaskService.js\";\n\nexport const BackgroundTaskServiceFeature = createFeature({\n name: \"BackgroundTaskService\",\n register(container) {\n container.register(BackgroundTaskService);\n }\n});\n"],"names":["BackgroundTaskServiceFeature","createFeature","container","BackgroundTaskService"],"mappings":";;AAGO,MAAMA,+BAA+BC,cAAc;IACtD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BackgroundTaskServiceFeature } from "./feature.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BackgroundTaskServiceFeature } from "./feature.js";
|
|
@@ -2,6 +2,9 @@ import { Result } from "@webiny/feature/api";
|
|
|
2
2
|
import { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
|
|
3
3
|
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
4
4
|
import { TaskDefinitionNotFoundError, TaskNotFoundError, TaskServiceInfoError } from "../../../api/domain/errors.js";
|
|
5
|
+
import { TaskTriggerError } from "../../../api/domain/errors.js";
|
|
6
|
+
import { TaskInputValidationError } from "../../../api/domain/errors.js";
|
|
7
|
+
import { BackgroundTaskPersistenceError } from "../../../api/domain/errors.js";
|
|
5
8
|
export interface ITriggerTaskUseCase {
|
|
6
9
|
execute<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskService.GenericOutput = TaskService.GenericOutput>(params: TriggerTaskParams<I>): Promise<Result<TaskService.Task<I, O>, UseCaseError>>;
|
|
7
10
|
}
|
|
@@ -16,6 +19,9 @@ export interface ITriggerTaskUseCaseErrors {
|
|
|
16
19
|
definitionNotFound: TaskDefinitionNotFoundError;
|
|
17
20
|
taskNotFound: TaskNotFoundError;
|
|
18
21
|
serviceError: TaskServiceInfoError;
|
|
22
|
+
triggerError: TaskTriggerError;
|
|
23
|
+
validation: TaskInputValidationError;
|
|
24
|
+
persistence: BackgroundTaskPersistenceError;
|
|
19
25
|
}
|
|
20
26
|
type UseCaseError = ITriggerTaskUseCaseErrors[keyof ITriggerTaskUseCaseErrors];
|
|
21
27
|
export declare const TriggerTaskUseCase: import("@webiny/di").Abstraction<ITriggerTaskUseCase>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/features/TriggerTask/abstractions.js","sources":["../../../../src/api/features/TriggerTask/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport {\n TaskDefinitionNotFoundError,\n TaskNotFoundError,\n TaskServiceInfoError\n} from \"~/api/domain/errors.js\";\n\nexport interface ITriggerTaskUseCase {\n execute<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskService.GenericOutput = TaskService.GenericOutput\n >(\n params: TriggerTaskParams<I>\n ): Promise<Result<TaskService.Task<I, O>, UseCaseError>>;\n}\n\nexport interface TriggerTaskParams<I = TaskDefinition.TaskInput> {\n definition: string;\n input?: I;\n name?: string;\n parent?: Pick<TaskService.Task, \"id\">;\n delay?: number;\n}\n\nexport interface ITriggerTaskUseCaseErrors {\n definitionNotFound: TaskDefinitionNotFoundError;\n taskNotFound: TaskNotFoundError;\n serviceError: TaskServiceInfoError;\n}\n\ntype UseCaseError = ITriggerTaskUseCaseErrors[keyof ITriggerTaskUseCaseErrors];\n\nexport const TriggerTaskUseCase = createAbstraction<ITriggerTaskUseCase>(\n \"Tasks/TriggerTaskUseCase\"\n);\n\nexport namespace TriggerTaskUseCase {\n export type Interface = ITriggerTaskUseCase;\n export type Params<I = TaskDefinition.TaskInput> = TriggerTaskParams<I>;\n\n export type Error = UseCaseError;\n export type Return<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskService.GenericOutput = TaskService.GenericOutput\n > = Promise<Result<TaskService.Task<I, O>, UseCaseError>>;\n}\n"],"names":["TriggerTaskUseCase","createAbstraction"],"mappings":";
|
|
1
|
+
{"version":3,"file":"api/features/TriggerTask/abstractions.js","sources":["../../../../src/api/features/TriggerTask/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport {\n TaskDefinitionNotFoundError,\n TaskNotFoundError,\n TaskServiceInfoError\n} from \"~/api/domain/errors.js\";\nimport { TaskTriggerError } from \"~/api/domain/errors.js\";\nimport { TaskInputValidationError } from \"~/api/domain/errors.js\";\nimport { BackgroundTaskPersistenceError } from \"~/api/domain/errors.js\";\n\nexport interface ITriggerTaskUseCase {\n execute<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskService.GenericOutput = TaskService.GenericOutput\n >(\n params: TriggerTaskParams<I>\n ): Promise<Result<TaskService.Task<I, O>, UseCaseError>>;\n}\n\nexport interface TriggerTaskParams<I = TaskDefinition.TaskInput> {\n definition: string;\n input?: I;\n name?: string;\n parent?: Pick<TaskService.Task, \"id\">;\n delay?: number;\n}\n\nexport interface ITriggerTaskUseCaseErrors {\n definitionNotFound: TaskDefinitionNotFoundError;\n taskNotFound: TaskNotFoundError;\n serviceError: TaskServiceInfoError;\n triggerError: TaskTriggerError;\n validation: TaskInputValidationError;\n persistence: BackgroundTaskPersistenceError;\n}\n\ntype UseCaseError = ITriggerTaskUseCaseErrors[keyof ITriggerTaskUseCaseErrors];\n\nexport const TriggerTaskUseCase = createAbstraction<ITriggerTaskUseCase>(\n \"Tasks/TriggerTaskUseCase\"\n);\n\nexport namespace TriggerTaskUseCase {\n export type Interface = ITriggerTaskUseCase;\n export type Params<I = TaskDefinition.TaskInput> = TriggerTaskParams<I>;\n\n export type Error = UseCaseError;\n export type Return<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskService.GenericOutput = TaskService.GenericOutput\n > = Promise<Result<TaskService.Task<I, O>, UseCaseError>>;\n}\n"],"names":["TriggerTaskUseCase","createAbstraction"],"mappings":";AAwCO,MAAMA,qBAAqBC,kBAC9B"}
|