@webiny/tasks 0.0.0-unstable.6f45466a1d → 0.0.0-unstable.7be00a75a9
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/context.js +38 -37
- package/context.js.map +1 -1
- package/crud/TaskLogPrivateModel.js +33 -24
- package/crud/TaskLogPrivateModel.js.map +1 -1
- package/crud/TaskPrivateModel.js +48 -36
- package/crud/TaskPrivateModel.js.map +1 -1
- package/crud/cleanupTaskSubtree.d.ts +8 -0
- package/crud/cleanupTaskSubtree.js +62 -0
- package/crud/cleanupTaskSubtree.js.map +1 -0
- package/crud/crud.tasks.js +292 -352
- package/crud/crud.tasks.js.map +1 -1
- package/crud/definition.tasks.js +13 -16
- package/crud/definition.tasks.js.map +1 -1
- package/crud/service.tasks.js +119 -155
- package/crud/service.tasks.js.map +1 -1
- package/decorators/RunnableTaskDecorator.d.ts +4 -3
- package/decorators/RunnableTaskDecorator.js +61 -74
- package/decorators/RunnableTaskDecorator.js.map +1 -1
- package/decorators/SelfCleaningTaskDecorator.d.ts +30 -0
- package/decorators/SelfCleaningTaskDecorator.js +84 -0
- package/decorators/SelfCleaningTaskDecorator.js.map +1 -0
- package/domain/errors.js +35 -39
- package/domain/errors.js.map +1 -1
- package/events/TaskAfterCreateEvent.d.ts +2 -2
- package/events/TaskAfterCreateEvent.js +10 -7
- package/events/TaskAfterCreateEvent.js.map +1 -1
- package/events/TaskAfterDeleteEvent.d.ts +2 -2
- package/events/TaskAfterDeleteEvent.js +10 -7
- package/events/TaskAfterDeleteEvent.js.map +1 -1
- package/events/TaskAfterUpdateEvent.d.ts +2 -2
- package/events/TaskAfterUpdateEvent.js +10 -7
- package/events/TaskAfterUpdateEvent.js.map +1 -1
- package/events/TaskBeforeCreateEvent.d.ts +2 -2
- package/events/TaskBeforeCreateEvent.js +10 -7
- package/events/TaskBeforeCreateEvent.js.map +1 -1
- package/events/TaskBeforeDeleteEvent.d.ts +2 -2
- package/events/TaskBeforeDeleteEvent.js +10 -7
- package/events/TaskBeforeDeleteEvent.js.map +1 -1
- package/events/TaskBeforeUpdateEvent.d.ts +2 -2
- package/events/TaskBeforeUpdateEvent.js +10 -7
- package/events/TaskBeforeUpdateEvent.js.map +1 -1
- package/events/abstractions.d.ts +13 -13
- package/events/abstractions.js +7 -36
- package/events/abstractions.js.map +1 -1
- package/events/index.js +0 -2
- package/features/AbortTask/AbortTaskUseCase.js +9 -8
- package/features/AbortTask/AbortTaskUseCase.js.map +1 -1
- package/features/AbortTask/abstractions.js +2 -1
- package/features/AbortTask/abstractions.js.map +1 -1
- package/features/AbortTask/feature.d.ts +4 -1
- package/features/AbortTask/feature.js +6 -5
- package/features/AbortTask/feature.js.map +1 -1
- package/features/AbortTask/index.js +0 -2
- package/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.d.ts +7 -0
- package/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js +11 -0
- package/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js.map +1 -0
- package/features/CleanupTaskSubtree/abstractions.d.ts +7 -0
- package/features/CleanupTaskSubtree/abstractions.js +5 -0
- package/features/CleanupTaskSubtree/abstractions.js.map +1 -0
- package/features/CleanupTaskSubtree/index.d.ts +2 -0
- package/features/CleanupTaskSubtree/index.js +2 -0
- package/features/GetTask/GetTaskUseCase.js +8 -7
- package/features/GetTask/GetTaskUseCase.js.map +1 -1
- package/features/GetTask/abstractions.js +2 -1
- package/features/GetTask/abstractions.js.map +1 -1
- package/features/GetTask/feature.d.ts +4 -1
- package/features/GetTask/feature.js +6 -5
- package/features/GetTask/feature.js.map +1 -1
- package/features/GetTask/index.js +0 -2
- package/features/GetTaskDefinition/GetTaskDefinitionUseCase.js +18 -16
- package/features/GetTaskDefinition/GetTaskDefinitionUseCase.js.map +1 -1
- package/features/GetTaskDefinition/abstractions.js +2 -1
- package/features/GetTaskDefinition/abstractions.js.map +1 -1
- package/features/GetTaskDefinition/feature.d.ts +4 -1
- package/features/GetTaskDefinition/feature.js +6 -5
- package/features/GetTaskDefinition/feature.js.map +1 -1
- package/features/GetTaskDefinition/index.js +0 -2
- package/features/ListTaskDefinitions/ListTaskDefinitionsUseCase.js +18 -12
- package/features/ListTaskDefinitions/ListTaskDefinitionsUseCase.js.map +1 -1
- package/features/ListTaskDefinitions/abstractions.js +2 -1
- package/features/ListTaskDefinitions/abstractions.js.map +1 -1
- package/features/ListTaskDefinitions/feature.d.ts +4 -1
- package/features/ListTaskDefinitions/feature.js +6 -5
- package/features/ListTaskDefinitions/feature.js.map +1 -1
- package/features/ListTaskDefinitions/index.js +0 -2
- package/features/ListTasks/ListTasksUseCase.js +8 -7
- package/features/ListTasks/ListTasksUseCase.js.map +1 -1
- package/features/ListTasks/abstractions.js +2 -1
- package/features/ListTasks/abstractions.js.map +1 -1
- package/features/ListTasks/feature.d.ts +4 -1
- package/features/ListTasks/feature.js +6 -5
- package/features/ListTasks/feature.js.map +1 -1
- package/features/ListTasks/index.js +0 -2
- package/features/TaskController/TaskController.js +60 -60
- package/features/TaskController/TaskController.js.map +1 -1
- package/features/TaskController/augmentation.js +0 -3
- package/features/TaskController/index.js +0 -5
- package/features/TaskExecutionContext/TaskExecutionContext.js +38 -45
- package/features/TaskExecutionContext/TaskExecutionContext.js.map +1 -1
- package/features/TaskExecutionContext/abstractions.js +2 -10
- package/features/TaskExecutionContext/abstractions.js.map +1 -1
- package/features/TaskExecutionContext/feature.d.ts +4 -1
- package/features/TaskExecutionContext/feature.js +6 -5
- package/features/TaskExecutionContext/feature.js.map +1 -1
- package/features/TaskExecutionContext/index.js +0 -2
- package/features/TriggerTask/TriggerTaskUseCase.js +9 -8
- package/features/TriggerTask/TriggerTaskUseCase.js.map +1 -1
- package/features/TriggerTask/abstractions.js +2 -1
- package/features/TriggerTask/abstractions.js.map +1 -1
- package/features/TriggerTask/feature.d.ts +4 -1
- package/features/TriggerTask/feature.js +6 -5
- package/features/TriggerTask/feature.js.map +1 -1
- package/features/TriggerTask/index.js +0 -2
- package/global.js +0 -2
- package/graphql/checkPermissions.js +16 -35
- package/graphql/checkPermissions.js.map +1 -1
- package/graphql/index.js +156 -202
- package/graphql/index.js.map +1 -1
- package/graphql/utils.js +15 -14
- package/graphql/utils.js.map +1 -1
- package/handler/index.js +46 -53
- package/handler/index.js.map +1 -1
- package/handler/register.js +7 -15
- package/handler/register.js.map +1 -1
- package/handler/types.js +0 -3
- package/index.js +2 -4
- package/package.json +30 -25
- package/plugins/TaskServicePlugin.js +9 -6
- package/plugins/TaskServicePlugin.js.map +1 -1
- package/plugins/index.js +0 -2
- package/response/DatabaseResponse.js +113 -132
- package/response/DatabaseResponse.js.map +1 -1
- package/response/Response.js +78 -96
- package/response/Response.js.map +1 -1
- package/response/ResponseAbortedResult.js +8 -7
- package/response/ResponseAbortedResult.js.map +1 -1
- package/response/ResponseContinueResult.js +12 -14
- package/response/ResponseContinueResult.js.map +1 -1
- package/response/ResponseDoneResult.js +10 -9
- package/response/ResponseDoneResult.js.map +1 -1
- package/response/ResponseErrorResult.js +9 -8
- package/response/ResponseErrorResult.js.map +1 -1
- package/response/TaskResponse.js +44 -64
- package/response/TaskResponse.js.map +1 -1
- package/response/abstractions/Response.js +0 -3
- package/response/abstractions/ResponseAbortedResult.js +0 -3
- package/response/abstractions/ResponseBaseResult.js +0 -3
- package/response/abstractions/ResponseContinueResult.js +0 -3
- package/response/abstractions/ResponseDoneResult.js +0 -3
- package/response/abstractions/ResponseErrorResult.js +0 -3
- package/response/abstractions/TaskResponse.js +0 -3
- package/response/abstractions/index.js +0 -2
- package/response/index.js +0 -2
- package/runner/TaskControl.js +151 -212
- package/runner/TaskControl.js.map +1 -1
- package/runner/TaskEventValidation.js +12 -13
- package/runner/TaskEventValidation.js.map +1 -1
- package/runner/TaskManager.js +68 -106
- package/runner/TaskManager.js.map +1 -1
- package/runner/TaskManagerStore.d.ts +2 -2
- package/runner/TaskManagerStore.js +90 -139
- package/runner/TaskManagerStore.js.map +1 -1
- package/runner/TaskRunner.js +45 -65
- package/runner/TaskRunner.js.map +1 -1
- package/runner/abstractions/TaskControl.js +0 -3
- package/runner/abstractions/TaskEventValidation.js +0 -3
- package/runner/abstractions/TaskManager.js +0 -3
- package/runner/abstractions/TaskManagerStore.js +0 -3
- package/runner/abstractions/TaskRunner.js +0 -3
- package/runner/abstractions/index.js +0 -2
- package/runner/index.js +0 -2
- package/service/EventBridgeEventTransportPlugin.js +43 -42
- package/service/EventBridgeEventTransportPlugin.js.map +1 -1
- package/service/StepFunctionServicePlugin.js +65 -66
- package/service/StepFunctionServicePlugin.js.map +1 -1
- package/service/createService.js +10 -13
- package/service/createService.js.map +1 -1
- package/service/index.js +7 -5
- package/service/index.js.map +1 -1
- package/tasks/testingRunTask.js +11 -10
- package/tasks/testingRunTask.js.map +1 -1
- package/types.d.ts +10 -1
- package/types.js +13 -11
- package/types.js.map +1 -1
- package/utils/ObjectUpdater.js +25 -31
- package/utils/ObjectUpdater.js.map +1 -1
- package/utils/getErrorProperties.js +5 -4
- package/utils/getErrorProperties.js.map +1 -1
- package/utils/getObjectProperties.js +8 -15
- package/utils/getObjectProperties.js.map +1 -1
- package/utils/index.js +0 -2
- package/utils/normalizeSelfCleanup.d.ts +2 -0
- package/utils/normalizeSelfCleanup.js +16 -0
- package/utils/normalizeSelfCleanup.js.map +1 -0
- package/events/index.js.map +0 -1
- package/features/AbortTask/index.js.map +0 -1
- package/features/GetTask/index.js.map +0 -1
- package/features/GetTaskDefinition/index.js.map +0 -1
- package/features/ListTaskDefinitions/index.js.map +0 -1
- package/features/ListTasks/index.js.map +0 -1
- package/features/TaskController/augmentation.js.map +0 -1
- package/features/TaskController/index.js.map +0 -1
- package/features/TaskExecutionContext/index.js.map +0 -1
- package/features/TriggerTask/index.js.map +0 -1
- package/global.js.map +0 -1
- package/handler/types.js.map +0 -1
- package/index.js.map +0 -1
- package/plugins/index.js.map +0 -1
- package/response/abstractions/Response.js.map +0 -1
- package/response/abstractions/ResponseAbortedResult.js.map +0 -1
- package/response/abstractions/ResponseBaseResult.js.map +0 -1
- package/response/abstractions/ResponseContinueResult.js.map +0 -1
- package/response/abstractions/ResponseDoneResult.js.map +0 -1
- package/response/abstractions/ResponseErrorResult.js.map +0 -1
- package/response/abstractions/TaskResponse.js.map +0 -1
- package/response/abstractions/index.js.map +0 -1
- package/response/index.js.map +0 -1
- package/runner/abstractions/TaskControl.js.map +0 -1
- package/runner/abstractions/TaskEventValidation.js.map +0 -1
- package/runner/abstractions/TaskManager.js.map +0 -1
- package/runner/abstractions/TaskManagerStore.js.map +0 -1
- package/runner/abstractions/TaskRunner.js.map +0 -1
- package/runner/abstractions/index.js.map +0 -1
- package/runner/index.js.map +0 -1
- package/utils/index.js.map +0 -1
package/graphql/utils.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { ErrorResponse, ListErrorResponse, ListResponse, Response } from "@webiny/handler-graphql";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
const emptyResolver = ()=>({});
|
|
3
|
+
const resolve = async (fn)=>{
|
|
4
|
+
try {
|
|
5
|
+
return new Response(await fn());
|
|
6
|
+
} catch (ex) {
|
|
7
|
+
return new ErrorResponse(ex);
|
|
8
|
+
}
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
const resolveList = async (fn)=>{
|
|
11
|
+
try {
|
|
12
|
+
const result = await fn();
|
|
13
|
+
return new ListResponse(result.items, result.meta);
|
|
14
|
+
} catch (ex) {
|
|
15
|
+
return new ListErrorResponse(ex);
|
|
16
|
+
}
|
|
17
17
|
};
|
|
18
|
+
export { emptyResolver, resolve, resolveList };
|
|
18
19
|
|
|
19
20
|
//# sourceMappingURL=utils.js.map
|
package/graphql/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"graphql/utils.js","sources":["../../src/graphql/utils.ts"],"sourcesContent":["import { ErrorResponse, ListErrorResponse, ListResponse, Response } from \"@webiny/handler-graphql\";\nimport type { CmsEntryMeta } from \"@webiny/api-headless-cms/types/index.js\";\n\nexport const emptyResolver = () => ({});\n\ninterface ResolveCallable<T = any> {\n (): Promise<T>;\n}\n\nexport const resolve = async <T = any>(fn: ResolveCallable<T>) => {\n try {\n return new Response(await fn());\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n};\n\ninterface IListResult {\n items: any[];\n meta: CmsEntryMeta;\n}\n\nexport const resolveList = async (fn: ResolveCallable) => {\n try {\n const result = (await fn()) as IListResult;\n return new ListResponse(result.items, result.meta);\n } catch (ex) {\n return new ListErrorResponse(ex);\n }\n};\n"],"names":["emptyResolver","resolve","fn","Response","ex","ErrorResponse","resolveList","result","ListResponse","ListErrorResponse"],"mappings":";AAGO,MAAMA,gBAAgB,IAAO,EAAC;AAM9B,MAAMC,UAAU,OAAgBC;IACnC,IAAI;QACA,OAAO,IAAIC,SAAS,MAAMD;IAC9B,EAAE,OAAOE,IAAI;QACT,OAAO,IAAIC,cAAcD;IAC7B;AACJ;AAOO,MAAME,cAAc,OAAOJ;IAC9B,IAAI;QACA,MAAMK,SAAU,MAAML;QACtB,OAAO,IAAIM,aAAaD,OAAO,KAAK,EAAEA,OAAO,IAAI;IACrD,EAAE,OAAOH,IAAI;QACT,OAAO,IAAIK,kBAAkBL;IACjC;AACJ"}
|
package/handler/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createHandler
|
|
1
|
+
import { createHandler } from "@webiny/handler";
|
|
2
2
|
import { registerDefaultPlugins } from "@webiny/handler-aws/plugins/index.js";
|
|
3
3
|
import { execute } from "@webiny/handler-aws/execute.js";
|
|
4
4
|
import { TaskRunner } from "../runner/index.js";
|
|
@@ -6,57 +6,50 @@ import { timerFactory } from "@webiny/handler-aws/utils/index.js";
|
|
|
6
6
|
import { TaskEventValidation } from "../runner/TaskEventValidation.js";
|
|
7
7
|
import { TaskResultStatus } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
8
8
|
const url = "/webiny-background-task-event";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
["x-webiny-cms-endpoint"]: event.endpoint,
|
|
55
|
-
["accept-language"]: "en-US"
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
};
|
|
9
|
+
const handler_createHandler = (params)=>async (event, context)=>{
|
|
10
|
+
const app = createHandler({
|
|
11
|
+
...params,
|
|
12
|
+
options: {
|
|
13
|
+
logger: true === params.debug,
|
|
14
|
+
...params.options || {}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
registerDefaultPlugins(app.webiny);
|
|
18
|
+
app.addHook("preSerialization", async (_, __, payload)=>{
|
|
19
|
+
if (!payload.body) return payload;
|
|
20
|
+
return payload.body;
|
|
21
|
+
});
|
|
22
|
+
await app.register(async (taskApp)=>{
|
|
23
|
+
taskApp.setErrorHandler(async (error, _, reply)=>{
|
|
24
|
+
app.__webiny_raw_result = {
|
|
25
|
+
error: {
|
|
26
|
+
message: error.message,
|
|
27
|
+
code: error.code,
|
|
28
|
+
data: error.data
|
|
29
|
+
},
|
|
30
|
+
status: TaskResultStatus.ERROR
|
|
31
|
+
};
|
|
32
|
+
return reply.send();
|
|
33
|
+
});
|
|
34
|
+
taskApp.post(url, async (_, reply)=>{
|
|
35
|
+
const handler = new TaskRunner(app.webiny, timerFactory(context), new TaskEventValidation());
|
|
36
|
+
app.__webiny_raw_result = await handler.run(event);
|
|
37
|
+
return reply.send({});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
return execute({
|
|
41
|
+
app,
|
|
42
|
+
url: url,
|
|
43
|
+
payload: {
|
|
44
|
+
...event,
|
|
45
|
+
headers: {
|
|
46
|
+
["x-tenant"]: event.tenant,
|
|
47
|
+
["x-webiny-cms-endpoint"]: event.endpoint,
|
|
48
|
+
["accept-language"]: "en-US"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
export { handler_createHandler as createHandler };
|
|
61
54
|
|
|
62
55
|
//# sourceMappingURL=index.js.map
|
package/handler/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"handler/index.js","sources":["../../src/handler/index.ts"],"sourcesContent":["import { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"@webiny/handler-aws/plugins/index.js\";\nimport { execute } from \"@webiny/handler-aws/execute.js\";\nimport type {\n APIGatewayProxyResult,\n Context as LambdaContext\n} from \"@webiny/aws-sdk/types/index.js\";\nimport type { Context } from \"~/types.js\";\nimport type { HandlerParams, ITaskRawEvent } from \"~/handler/types.js\";\nimport { TaskRunner } from \"~/runner/index.js\";\nimport type WebinyError from \"@webiny/error\";\nimport { timerFactory } from \"@webiny/handler-aws/utils/index.js\";\nimport { TaskEventValidation } from \"~/runner/TaskEventValidation.js\";\nimport { TaskResultStatus } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\n\nexport interface HandlerCallable {\n (event: ITaskRawEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nconst url = \"/webiny-background-task-event\";\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return async (event, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n\n registerDefaultPlugins(app.webiny);\n\n app.addHook(\"preSerialization\", async (_, __, payload: Record<string, any>) => {\n if (!payload.body) {\n return payload;\n }\n return payload.body;\n });\n\n await app.register(async taskApp => {\n taskApp.setErrorHandler<WebinyError>(async (error, _, reply) => {\n app.__webiny_raw_result = {\n error: {\n message: error.message,\n code: error.code,\n data: error.data\n },\n status: TaskResultStatus.ERROR\n };\n return reply.send();\n });\n\n taskApp.post(url, async (_, reply) => {\n const handler = new TaskRunner(\n /**\n * We can safely cast because we know that the context is of type tasks/Context\n */\n app.webiny as Context,\n timerFactory(context),\n new TaskEventValidation()\n );\n\n app.__webiny_raw_result = await handler.run(event);\n return reply.send({});\n });\n });\n\n return execute({\n app,\n url,\n payload: {\n ...event,\n headers: {\n [\"x-tenant\"]: event.tenant,\n [\"x-webiny-cms-endpoint\"]: event.endpoint,\n [\"accept-language\"]: \"en-US\"\n }\n }\n });\n };\n};\n"],"names":["url","createHandler","params","event","context","app","createBaseHandler","registerDefaultPlugins","_","__","payload","taskApp","error","reply","TaskResultStatus","handler","TaskRunner","timerFactory","TaskEventValidation","execute"],"mappings":";;;;;;;AAmBA,MAAMA,MAAM;AAEL,MAAMC,wBAAgB,CAACC,SACnB,OAAOC,OAAOC;QACjB,MAAMC,MAAMC,cAAkB;YAC1B,GAAGJ,MAAM;YACT,SAAS;gBACL,QAAQA,AAAiB,SAAjBA,OAAO,KAAK;gBACpB,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YAC5B;QACJ;QAEAK,uBAAuBF,IAAI,MAAM;QAEjCA,IAAI,OAAO,CAAC,oBAAoB,OAAOG,GAAGC,IAAIC;YAC1C,IAAI,CAACA,QAAQ,IAAI,EACb,OAAOA;YAEX,OAAOA,QAAQ,IAAI;QACvB;QAEA,MAAML,IAAI,QAAQ,CAAC,OAAMM;YACrBA,QAAQ,eAAe,CAAc,OAAOC,OAAOJ,GAAGK;gBAClDR,IAAI,mBAAmB,GAAG;oBACtB,OAAO;wBACH,SAASO,MAAM,OAAO;wBACtB,MAAMA,MAAM,IAAI;wBAChB,MAAMA,MAAM,IAAI;oBACpB;oBACA,QAAQE,iBAAiB,KAAK;gBAClC;gBACA,OAAOD,MAAM,IAAI;YACrB;YAEAF,QAAQ,IAAI,CAACX,KAAK,OAAOQ,GAAGK;gBACxB,MAAME,UAAU,IAAIC,WAIhBX,IAAI,MAAM,EACVY,aAAab,UACb,IAAIc;gBAGRb,IAAI,mBAAmB,GAAG,MAAMU,QAAQ,GAAG,CAACZ;gBAC5C,OAAOU,MAAM,IAAI,CAAC,CAAC;YACvB;QACJ;QAEA,OAAOM,QAAQ;YACXd;YACAL,KAAAA;YACA,SAAS;gBACL,GAAGG,KAAK;gBACR,SAAS;oBACL,CAAC,WAAW,EAAEA,MAAM,MAAM;oBAC1B,CAAC,wBAAwB,EAAEA,MAAM,QAAQ;oBACzC,CAAC,kBAAkB,EAAE;gBACzB;YACJ;QACJ;IACJ"}
|
package/handler/register.js
CHANGED
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
import { registry } from "@webiny/handler-aws/registry.js";
|
|
2
2
|
import { createSourceHandler } from "@webiny/handler-aws";
|
|
3
3
|
const handler = createSourceHandler({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
event,
|
|
11
|
-
context
|
|
12
|
-
}) => {
|
|
13
|
-
const {
|
|
14
|
-
createHandler
|
|
15
|
-
} = await import(/* webpackChunkName: "tasks.handler.createHandler" */"./index.js");
|
|
16
|
-
return createHandler(params)(event.payload, context);
|
|
17
|
-
}
|
|
4
|
+
name: "handler-webiny-background-task",
|
|
5
|
+
canUse: (event)=>!!event.payload?.webinyTaskId,
|
|
6
|
+
handle: async ({ params, event, context })=>{
|
|
7
|
+
const { createHandler } = await import("./index.js");
|
|
8
|
+
return createHandler(params)(event.payload, context);
|
|
9
|
+
}
|
|
18
10
|
});
|
|
19
11
|
registry.register(handler, {
|
|
20
|
-
|
|
12
|
+
silent: true
|
|
21
13
|
});
|
|
22
14
|
|
|
23
15
|
//# sourceMappingURL=register.js.map
|
package/handler/register.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"handler/register.js","sources":["../../src/handler/register.ts"],"sourcesContent":["import { registry } from \"@webiny/handler-aws/registry.js\";\nimport { createSourceHandler } from \"@webiny/handler-aws\";\nimport type { HandlerParams, IIncomingEvent, ITaskEvent } from \"./types.js\";\n\nconst handler = createSourceHandler<IIncomingEvent<ITaskEvent>, HandlerParams>({\n name: \"handler-webiny-background-task\",\n canUse: event => {\n return !!event.payload?.webinyTaskId;\n },\n handle: async ({ params, event, context }) => {\n const { createHandler } = await import(\n /* webpackChunkName: \"tasks.handler.createHandler\" */\n \"./index.js\"\n );\n return createHandler(params)(event.payload, context);\n }\n});\n\nregistry.register(handler, {\n silent: true\n});\n"],"names":["handler","createSourceHandler","event","params","context","createHandler","registry"],"mappings":";;AAIA,MAAMA,UAAUC,oBAA+D;IAC3E,MAAM;IACN,QAAQC,CAAAA,QACG,CAAC,CAACA,MAAM,OAAO,EAAE;IAE5B,QAAQ,OAAO,EAAEC,MAAM,EAAED,KAAK,EAAEE,OAAO,EAAE;QACrC,MAAM,EAAEC,aAAa,EAAE,GAAG,MAAM,MAAM,CAAN;QAIhC,OAAOA,cAAcF,QAAQD,MAAM,OAAO,EAAEE;IAChD;AACJ;AAEAE,SAAS,QAAQ,CAACN,SAAS;IACvB,QAAQ;AACZ"}
|
package/handler/types.js
CHANGED
package/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import "./handler/register.js";
|
|
2
|
-
export { createBackgroundTaskGraphQL } from "./graphql/index.js";
|
|
3
|
-
export { createBackgroundTaskContext } from "./context.js";
|
|
4
2
|
export * from "./response/index.js";
|
|
5
3
|
export * from "./types.js";
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
export { createBackgroundTaskGraphQL } from "./graphql/index.js";
|
|
5
|
+
export { createBackgroundTaskContext } from "./context.js";
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/tasks",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.7be00a75a9",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./index.js",
|
|
7
|
+
"./*": "./*"
|
|
8
|
+
},
|
|
6
9
|
"repository": {
|
|
7
10
|
"type": "git",
|
|
8
11
|
"url": "https://github.com/webiny/webiny-js.git"
|
|
@@ -13,34 +16,36 @@
|
|
|
13
16
|
],
|
|
14
17
|
"license": "MIT",
|
|
15
18
|
"dependencies": {
|
|
16
|
-
"@webiny/api": "0.0.0-unstable.
|
|
17
|
-
"@webiny/api-core": "0.0.0-unstable.
|
|
18
|
-
"@webiny/api-headless-cms": "0.0.0-unstable.
|
|
19
|
-
"@webiny/aws-sdk": "0.0.0-unstable.
|
|
20
|
-
"@webiny/error": "0.0.0-unstable.
|
|
21
|
-
"@webiny/feature": "0.0.0-unstable.
|
|
22
|
-
"@webiny/handler": "0.0.0-unstable.
|
|
23
|
-
"@webiny/handler-aws": "0.0.0-unstable.
|
|
24
|
-
"@webiny/handler-graphql": "0.0.0-unstable.
|
|
25
|
-
"@webiny/plugins": "0.0.0-unstable.
|
|
26
|
-
"@webiny/utils": "0.0.0-unstable.
|
|
19
|
+
"@webiny/api": "0.0.0-unstable.7be00a75a9",
|
|
20
|
+
"@webiny/api-core": "0.0.0-unstable.7be00a75a9",
|
|
21
|
+
"@webiny/api-headless-cms": "0.0.0-unstable.7be00a75a9",
|
|
22
|
+
"@webiny/aws-sdk": "0.0.0-unstable.7be00a75a9",
|
|
23
|
+
"@webiny/error": "0.0.0-unstable.7be00a75a9",
|
|
24
|
+
"@webiny/feature": "0.0.0-unstable.7be00a75a9",
|
|
25
|
+
"@webiny/handler": "0.0.0-unstable.7be00a75a9",
|
|
26
|
+
"@webiny/handler-aws": "0.0.0-unstable.7be00a75a9",
|
|
27
|
+
"@webiny/handler-graphql": "0.0.0-unstable.7be00a75a9",
|
|
28
|
+
"@webiny/plugins": "0.0.0-unstable.7be00a75a9",
|
|
29
|
+
"@webiny/utils": "0.0.0-unstable.7be00a75a9",
|
|
27
30
|
"deep-equal": "2.2.3",
|
|
28
|
-
"lodash": "4.
|
|
29
|
-
"object-merge-advanced": "
|
|
31
|
+
"lodash": "4.18.1",
|
|
32
|
+
"object-merge-advanced": "14.1.3",
|
|
30
33
|
"object-sizeof": "2.6.5",
|
|
31
|
-
"zod": "
|
|
34
|
+
"zod": "4.4.3"
|
|
32
35
|
},
|
|
33
36
|
"devDependencies": {
|
|
34
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
35
|
-
"@webiny/project-utils": "0.0.0-unstable.
|
|
36
|
-
"rimraf": "6.1.
|
|
37
|
-
"type-fest": "5.
|
|
38
|
-
"typescript": "
|
|
39
|
-
"vitest": "
|
|
37
|
+
"@webiny/build-tools": "0.0.0-unstable.7be00a75a9",
|
|
38
|
+
"@webiny/project-utils": "0.0.0-unstable.7be00a75a9",
|
|
39
|
+
"rimraf": "6.1.3",
|
|
40
|
+
"type-fest": "5.6.0",
|
|
41
|
+
"typescript": "6.0.3",
|
|
42
|
+
"vitest": "4.1.7"
|
|
40
43
|
},
|
|
41
44
|
"publishConfig": {
|
|
42
|
-
"access": "public"
|
|
43
|
-
"directory": "dist"
|
|
45
|
+
"access": "public"
|
|
44
46
|
},
|
|
45
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "8476da73b653c89cc1474d968baf55c1b0ae0e5f",
|
|
48
|
+
"webiny": {
|
|
49
|
+
"publishFrom": "dist"
|
|
50
|
+
}
|
|
46
51
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
class TaskServicePlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "tasks.taskService";
|
|
5
|
+
}
|
|
6
|
+
constructor(params){
|
|
7
|
+
super();
|
|
8
|
+
this.default = !!params?.default;
|
|
9
|
+
}
|
|
8
10
|
}
|
|
11
|
+
export { TaskServicePlugin };
|
|
9
12
|
|
|
10
13
|
//# sourceMappingURL=TaskServicePlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/TaskServicePlugin.js","sources":["../../src/plugins/TaskServicePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { ITask } from \"~/types.js\";\n\nexport interface ITaskServiceCreatePluginParams {\n getTenant(): string;\n}\n\nexport type ITaskServiceTask = Pick<ITask, \"id\" | \"definitionId\">;\n\nexport interface ITaskService {\n send(task: ITaskServiceTask, delay: number): Promise<unknown | null>;\n fetch(task: ITask): Promise<unknown | null>;\n}\n\nexport interface ITaskServicePluginParams {\n default?: boolean;\n}\n\nexport abstract class TaskServicePlugin extends Plugin {\n public static override readonly type: string = \"tasks.taskService\";\n public readonly default: boolean;\n\n public constructor(params?: ITaskServicePluginParams) {\n super();\n this.default = !!params?.default;\n }\n\n public abstract createService(params: ITaskServiceCreatePluginParams): ITaskService;\n}\n"],"names":["TaskServicePlugin","Plugin","params"],"mappings":";AAkBO,MAAeA,0BAA0BC;;aACZ,IAAI,GAAW;;IAG/C,YAAmBC,MAAiC,CAAE;QAClD,KAAK;QACL,IAAI,CAAC,OAAO,GAAG,CAAC,CAACA,QAAQ;IAC7B;AAGJ"}
|
package/plugins/index.js
CHANGED
|
@@ -2,145 +2,126 @@ import { TaskDataStatus } from "../types.js";
|
|
|
2
2
|
import { NotFoundError } from "@webiny/handler-graphql";
|
|
3
3
|
import { getErrorProperties } from "../utils/getErrorProperties.js";
|
|
4
4
|
import { TaskResultStatus } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
from(result) {
|
|
11
|
-
switch (result.status) {
|
|
12
|
-
case TaskResultStatus.DONE:
|
|
13
|
-
return this.done(result);
|
|
14
|
-
case TaskResultStatus.CONTINUE:
|
|
15
|
-
return this.continue(result);
|
|
16
|
-
case TaskResultStatus.ERROR:
|
|
17
|
-
return this.error(result);
|
|
18
|
-
case TaskResultStatus.ABORTED:
|
|
19
|
-
return this.aborted();
|
|
5
|
+
class DatabaseResponse {
|
|
6
|
+
constructor(response, store){
|
|
7
|
+
this.response = response;
|
|
8
|
+
this.store = store;
|
|
20
9
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
finishedOn: new Date().toISOString(),
|
|
32
|
-
output
|
|
33
|
-
});
|
|
34
|
-
await this.store.addInfoLog({
|
|
35
|
-
message: message || "Task done."
|
|
36
|
-
});
|
|
37
|
-
await this.store.save();
|
|
38
|
-
} catch (ex) {
|
|
39
|
-
message = `Task done, but failed to update task log. (${ex.message || "unknown"})`;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Default behavior is to return the done response.
|
|
43
|
-
*/
|
|
44
|
-
return this.response.done({
|
|
45
|
-
...rest,
|
|
46
|
-
message,
|
|
47
|
-
output
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
async aborted() {
|
|
51
|
-
return this.response.aborted();
|
|
52
|
-
}
|
|
53
|
-
async continue(params) {
|
|
54
|
-
try {
|
|
55
|
-
const task = this.store.getTask();
|
|
56
|
-
await this.store.updateTask({
|
|
57
|
-
input: {
|
|
58
|
-
...task.input,
|
|
59
|
-
...params.input
|
|
60
|
-
},
|
|
61
|
-
taskStatus: TaskDataStatus.RUNNING
|
|
62
|
-
});
|
|
63
|
-
await this.store.addInfoLog({
|
|
64
|
-
message: "Task continuing.",
|
|
65
|
-
data: params.input
|
|
66
|
-
});
|
|
67
|
-
await this.store.save();
|
|
68
|
-
} catch (ex) {
|
|
69
|
-
/**
|
|
70
|
-
* If task was not found, we just return the error.
|
|
71
|
-
*/
|
|
72
|
-
if (ex instanceof NotFoundError) {
|
|
73
|
-
return this.response.error({
|
|
74
|
-
error: {
|
|
75
|
-
message: ex.message || `Task not found.`,
|
|
76
|
-
code: ex.code || "TASK_NOT_FOUND",
|
|
77
|
-
data: {
|
|
78
|
-
...ex.data,
|
|
79
|
-
input: this.store.getInput()
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Otherwise, we store the error and return it...
|
|
86
|
-
*/
|
|
87
|
-
return this.error({
|
|
88
|
-
error: {
|
|
89
|
-
message: `Failed to update task input: ${ex.message || "unknown error"}`,
|
|
90
|
-
code: ex.code || "TASK_UPDATE_ERROR"
|
|
10
|
+
from(result) {
|
|
11
|
+
switch(result.status){
|
|
12
|
+
case TaskResultStatus.DONE:
|
|
13
|
+
return this.done(result);
|
|
14
|
+
case TaskResultStatus.CONTINUE:
|
|
15
|
+
return this.continue(result);
|
|
16
|
+
case TaskResultStatus.ERROR:
|
|
17
|
+
return this.error(result);
|
|
18
|
+
case TaskResultStatus.ABORTED:
|
|
19
|
+
return this.aborted();
|
|
91
20
|
}
|
|
92
|
-
});
|
|
93
21
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
22
|
+
async done(params) {
|
|
23
|
+
const { output, ...rest } = params;
|
|
24
|
+
let message = params.message;
|
|
25
|
+
try {
|
|
26
|
+
await this.store.updateTask({
|
|
27
|
+
taskStatus: TaskDataStatus.SUCCESS,
|
|
28
|
+
finishedOn: new Date().toISOString(),
|
|
29
|
+
output
|
|
30
|
+
});
|
|
31
|
+
await this.store.addInfoLog({
|
|
32
|
+
message: message || "Task done."
|
|
33
|
+
});
|
|
34
|
+
await this.store.save();
|
|
35
|
+
} catch (ex) {
|
|
36
|
+
message = `Task done, but failed to update task log. (${ex.message || "unknown"})`;
|
|
107
37
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
38
|
+
return this.response.done({
|
|
39
|
+
...rest,
|
|
40
|
+
message,
|
|
41
|
+
output
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async aborted() {
|
|
45
|
+
return this.response.aborted();
|
|
46
|
+
}
|
|
47
|
+
async continue(params) {
|
|
48
|
+
try {
|
|
49
|
+
const task = this.store.getTask();
|
|
50
|
+
await this.store.updateTask({
|
|
51
|
+
input: {
|
|
52
|
+
...task.input,
|
|
53
|
+
...params.input
|
|
54
|
+
},
|
|
55
|
+
taskStatus: TaskDataStatus.RUNNING
|
|
56
|
+
});
|
|
57
|
+
await this.store.addInfoLog({
|
|
58
|
+
message: "Task continuing.",
|
|
59
|
+
data: params.input
|
|
60
|
+
});
|
|
61
|
+
await this.store.save();
|
|
62
|
+
} catch (ex) {
|
|
63
|
+
if (ex instanceof NotFoundError) return this.response.error({
|
|
64
|
+
error: {
|
|
65
|
+
message: ex.message || "Task not found.",
|
|
66
|
+
code: ex.code || "TASK_NOT_FOUND",
|
|
67
|
+
data: {
|
|
68
|
+
...ex.data,
|
|
69
|
+
input: this.store.getInput()
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return this.error({
|
|
74
|
+
error: {
|
|
75
|
+
message: `Failed to update task input: ${ex.message || "unknown error"}`,
|
|
76
|
+
code: ex.code || "TASK_UPDATE_ERROR"
|
|
77
|
+
}
|
|
78
|
+
});
|
|
127
79
|
}
|
|
128
|
-
|
|
80
|
+
return this.response.continue(params);
|
|
129
81
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
82
|
+
async error(params) {
|
|
83
|
+
const error = params.error instanceof Error ? getErrorProperties(params.error) : params.error;
|
|
84
|
+
try {
|
|
85
|
+
await this.store.updateTask({
|
|
86
|
+
taskStatus: TaskDataStatus.FAILED,
|
|
87
|
+
finishedOn: new Date().toISOString(),
|
|
88
|
+
output: {
|
|
89
|
+
error
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
await this.store.addErrorLog({
|
|
93
|
+
message: params.error.message,
|
|
94
|
+
data: this.store.getInput(),
|
|
95
|
+
error
|
|
96
|
+
});
|
|
97
|
+
await this.store.save();
|
|
98
|
+
} catch (ex) {
|
|
99
|
+
return this.response.error({
|
|
100
|
+
...params,
|
|
101
|
+
error: {
|
|
102
|
+
...error,
|
|
103
|
+
message: ex.message || error.message,
|
|
104
|
+
code: ex.code || error.code,
|
|
105
|
+
data: {
|
|
106
|
+
...error.data,
|
|
107
|
+
...ex.data,
|
|
108
|
+
input: this.store.getInput()
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
140
112
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
113
|
+
return this.response.error({
|
|
114
|
+
...params,
|
|
115
|
+
error: {
|
|
116
|
+
...params.error,
|
|
117
|
+
data: {
|
|
118
|
+
...error.data,
|
|
119
|
+
input: this.store.getInput()
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
144
124
|
}
|
|
125
|
+
export { DatabaseResponse };
|
|
145
126
|
|
|
146
127
|
//# sourceMappingURL=DatabaseResponse.js.map
|