@webiny/background-tasks 6.6.0-alpha.0 → 6.6.0-alpha.1
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/admin/BackgroundTaskRoutes.js +16 -3
- package/admin/BackgroundTaskRoutes.js.map +1 -1
- package/admin/presentation/TaskDetail/components/TaskDetailDrawer.js +6 -0
- package/admin/presentation/TaskDetail/components/TaskDetailDrawer.js.map +1 -1
- package/admin/presentation/TaskExecutions/components/TaskExecutionsView.js +44 -24
- package/admin/presentation/TaskExecutions/components/TaskExecutionsView.js.map +1 -1
- package/api/BackgroundTasksFeature.js +2 -0
- package/api/BackgroundTasksFeature.js.map +1 -1
- package/api/crud/service.tasks.js +4 -2
- package/api/crud/service.tasks.js.map +1 -1
- package/api/decorators/RunnableTaskDecorator.d.ts +2 -1
- package/api/decorators/RunnableTaskDecorator.js +5 -6
- package/api/decorators/RunnableTaskDecorator.js.map +1 -1
- package/api/decorators/SelfCleaningTaskDecorator.d.ts +5 -2
- package/api/decorators/SelfCleaningTaskDecorator.js +14 -5
- package/api/decorators/SelfCleaningTaskDecorator.js.map +1 -1
- package/api/domain/errors.d.ts +10 -0
- package/api/domain/errors.js +11 -1
- package/api/domain/errors.js.map +1 -1
- package/api/features/GetTaskDefinition/GetTaskDefinitionUseCase.d.ts +6 -3
- package/api/features/GetTaskDefinition/GetTaskDefinitionUseCase.js +66 -5
- package/api/features/GetTaskDefinition/GetTaskDefinitionUseCase.js.map +1 -1
- package/api/features/GetTaskDefinition/abstractions.d.ts +2 -1
- package/api/features/GetTaskDefinition/abstractions.js.map +1 -1
- package/api/features/TaskHandlerResolver/TaskHandlerResolver.d.ts +12 -0
- package/api/features/TaskHandlerResolver/TaskHandlerResolver.js +19 -0
- package/api/features/TaskHandlerResolver/TaskHandlerResolver.js.map +1 -0
- package/api/features/TaskHandlerResolver/abstractions.d.ts +17 -0
- package/api/features/TaskHandlerResolver/abstractions.js +5 -0
- package/api/features/TaskHandlerResolver/abstractions.js.map +1 -0
- package/api/features/TaskHandlerResolver/feature.d.ts +9 -0
- package/api/features/TaskHandlerResolver/feature.js +11 -0
- package/api/features/TaskHandlerResolver/feature.js.map +1 -0
- package/api/features/TaskHandlerResolver/index.d.ts +2 -0
- package/api/features/TaskHandlerResolver/index.js +2 -0
- package/api/runner/TaskControl.d.ts +25 -1
- package/api/runner/TaskControl.js +28 -18
- package/api/runner/TaskControl.js.map +1 -1
- package/api/runner/TaskManager.d.ts +12 -1
- package/api/runner/TaskManager.js +8 -7
- package/api/runner/TaskManager.js.map +1 -1
- package/api/runner/TaskManagerStore.d.ts +7 -0
- package/api/runner/TaskManagerStore.js +3 -3
- package/api/runner/TaskManagerStore.js.map +1 -1
- package/api/runner/TaskRunner.js +25 -4
- package/api/runner/TaskRunner.js.map +1 -1
- package/api/tasks/testingRunTask.d.ts +10 -2
- package/api/tasks/testingRunTask.js +10 -3
- package/api/tasks/testingRunTask.js.map +1 -1
- package/package.json +26 -28
- package/testing/index.d.ts +3 -0
- package/testing/index.js +2 -0
- package/testing/mockTaskTriggerTransportPlugin.d.ts +2 -0
- package/testing/mockTaskTriggerTransportPlugin.js +18 -0
- package/testing/mockTaskTriggerTransportPlugin.js.map +1 -0
- package/testing/runner.d.ts +19 -0
- package/testing/runner.js +44 -0
- package/testing/runner.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/background-tasks",
|
|
3
|
-
"version": "6.6.0-alpha.
|
|
3
|
+
"version": "6.6.0-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -19,45 +19,43 @@
|
|
|
19
19
|
},
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@graphql-tools/merge": "9.2.
|
|
23
|
-
"@graphql-tools/schema": "10.0
|
|
24
|
-
"@webiny/admin-ui": "6.6.0-alpha.
|
|
25
|
-
"@webiny/api": "6.6.0-alpha.
|
|
26
|
-
"@webiny/api-core": "6.6.0-alpha.
|
|
27
|
-
"@webiny/api-graphql": "6.6.0-alpha.
|
|
28
|
-
"@webiny/api-headless-cms": "6.6.0-alpha.
|
|
29
|
-
"@webiny/app": "6.6.0-alpha.
|
|
30
|
-
"@webiny/app-admin": "6.6.0-alpha.
|
|
31
|
-
"@webiny/error": "6.6.0-alpha.
|
|
32
|
-
"@webiny/
|
|
33
|
-
"@webiny/
|
|
34
|
-
"@webiny/
|
|
35
|
-
"@webiny/
|
|
36
|
-
"@webiny/
|
|
37
|
-
"@webiny/
|
|
38
|
-
"@webiny/utils": "6.6.0-alpha.0",
|
|
22
|
+
"@graphql-tools/merge": "9.2.3",
|
|
23
|
+
"@graphql-tools/schema": "10.1.0",
|
|
24
|
+
"@webiny/admin-ui": "6.6.0-alpha.1",
|
|
25
|
+
"@webiny/api": "6.6.0-alpha.1",
|
|
26
|
+
"@webiny/api-core": "6.6.0-alpha.1",
|
|
27
|
+
"@webiny/api-graphql": "6.6.0-alpha.1",
|
|
28
|
+
"@webiny/api-headless-cms": "6.6.0-alpha.1",
|
|
29
|
+
"@webiny/app": "6.6.0-alpha.1",
|
|
30
|
+
"@webiny/app-admin": "6.6.0-alpha.1",
|
|
31
|
+
"@webiny/error": "6.6.0-alpha.1",
|
|
32
|
+
"@webiny/feature": "6.6.0-alpha.1",
|
|
33
|
+
"@webiny/handler": "6.6.0-alpha.1",
|
|
34
|
+
"@webiny/icons": "6.6.0-alpha.1",
|
|
35
|
+
"@webiny/plugins": "6.6.0-alpha.1",
|
|
36
|
+
"@webiny/sdk": "6.6.0-alpha.1",
|
|
37
|
+
"@webiny/utils": "6.6.0-alpha.1",
|
|
39
38
|
"deep-equal": "2.2.3",
|
|
40
39
|
"graphql": "16.14.2",
|
|
41
40
|
"lodash": "4.18.1",
|
|
42
|
-
"mobx": "
|
|
43
|
-
"mobx-react-lite": "
|
|
44
|
-
"object-merge-advanced": "14.
|
|
41
|
+
"mobx": "7.0.3",
|
|
42
|
+
"mobx-react-lite": "5.0.3",
|
|
43
|
+
"object-merge-advanced": "14.2.0",
|
|
45
44
|
"object-sizeof": "2.6.5",
|
|
46
45
|
"react": "18.3.1",
|
|
47
46
|
"react-dom": "18.3.1",
|
|
48
47
|
"zod": "4.4.3"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
|
-
"@webiny/api-core-testing": "6.6.0-alpha.
|
|
52
|
-
"@webiny/
|
|
53
|
-
"@webiny/
|
|
54
|
-
"@webiny/
|
|
55
|
-
"@webiny/
|
|
56
|
-
"@webiny/wcp": "6.6.0-alpha.0",
|
|
50
|
+
"@webiny/api-core-testing": "6.6.0-alpha.1",
|
|
51
|
+
"@webiny/build-tools": "6.6.0-alpha.1",
|
|
52
|
+
"@webiny/di": "1.1.0",
|
|
53
|
+
"@webiny/event-handler-core": "6.6.0-alpha.1",
|
|
54
|
+
"@webiny/wcp": "6.6.0-alpha.1",
|
|
57
55
|
"rimraf": "6.1.3",
|
|
58
56
|
"type-fest": "5.8.0",
|
|
59
57
|
"typescript": "7.0.2",
|
|
60
|
-
"vitest": "4.1.
|
|
58
|
+
"vitest": "4.1.11"
|
|
61
59
|
},
|
|
62
60
|
"publishConfig": {
|
|
63
61
|
"access": "public"
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { createRunner } from "./runner.js";
|
|
2
|
+
export type { ICreateRunnerParams, ICreateRunnerParamsOnContinueCallable, ICreateRunnerParamsOnContinueCallableParams, IExecuteEvent } from "./runner.js";
|
|
3
|
+
export { createMockTaskService } from "./mockTaskTriggerTransportPlugin.js";
|
package/testing/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const createMockTaskService = ()=>({
|
|
2
|
+
async send () {
|
|
3
|
+
return {
|
|
4
|
+
Entries: [],
|
|
5
|
+
$metadata: {},
|
|
6
|
+
FailedEntryCount: 0
|
|
7
|
+
};
|
|
8
|
+
},
|
|
9
|
+
async fetch (input) {
|
|
10
|
+
return {
|
|
11
|
+
fetched: true,
|
|
12
|
+
input
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
export { createMockTaskService };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=mockTaskTriggerTransportPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing/mockTaskTriggerTransportPlugin.js","sources":["../../src/testing/mockTaskTriggerTransportPlugin.ts"],"sourcesContent":["import type { TaskService } from \"~/api/domain/TaskService.js\";\n\nexport const createMockTaskService = (): TaskService.Interface => {\n return {\n async send() {\n return {\n Entries: [],\n $metadata: {},\n FailedEntryCount: 0\n };\n },\n async fetch(input: any) {\n return {\n fetched: true,\n input\n } as any;\n }\n };\n};\n"],"names":["createMockTaskService","input"],"mappings":"AAEO,MAAMA,wBAAwB,IAC1B;QACH,MAAM;YACF,OAAO;gBACH,SAAS,EAAE;gBACX,WAAW,CAAC;gBACZ,kBAAkB;YACtB;QACJ;QACA,MAAM,OAAMC,KAAU;YAClB,OAAO;gBACH,SAAS;gBACTA;YACJ;QACJ;IACJ"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Context, IResponseContinueResult, ITaskEvent } from "../api/types.js";
|
|
2
|
+
import { ResponseContinueResult } from "../api/response/ResponseContinueResult.js";
|
|
3
|
+
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
4
|
+
export interface ICreateRunnerParamsOnContinueCallableParams {
|
|
5
|
+
taskId: string;
|
|
6
|
+
iteration: number;
|
|
7
|
+
result: IResponseContinueResult;
|
|
8
|
+
}
|
|
9
|
+
export interface ICreateRunnerParamsOnContinueCallable {
|
|
10
|
+
(params: ICreateRunnerParamsOnContinueCallableParams): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export interface ICreateRunnerParams<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput> {
|
|
13
|
+
context: Context;
|
|
14
|
+
task: TaskDefinition.Interface<I, O>;
|
|
15
|
+
getRemainingTimeInMills?: () => number;
|
|
16
|
+
onContinue?: ICreateRunnerParamsOnContinueCallable;
|
|
17
|
+
}
|
|
18
|
+
export type IExecuteEvent = Pick<ITaskEvent, "webinyTaskId"> & Partial<Pick<ITaskEvent, "tenant">>;
|
|
19
|
+
export declare const createRunner: <I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput, O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput>(params: ICreateRunnerParams<I, O>) => (event: IExecuteEvent) => Promise<import("~/api/types.js").IResponseAbortedResult | import("~/api/types.js").IResponseDoneResult<import("@webiny/api-core/features/task/TaskDefinition/abstractions.js").ITaskOutput> | import("~/api/types.js").IResponseErrorResult | ResponseContinueResult<any>>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { TaskRunner } from "../api/runner/index.js";
|
|
2
|
+
import { timerFactory } from "@webiny/utils/features/Timer/factory.js";
|
|
3
|
+
import { TaskEventValidation } from "../api/runner/TaskEventValidation.js";
|
|
4
|
+
import { ResponseContinueResult } from "../api/response/ResponseContinueResult.js";
|
|
5
|
+
import { createMockTaskService } from "./mockTaskTriggerTransportPlugin.js";
|
|
6
|
+
import { TaskService } from "../api/domain/TaskService.js";
|
|
7
|
+
const createRunner = (params)=>{
|
|
8
|
+
params.context.container.registerInstance(TaskService, createMockTaskService());
|
|
9
|
+
const runner = new TaskRunner(params.context, timerFactory({
|
|
10
|
+
getRemainingTimeInMillis: ()=>{
|
|
11
|
+
if (!params.getRemainingTimeInMills) return 300000;
|
|
12
|
+
return params.getRemainingTimeInMills();
|
|
13
|
+
}
|
|
14
|
+
}), new TaskEventValidation());
|
|
15
|
+
const execute = async (event)=>await runner.run({
|
|
16
|
+
tenant: "root",
|
|
17
|
+
...event,
|
|
18
|
+
stateMachineId: "aMockStateMachineId",
|
|
19
|
+
webinyTaskDefinitionId: params.task.id,
|
|
20
|
+
endpoint: "manage",
|
|
21
|
+
executionName: "aMockExecutionName"
|
|
22
|
+
});
|
|
23
|
+
return async (event)=>{
|
|
24
|
+
let iteration = 1;
|
|
25
|
+
let result;
|
|
26
|
+
while(result = await execute(event)){
|
|
27
|
+
if (result instanceof ResponseContinueResult && params.onContinue) {
|
|
28
|
+
await params.onContinue({
|
|
29
|
+
taskId: event.webinyTaskId,
|
|
30
|
+
iteration,
|
|
31
|
+
result
|
|
32
|
+
});
|
|
33
|
+
iteration++;
|
|
34
|
+
console.debug(`Continuing task ${params.task.id} #${iteration}.`);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export { createRunner };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing/runner.js","sources":["../../src/testing/runner.ts"],"sourcesContent":["import type { Context, IResponseContinueResult, IResponseResult, ITaskEvent } from \"~/api/types.js\";\nimport { TaskRunner } from \"~/api/runner/index.js\";\nimport { timerFactory } from \"@webiny/utils/features/Timer/factory.js\";\nimport { TaskEventValidation } from \"~/api/runner/TaskEventValidation.js\";\nimport { ResponseContinueResult } from \"~/api/response/ResponseContinueResult.js\";\nimport { createMockTaskService } from \"./mockTaskTriggerTransportPlugin.js\";\nimport { TaskService } from \"~/api/domain/TaskService.js\";\nimport { TaskDefinition } from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\n\nexport interface ICreateRunnerParamsOnContinueCallableParams {\n taskId: string;\n iteration: number;\n result: IResponseContinueResult;\n}\n\nexport interface ICreateRunnerParamsOnContinueCallable {\n (params: ICreateRunnerParamsOnContinueCallableParams): Promise<void>;\n}\n\nexport interface ICreateRunnerParams<\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput\n> {\n context: Context;\n task: TaskDefinition.Interface<I, O>;\n getRemainingTimeInMills?: () => number;\n onContinue?: ICreateRunnerParamsOnContinueCallable;\n}\n\nexport type IExecuteEvent = Pick<ITaskEvent, \"webinyTaskId\"> & Partial<Pick<ITaskEvent, \"tenant\">>;\n\nexport const createRunner = <\n I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput,\n O extends TaskDefinition.TaskOutput = TaskDefinition.TaskOutput\n>(\n params: ICreateRunnerParams<I, O>\n) => {\n params.context.container.registerInstance(TaskService, createMockTaskService());\n const runner = new TaskRunner(\n params.context,\n timerFactory({\n getRemainingTimeInMillis: () => {\n if (!params.getRemainingTimeInMills) {\n return 5 * 60 * 1000;\n }\n return params.getRemainingTimeInMills();\n }\n }),\n new TaskEventValidation()\n );\n\n const execute = async (event: IExecuteEvent) => {\n return await runner.run({\n tenant: \"root\",\n ...event,\n stateMachineId: \"aMockStateMachineId\",\n webinyTaskDefinitionId: params.task.id,\n endpoint: \"manage\",\n executionName: \"aMockExecutionName\"\n });\n };\n\n return async (event: IExecuteEvent) => {\n let iteration = 1;\n let result: IResponseResult;\n while ((result = await execute(event))) {\n if (result instanceof ResponseContinueResult && params.onContinue) {\n await params.onContinue({\n taskId: event.webinyTaskId,\n iteration,\n result\n });\n iteration++;\n console.debug(`Continuing task ${params.task.id} #${iteration}.`);\n continue;\n }\n return result;\n }\n return result;\n };\n};\n"],"names":["createRunner","params","TaskService","createMockTaskService","runner","TaskRunner","timerFactory","TaskEventValidation","execute","event","iteration","result","ResponseContinueResult","console"],"mappings":";;;;;;AA+BO,MAAMA,eAAe,CAIxBC;IAEAA,OAAO,OAAO,CAAC,SAAS,CAAC,gBAAgB,CAACC,aAAaC;IACvD,MAAMC,SAAS,IAAIC,WACfJ,OAAO,OAAO,EACdK,aAAa;QACT,0BAA0B;YACtB,IAAI,CAACL,OAAO,uBAAuB,EAC/B,OAAO;YAEX,OAAOA,OAAO,uBAAuB;QACzC;IACJ,IACA,IAAIM;IAGR,MAAMC,UAAU,OAAOC,QACZ,MAAML,OAAO,GAAG,CAAC;YACpB,QAAQ;YACR,GAAGK,KAAK;YACR,gBAAgB;YAChB,wBAAwBR,OAAO,IAAI,CAAC,EAAE;YACtC,UAAU;YACV,eAAe;QACnB;IAGJ,OAAO,OAAOQ;QACV,IAAIC,YAAY;QAChB,IAAIC;QACJ,MAAQA,SAAS,MAAMH,QAAQC,OAAS;YACpC,IAAIE,kBAAkBC,0BAA0BX,OAAO,UAAU,EAAE;gBAC/D,MAAMA,OAAO,UAAU,CAAC;oBACpB,QAAQQ,MAAM,YAAY;oBAC1BC;oBACAC;gBACJ;gBACAD;gBACAG,QAAQ,KAAK,CAAC,CAAC,gBAAgB,EAAEZ,OAAO,IAAI,CAAC,EAAE,CAAC,EAAE,EAAES,UAAU,CAAC,CAAC;gBAChE;YACJ;YACA;QACJ;QACA,OAAOC;IACX;AACJ"}
|