@webiny/background-tasks 6.4.5 → 6.6.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/admin/features/listLogs/ListLogsGateway.js +1 -1
- package/admin/features/listLogs/ListLogsGateway.js.map +1 -1
- package/admin/features/permissions/feature.d.ts +1 -1
- package/admin/presentation/BackgroundTaskSettings/BackgroundTaskSettingsPresenter.js +2 -2
- package/admin/presentation/BackgroundTaskSettings/BackgroundTaskSettingsPresenter.js.map +1 -1
- package/admin/presentation/TaskDetail/TaskDetailPresenter.js +1 -1
- package/admin/presentation/TaskDetail/TaskDetailPresenter.js.map +1 -1
- package/admin/presentation/TaskExecutions/TaskExecutionsDataSource.js +1 -1
- package/admin/presentation/TaskExecutions/TaskExecutionsDataSource.js.map +1 -1
- package/admin/presentation/TaskExecutions/TaskExecutionsPresenter.d.ts +2 -0
- package/admin/presentation/TaskExecutions/TaskExecutionsPresenter.js +3 -1
- package/admin/presentation/TaskExecutions/TaskExecutionsPresenter.js.map +1 -1
- package/api/BackgroundTasksFeature.d.ts +4 -0
- package/api/BackgroundTasksFeature.js +59 -0
- package/api/BackgroundTasksFeature.js.map +1 -0
- package/api/TasksCrud.d.ts +10 -0
- package/api/TasksCrud.js +5 -0
- package/api/TasksCrud.js.map +1 -0
- package/api/abstractions/Timer.d.ts +1 -0
- package/api/abstractions/Timer.js +0 -0
- package/api/abstractions/index.d.ts +1 -0
- package/api/abstractions/index.js +1 -0
- package/api/crud/cleanupTaskSubtree.d.ts +2 -2
- package/api/crud/cleanupTaskSubtree.js +8 -7
- package/api/crud/cleanupTaskSubtree.js.map +1 -1
- package/api/crud/crud.tasks.d.ts +3 -2
- package/api/crud/crud.tasks.js +37 -37
- package/api/crud/crud.tasks.js.map +1 -1
- package/api/crud/definition.tasks.d.ts +3 -2
- package/api/crud/definition.tasks.js +3 -3
- package/api/crud/definition.tasks.js.map +1 -1
- package/api/crud/service.tasks.d.ts +3 -2
- package/api/crud/service.tasks.js +21 -19
- package/api/crud/service.tasks.js.map +1 -1
- package/api/decorators/RunnableTaskDecorator.d.ts +1 -1
- package/api/decorators/RunnableTaskDecorator.js +2 -2
- package/api/decorators/RunnableTaskDecorator.js.map +1 -1
- package/api/decorators/SelfCleaningTaskDecorator.d.ts +1 -1
- package/api/domain/TaskService.d.ts +12 -0
- package/api/domain/TaskService.js +5 -0
- package/api/domain/TaskService.js.map +1 -0
- package/api/features/AbortTask/AbortTaskUseCase.d.ts +2 -3
- package/api/features/AbortTask/AbortTaskUseCase.js +3 -3
- package/api/features/AbortTask/AbortTaskUseCase.js.map +1 -1
- package/api/features/AbortTask/feature.d.ts +1 -2
- package/api/features/AbortTask/feature.js +3 -2
- package/api/features/AbortTask/feature.js.map +1 -1
- package/api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.d.ts +3 -3
- package/api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js +3 -3
- package/api/features/CleanupTaskSubtree/CleanupTaskSubtreeUseCase.js.map +1 -1
- package/api/features/GetBackgroundTaskSettings/GetBackgroundTaskSettingsRepository.js +7 -4
- package/api/features/GetBackgroundTaskSettings/GetBackgroundTaskSettingsRepository.js.map +1 -1
- package/api/features/GetTask/GetTaskUseCase.d.ts +3 -3
- package/api/features/GetTask/GetTaskUseCase.js +3 -3
- package/api/features/GetTask/GetTaskUseCase.js.map +1 -1
- package/api/features/GetTask/feature.d.ts +1 -2
- package/api/features/GetTask/feature.js +3 -2
- package/api/features/GetTask/feature.js.map +1 -1
- package/api/features/ListTasks/ListTasksUseCase.d.ts +4 -3
- package/api/features/ListTasks/ListTasksUseCase.js +3 -3
- package/api/features/ListTasks/ListTasksUseCase.js.map +1 -1
- package/api/features/ListTasks/feature.d.ts +1 -2
- package/api/features/ListTasks/feature.js +3 -2
- package/api/features/ListTasks/feature.js.map +1 -1
- package/api/features/TaskController/TaskController.d.ts +2 -2
- package/api/features/TaskExecutionContext/TaskExecutionContext.d.ts +3 -3
- package/api/features/TaskExecutionContext/TaskExecutionContext.js.map +1 -1
- package/api/features/TaskExecutionContext/abstractions.d.ts +3 -3
- package/api/features/TaskExecutionContext/abstractions.js.map +1 -1
- package/api/features/TriggerTask/TriggerTaskUseCase.d.ts +2 -3
- package/api/features/TriggerTask/TriggerTaskUseCase.js +3 -3
- package/api/features/TriggerTask/TriggerTaskUseCase.js.map +1 -1
- package/api/features/TriggerTask/feature.d.ts +1 -2
- package/api/features/TriggerTask/feature.js +3 -2
- package/api/features/TriggerTask/feature.js.map +1 -1
- package/api/features/UpdateBackgroundTaskSettings/UpdateBackgroundTaskSettingsRepository.js +3 -2
- package/api/features/UpdateBackgroundTaskSettings/UpdateBackgroundTaskSettingsRepository.js.map +1 -1
- package/api/graphql/BackgroundTasksContextualSchema.d.ts +21 -0
- package/api/graphql/BackgroundTasksContextualSchema.js +369 -0
- package/api/graphql/BackgroundTasksContextualSchema.js.map +1 -0
- package/api/graphql/checkPermissions.js +2 -1
- package/api/graphql/checkPermissions.js.map +1 -1
- package/api/graphql/utils.d.ts +3 -3
- package/api/graphql/utils.js +1 -1
- package/api/graphql/utils.js.map +1 -1
- package/api/handler/types.d.ts +0 -2
- package/api/index.d.ts +10 -3
- package/api/index.js +9 -3
- package/api/response/DatabaseResponse.js +1 -1
- package/api/response/DatabaseResponse.js.map +1 -1
- package/api/runner/TaskControl.js +11 -8
- package/api/runner/TaskControl.js.map +1 -1
- package/api/runner/TaskManager.js +2 -1
- package/api/runner/TaskManager.js.map +1 -1
- package/api/runner/TaskManagerStore.d.ts +3 -2
- package/api/runner/TaskManagerStore.js +5 -3
- package/api/runner/TaskManagerStore.js.map +1 -1
- package/api/runner/TaskRunner.d.ts +3 -3
- package/api/runner/TaskRunner.js.map +1 -1
- package/api/runner/abstractions/TaskRunner.d.ts +2 -2
- package/api/service/createService.d.ts +3 -3
- package/api/service/createService.js +5 -10
- package/api/service/createService.js.map +1 -1
- package/api/service/index.d.ts +1 -4
- package/api/service/index.js +1 -12
- package/api/types.d.ts +2 -2
- package/api/types.js.map +1 -1
- package/package.json +26 -20
- package/api/context.d.ts +0 -2
- package/api/context.js +0 -66
- package/api/context.js.map +0 -1
- package/api/graphql/BackgroundTaskSettingsSchema.d.ts +0 -2
- package/api/graphql/BackgroundTaskSettingsSchema.js +0 -84
- package/api/graphql/BackgroundTaskSettingsSchema.js.map +0 -1
- package/api/graphql/index.d.ts +0 -2
- package/api/graphql/index.js +0 -302
- package/api/graphql/index.js.map +0 -1
- package/api/handler/index.d.ts +0 -6
- package/api/handler/index.js +0 -55
- package/api/handler/index.js.map +0 -1
- package/api/handler/register.d.ts +0 -1
- package/api/handler/register.js +0 -15
- package/api/handler/register.js.map +0 -1
- package/api/plugins/TaskServicePlugin.d.ts +0 -19
- package/api/plugins/TaskServicePlugin.js +0 -13
- package/api/plugins/TaskServicePlugin.js.map +0 -1
- package/api/plugins/index.d.ts +0 -1
- package/api/plugins/index.js +0 -1
- package/api/service/EventBridgeEventTransportPlugin.d.ts +0 -16
- package/api/service/EventBridgeEventTransportPlugin.js +0 -52
- package/api/service/EventBridgeEventTransportPlugin.js.map +0 -1
- package/api/service/StepFunctionServicePlugin.d.ts +0 -25
- package/api/service/StepFunctionServicePlugin.js +0 -77
- package/api/service/StepFunctionServicePlugin.js.map +0 -1
- package/api/service/index.js.map +0 -1
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
import type { ITask } from "../../api/types.js";
|
|
3
|
-
export interface ITaskServiceCreatePluginParams {
|
|
4
|
-
getTenant(): string;
|
|
5
|
-
}
|
|
6
|
-
export type ITaskServiceTask = Pick<ITask, "id" | "definitionId">;
|
|
7
|
-
export interface ITaskService {
|
|
8
|
-
send(task: ITaskServiceTask, delay: number): Promise<unknown | null>;
|
|
9
|
-
fetch(task: ITask): Promise<unknown | null>;
|
|
10
|
-
}
|
|
11
|
-
export interface ITaskServicePluginParams {
|
|
12
|
-
default?: boolean;
|
|
13
|
-
}
|
|
14
|
-
export declare abstract class TaskServicePlugin extends Plugin {
|
|
15
|
-
static readonly type: string;
|
|
16
|
-
readonly default: boolean;
|
|
17
|
-
constructor(params?: ITaskServicePluginParams);
|
|
18
|
-
abstract createService(params: ITaskServiceCreatePluginParams): ITaskService;
|
|
19
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
class TaskServicePlugin extends Plugin {
|
|
3
|
-
static{
|
|
4
|
-
this.type = "tasks.taskService";
|
|
5
|
-
}
|
|
6
|
-
constructor(params){
|
|
7
|
-
super();
|
|
8
|
-
this.default = !!params?.default;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export { TaskServicePlugin };
|
|
12
|
-
|
|
13
|
-
//# sourceMappingURL=TaskServicePlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api/plugins/TaskServicePlugin.js","sources":["../../../src/api/plugins/TaskServicePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { ITask } from \"~/api/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/api/plugins/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./TaskServicePlugin.js";
|
package/api/plugins/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./TaskServicePlugin.js";
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ITaskService, ITaskServiceCreatePluginParams, ITaskServiceTask } from "../../api/plugins/index.js";
|
|
2
|
-
import { TaskServicePlugin } from "../../api/plugins/index.js";
|
|
3
|
-
import type { PutEventsCommandOutput } from "@webiny/aws-sdk/client-eventbridge/index.js";
|
|
4
|
-
import type { GenericRecord } from "@webiny/api/types.js";
|
|
5
|
-
declare class EventBridgeService implements ITaskService {
|
|
6
|
-
protected readonly getTenant: () => string;
|
|
7
|
-
private readonly client;
|
|
8
|
-
constructor(params: ITaskServiceCreatePluginParams);
|
|
9
|
-
send(task: ITaskServiceTask, delay: number): Promise<PutEventsCommandOutput>;
|
|
10
|
-
fetch(): Promise<GenericRecord>;
|
|
11
|
-
}
|
|
12
|
-
export declare class EventBridgeEventTransportPlugin extends TaskServicePlugin {
|
|
13
|
-
name: string;
|
|
14
|
-
createService(params: ITaskServiceCreatePluginParams): EventBridgeService;
|
|
15
|
-
}
|
|
16
|
-
export {};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { TaskServicePlugin } from "../plugins/index.js";
|
|
2
|
-
import { EventBridgeClient, PutEventsCommand } from "@webiny/aws-sdk/client-eventbridge/index.js";
|
|
3
|
-
import { WebinyError } from "@webiny/error";
|
|
4
|
-
class EventBridgeService {
|
|
5
|
-
constructor(params){
|
|
6
|
-
this.client = new EventBridgeClient({
|
|
7
|
-
region: process.env.AWS_REGION
|
|
8
|
-
});
|
|
9
|
-
this.getTenant = params.getTenant;
|
|
10
|
-
}
|
|
11
|
-
async send(task, delay) {
|
|
12
|
-
const event = {
|
|
13
|
-
webinyTaskId: task.id,
|
|
14
|
-
webinyTaskDefinitionId: task.definitionId,
|
|
15
|
-
tenant: this.getTenant(),
|
|
16
|
-
delay
|
|
17
|
-
};
|
|
18
|
-
const cmd = new PutEventsCommand({
|
|
19
|
-
Entries: [
|
|
20
|
-
{
|
|
21
|
-
Source: "webiny-api-tasks",
|
|
22
|
-
EventBusName: String(process.env.EVENT_BUS),
|
|
23
|
-
DetailType: "WebinyBackgroundTask",
|
|
24
|
-
Detail: JSON.stringify(event)
|
|
25
|
-
}
|
|
26
|
-
]
|
|
27
|
-
});
|
|
28
|
-
try {
|
|
29
|
-
const result = await this.client.send(cmd);
|
|
30
|
-
return JSON.parse(JSON.stringify(result));
|
|
31
|
-
} catch (ex) {
|
|
32
|
-
throw new WebinyError(ex.message || "Could not trigger task via Event Bridge!", ex.code || "TRIGGER_TASK_ERROR", {
|
|
33
|
-
event,
|
|
34
|
-
...ex.data || {}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
async fetch() {
|
|
39
|
-
throw new WebinyError("Not implemented!", "NOT_IMPLEMENTED");
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
class EventBridgeEventTransportPlugin extends TaskServicePlugin {
|
|
43
|
-
createService(params) {
|
|
44
|
-
return new EventBridgeService(params);
|
|
45
|
-
}
|
|
46
|
-
constructor(...args){
|
|
47
|
-
super(...args), this.name = "task.eventBridgeEventTransport";
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export { EventBridgeEventTransportPlugin };
|
|
51
|
-
|
|
52
|
-
//# sourceMappingURL=EventBridgeEventTransportPlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api/service/EventBridgeEventTransportPlugin.js","sources":["../../../src/api/service/EventBridgeEventTransportPlugin.ts"],"sourcesContent":["import type {\n ITaskService,\n ITaskServiceCreatePluginParams,\n ITaskServiceTask\n} from \"~/api/plugins/index.js\";\nimport { TaskServicePlugin } from \"~/api/plugins/index.js\";\nimport type { ITaskEventInput } from \"~/api/types.js\";\nimport type { PutEventsCommandOutput } from \"@webiny/aws-sdk/client-eventbridge/index.js\";\nimport { EventBridgeClient, PutEventsCommand } from \"@webiny/aws-sdk/client-eventbridge/index.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nclass EventBridgeService implements ITaskService {\n protected readonly getTenant: () => string;\n private readonly client: EventBridgeClient;\n\n public constructor(params: ITaskServiceCreatePluginParams) {\n this.client = new EventBridgeClient({\n region: process.env.AWS_REGION\n });\n this.getTenant = params.getTenant;\n }\n\n public async send(task: ITaskServiceTask, delay: number): Promise<PutEventsCommandOutput> {\n /**\n * The ITaskEvent is what our handler expect to get.\n * Endpoint and stateMachineId are added by the step function.\n */\n const event: ITaskEventInput = {\n webinyTaskId: task.id,\n webinyTaskDefinitionId: task.definitionId,\n tenant: this.getTenant(),\n delay\n };\n\n const cmd = new PutEventsCommand({\n Entries: [\n {\n Source: \"webiny-api-tasks\",\n EventBusName: String(process.env.EVENT_BUS),\n DetailType: \"WebinyBackgroundTask\",\n Detail: JSON.stringify(event)\n }\n ]\n });\n try {\n const result = await this.client.send(cmd);\n\n return JSON.parse(JSON.stringify(result));\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not trigger task via Event Bridge!\",\n ex.code || \"TRIGGER_TASK_ERROR\",\n {\n event,\n ...(ex.data || {})\n }\n );\n }\n }\n\n public async fetch(): Promise<GenericRecord> {\n throw new WebinyError(\"Not implemented!\", \"NOT_IMPLEMENTED\");\n }\n}\n\nexport class EventBridgeEventTransportPlugin extends TaskServicePlugin {\n public override name = \"task.eventBridgeEventTransport\";\n public createService(params: ITaskServiceCreatePluginParams) {\n return new EventBridgeService(params);\n }\n}\n"],"names":["EventBridgeService","params","EventBridgeClient","process","task","delay","event","cmd","PutEventsCommand","String","JSON","result","ex","WebinyError","EventBridgeEventTransportPlugin","TaskServicePlugin"],"mappings":";;;AAYA,MAAMA;IAIF,YAAmBC,MAAsC,CAAE;QACvD,IAAI,CAAC,MAAM,GAAG,IAAIC,kBAAkB;YAChC,QAAQC,QAAQ,GAAG,CAAC,UAAU;QAClC;QACA,IAAI,CAAC,SAAS,GAAGF,OAAO,SAAS;IACrC;IAEA,MAAa,KAAKG,IAAsB,EAAEC,KAAa,EAAmC;QAKtF,MAAMC,QAAyB;YAC3B,cAAcF,KAAK,EAAE;YACrB,wBAAwBA,KAAK,YAAY;YACzC,QAAQ,IAAI,CAAC,SAAS;YACtBC;QACJ;QAEA,MAAME,MAAM,IAAIC,iBAAiB;YAC7B,SAAS;gBACL;oBACI,QAAQ;oBACR,cAAcC,OAAON,QAAQ,GAAG,CAAC,SAAS;oBAC1C,YAAY;oBACZ,QAAQO,KAAK,SAAS,CAACJ;gBAC3B;aACH;QACL;QACA,IAAI;YACA,MAAMK,SAAS,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAACJ;YAEtC,OAAOG,KAAK,KAAK,CAACA,KAAK,SAAS,CAACC;QACrC,EAAE,OAAOC,IAAI;YACT,MAAM,IAAIC,YACND,GAAG,OAAO,IAAI,4CACdA,GAAG,IAAI,IAAI,sBACX;gBACIN;gBACA,GAAIM,GAAG,IAAI,IAAI,CAAC,CAAC;YACrB;QAER;IACJ;IAEA,MAAa,QAAgC;QACzC,MAAM,IAAIC,YAAY,oBAAoB;IAC9C;AACJ;AAEO,MAAMC,wCAAwCC;IAE1C,cAAcd,MAAsC,EAAE;QACzD,OAAO,IAAID,mBAAmBC;IAClC;;QAJG,qBACa,IAAI,GAAG;;AAI3B"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { ITaskService, ITaskServiceCreatePluginParams, ITaskServiceTask } from "../../api/plugins/index.js";
|
|
2
|
-
import { TaskServicePlugin } from "../../api/plugins/index.js";
|
|
3
|
-
import type { DescribeExecutionCommandOutput } from "@webiny/aws-sdk/client-sfn/index.js";
|
|
4
|
-
import type { ITask } from "../../api/types.js";
|
|
5
|
-
export type IStepFunctionServiceFetchResult = DescribeExecutionCommandOutput;
|
|
6
|
-
export interface IDetailWrapper<T> {
|
|
7
|
-
detail: T;
|
|
8
|
-
}
|
|
9
|
-
export declare class StepFunctionService implements ITaskService {
|
|
10
|
-
private readonly getTenant;
|
|
11
|
-
private readonly trigger;
|
|
12
|
-
private readonly get;
|
|
13
|
-
constructor(params: ITaskServiceCreatePluginParams);
|
|
14
|
-
send(task: ITaskServiceTask, delay: number): Promise<{
|
|
15
|
-
name: string;
|
|
16
|
-
executionArn: string | undefined;
|
|
17
|
-
startDate: Date | undefined;
|
|
18
|
-
$metadata: import("@smithy/types").ResponseMetadata;
|
|
19
|
-
} | null>;
|
|
20
|
-
fetch(task: ITask): Promise<IStepFunctionServiceFetchResult | null>;
|
|
21
|
-
}
|
|
22
|
-
export declare class StepFunctionServicePlugin extends TaskServicePlugin {
|
|
23
|
-
name: string;
|
|
24
|
-
createService(params: ITaskServiceCreatePluginParams): StepFunctionService;
|
|
25
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { TaskServicePlugin } from "../plugins/index.js";
|
|
2
|
-
import { createStepFunctionClient, describeExecutionFactory, triggerStepFunctionFactory } from "@webiny/aws-sdk/client-sfn/index.js";
|
|
3
|
-
import { generateAlphaNumericId } from "@webiny/utils";
|
|
4
|
-
import { ServiceDiscovery } from "@webiny/api";
|
|
5
|
-
class StepFunctionService {
|
|
6
|
-
constructor(params){
|
|
7
|
-
this.getTenant = params.getTenant;
|
|
8
|
-
const client = createStepFunctionClient();
|
|
9
|
-
this.trigger = triggerStepFunctionFactory(client);
|
|
10
|
-
this.get = describeExecutionFactory(client);
|
|
11
|
-
}
|
|
12
|
-
async send(task, delay) {
|
|
13
|
-
const manifest = await ServiceDiscovery.load();
|
|
14
|
-
if (!manifest) {
|
|
15
|
-
console.error("Service manifest not found.");
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
const { bgTaskSfn } = manifest.api || {};
|
|
19
|
-
if (!bgTaskSfn) {
|
|
20
|
-
console.error("Background task state machine not found.");
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
const input = {
|
|
24
|
-
webinyTaskId: task.id,
|
|
25
|
-
webinyTaskDefinitionId: task.definitionId,
|
|
26
|
-
tenant: this.getTenant(),
|
|
27
|
-
delay
|
|
28
|
-
};
|
|
29
|
-
const name = `${task.definitionId}_${task.id}_${generateAlphaNumericId(10)}`;
|
|
30
|
-
try {
|
|
31
|
-
const result = await this.trigger({
|
|
32
|
-
input: {
|
|
33
|
-
detail: input
|
|
34
|
-
},
|
|
35
|
-
stateMachineArn: bgTaskSfn,
|
|
36
|
-
name
|
|
37
|
-
});
|
|
38
|
-
return {
|
|
39
|
-
...result,
|
|
40
|
-
name
|
|
41
|
-
};
|
|
42
|
-
} catch (ex) {
|
|
43
|
-
console.log("Could not trigger a step function.");
|
|
44
|
-
console.error(ex);
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async fetch(task) {
|
|
49
|
-
const executionArn = task.eventResponse?.executionArn;
|
|
50
|
-
if (!executionArn) {
|
|
51
|
-
console.error(`Execution ARN not found in task "${task.id}".`);
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
try {
|
|
55
|
-
const result = await this.get({
|
|
56
|
-
executionArn
|
|
57
|
-
});
|
|
58
|
-
if (!result) return null;
|
|
59
|
-
return JSON.parse(JSON.stringify(result));
|
|
60
|
-
} catch (ex) {
|
|
61
|
-
console.log("Could not get the execution details.");
|
|
62
|
-
console.error(ex);
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
class StepFunctionServicePlugin extends TaskServicePlugin {
|
|
68
|
-
createService(params) {
|
|
69
|
-
return new StepFunctionService(params);
|
|
70
|
-
}
|
|
71
|
-
constructor(...args){
|
|
72
|
-
super(...args), this.name = "task.stepFunctionTriggerTransport";
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
export { StepFunctionService, StepFunctionServicePlugin };
|
|
76
|
-
|
|
77
|
-
//# sourceMappingURL=StepFunctionServicePlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api/service/StepFunctionServicePlugin.js","sources":["../../../src/api/service/StepFunctionServicePlugin.ts"],"sourcesContent":["import type {\n ITaskService,\n ITaskServiceCreatePluginParams,\n ITaskServiceTask\n} from \"~/api/plugins/index.js\";\nimport { TaskServicePlugin } from \"~/api/plugins/index.js\";\nimport type { DescribeExecutionCommandOutput } from \"@webiny/aws-sdk/client-sfn/index.js\";\nimport {\n createStepFunctionClient,\n describeExecutionFactory,\n triggerStepFunctionFactory\n} from \"@webiny/aws-sdk/client-sfn/index.js\";\nimport type { ITaskEventInput } from \"~/api/handler/types.js\";\nimport { generateAlphaNumericId } from \"@webiny/utils\";\nimport { ServiceDiscovery } from \"@webiny/api\";\nimport type { ITask } from \"~/api/types.js\";\n\nexport type IStepFunctionServiceFetchResult = DescribeExecutionCommandOutput;\n\nexport interface IDetailWrapper<T> {\n detail: T;\n}\n\nexport class StepFunctionService implements ITaskService {\n private readonly getTenant: () => string;\n private readonly trigger: ReturnType<typeof triggerStepFunctionFactory>;\n private readonly get: ReturnType<typeof describeExecutionFactory>;\n\n public constructor(params: ITaskServiceCreatePluginParams) {\n this.getTenant = params.getTenant;\n const client = createStepFunctionClient();\n this.trigger = triggerStepFunctionFactory(client);\n this.get = describeExecutionFactory(client);\n }\n public async send(task: ITaskServiceTask, delay: number) {\n const manifest = await ServiceDiscovery.load();\n if (!manifest) {\n console.error(\"Service manifest not found.\");\n return null;\n }\n const { bgTaskSfn } = manifest.api || {};\n if (!bgTaskSfn) {\n console.error(\"Background task state machine not found.\");\n return null;\n }\n\n const input: ITaskEventInput = {\n webinyTaskId: task.id,\n webinyTaskDefinitionId: task.definitionId,\n tenant: this.getTenant(),\n delay\n };\n const name = `${task.definitionId}_${task.id}_${generateAlphaNumericId(10)}`;\n try {\n const result = await this.trigger<IDetailWrapper<ITaskEventInput>>({\n input: {\n detail: input\n },\n stateMachineArn: bgTaskSfn,\n name\n });\n return {\n ...result,\n name\n };\n } catch (ex) {\n console.log(\"Could not trigger a step function.\");\n console.error(ex);\n return null;\n }\n }\n\n public async fetch(task: ITask): Promise<IStepFunctionServiceFetchResult | null> {\n const executionArn = task.eventResponse?.executionArn;\n if (!executionArn) {\n console.error(`Execution ARN not found in task \"${task.id}\".`);\n return null;\n }\n try {\n const result = await this.get({\n executionArn\n });\n if (!result) {\n return null;\n }\n return JSON.parse(JSON.stringify(result));\n } catch (ex) {\n console.log(\"Could not get the execution details.\");\n console.error(ex);\n return null;\n }\n }\n}\n\nexport class StepFunctionServicePlugin extends TaskServicePlugin {\n public override name = \"task.stepFunctionTriggerTransport\";\n\n public createService(params: ITaskServiceCreatePluginParams) {\n return new StepFunctionService(params);\n }\n}\n"],"names":["StepFunctionService","params","client","createStepFunctionClient","triggerStepFunctionFactory","describeExecutionFactory","task","delay","manifest","ServiceDiscovery","console","bgTaskSfn","input","name","generateAlphaNumericId","result","ex","executionArn","JSON","StepFunctionServicePlugin","TaskServicePlugin"],"mappings":";;;;AAuBO,MAAMA;IAKT,YAAmBC,MAAsC,CAAE;QACvD,IAAI,CAAC,SAAS,GAAGA,OAAO,SAAS;QACjC,MAAMC,SAASC;QACf,IAAI,CAAC,OAAO,GAAGC,2BAA2BF;QAC1C,IAAI,CAAC,GAAG,GAAGG,yBAAyBH;IACxC;IACA,MAAa,KAAKI,IAAsB,EAAEC,KAAa,EAAE;QACrD,MAAMC,WAAW,MAAMC,iBAAiB,IAAI;QAC5C,IAAI,CAACD,UAAU;YACXE,QAAQ,KAAK,CAAC;YACd,OAAO;QACX;QACA,MAAM,EAAEC,SAAS,EAAE,GAAGH,SAAS,GAAG,IAAI,CAAC;QACvC,IAAI,CAACG,WAAW;YACZD,QAAQ,KAAK,CAAC;YACd,OAAO;QACX;QAEA,MAAME,QAAyB;YAC3B,cAAcN,KAAK,EAAE;YACrB,wBAAwBA,KAAK,YAAY;YACzC,QAAQ,IAAI,CAAC,SAAS;YACtBC;QACJ;QACA,MAAMM,OAAO,GAAGP,KAAK,YAAY,CAAC,CAAC,EAAEA,KAAK,EAAE,CAAC,CAAC,EAAEQ,uBAAuB,KAAK;QAC5E,IAAI;YACA,MAAMC,SAAS,MAAM,IAAI,CAAC,OAAO,CAAkC;gBAC/D,OAAO;oBACH,QAAQH;gBACZ;gBACA,iBAAiBD;gBACjBE;YACJ;YACA,OAAO;gBACH,GAAGE,MAAM;gBACTF;YACJ;QACJ,EAAE,OAAOG,IAAI;YACTN,QAAQ,GAAG,CAAC;YACZA,QAAQ,KAAK,CAACM;YACd,OAAO;QACX;IACJ;IAEA,MAAa,MAAMV,IAAW,EAAmD;QAC7E,MAAMW,eAAeX,KAAK,aAAa,EAAE;QACzC,IAAI,CAACW,cAAc;YACfP,QAAQ,KAAK,CAAC,CAAC,iCAAiC,EAAEJ,KAAK,EAAE,CAAC,EAAE,CAAC;YAC7D,OAAO;QACX;QACA,IAAI;YACA,MAAMS,SAAS,MAAM,IAAI,CAAC,GAAG,CAAC;gBAC1BE;YACJ;YACA,IAAI,CAACF,QACD,OAAO;YAEX,OAAOG,KAAK,KAAK,CAACA,KAAK,SAAS,CAACH;QACrC,EAAE,OAAOC,IAAI;YACTN,QAAQ,GAAG,CAAC;YACZA,QAAQ,KAAK,CAACM;YACd,OAAO;QACX;IACJ;AACJ;AAEO,MAAMG,kCAAkCC;IAGpC,cAAcnB,MAAsC,EAAE;QACzD,OAAO,IAAID,oBAAoBC;IACnC;;QALG,qBACa,IAAI,GAAG;;AAK3B"}
|
package/api/service/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api/service/index.js","sources":["../../../src/api/service/index.ts"],"sourcesContent":["import { EventBridgeEventTransportPlugin } from \"./EventBridgeEventTransportPlugin.js\";\nimport { StepFunctionServicePlugin } from \"./StepFunctionServicePlugin.js\";\n\nexport const createServicePlugins = () => {\n return [\n new StepFunctionServicePlugin({ default: true }),\n new EventBridgeEventTransportPlugin()\n ];\n};\n\nexport * from \"./createService.js\";\n"],"names":["createServicePlugins","StepFunctionServicePlugin","EventBridgeEventTransportPlugin"],"mappings":";;;AAGO,MAAMA,uBAAuB,IACzB;QACH,IAAIC,0BAA0B;YAAE,SAAS;QAAK;QAC9C,IAAIC;KACP"}
|