@webiny/background-tasks-aws 0.0.0-unstable.0d717d18dd

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.
@@ -0,0 +1,13 @@
1
+ import type { Container } from "@webiny/feature/api";
2
+ import { BackgroundTaskEventHandler } from "@webiny/event-handler-aws/abstractions/handlers/BackgroundTaskEventHandler.js";
3
+ import type { EventContext, NextFunction } from "@webiny/event-handler-core";
4
+ import type { IBackgroundTaskEvent } from "@webiny/event-handler-aws/eventTypes/BackgroundTaskEventType.js";
5
+ declare class BackgroundTaskLambdaHandlerImpl implements BackgroundTaskEventHandler.Interface {
6
+ private container;
7
+ constructor(container: Container);
8
+ execute(eventCtx: EventContext<IBackgroundTaskEvent>, _next: NextFunction): Promise<unknown>;
9
+ }
10
+ export declare const BackgroundTaskLambdaHandler: typeof BackgroundTaskLambdaHandlerImpl & {
11
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/event-handler-aws/abstractions/handlers/BackgroundTaskEventHandler.js").IBackgroundTaskEventHandler>;
12
+ };
13
+ export {};
@@ -0,0 +1,48 @@
1
+ import { AwsLambdaContext } from "@webiny/event-handler-aws/abstractions/AwsLambdaContext.js";
2
+ import { BackgroundTaskEventHandler } from "@webiny/event-handler-aws/abstractions/handlers/BackgroundTaskEventHandler.js";
3
+ import { GraphQLContextEnhancer, GraphQLContextualSchema } from "@webiny/api-graphql";
4
+ import { RequestContainer, runRequestContextInitializers } from "@webiny/event-handler-core";
5
+ import { RawTenantId, RequestTenantLoader } from "@webiny/api-core/features/requestContext/index.js";
6
+ import { TaskRunner } from "@webiny/background-tasks/api/runner/index.js";
7
+ import { TaskEventValidation } from "@webiny/background-tasks/api/runner/TaskEventValidation.js";
8
+ import { LambdaTimer } from "./timer/LambdaTimer.js";
9
+ const FALLBACK_MAX_RUNNING_MILLISECONDS = 840000;
10
+ class BackgroundTaskLambdaHandlerImpl {
11
+ constructor(container){
12
+ this.container = container;
13
+ }
14
+ async execute(eventCtx, _next) {
15
+ const fallbackStartTime = Date.now();
16
+ const taskEvent = eventCtx.event?.payload || eventCtx.event;
17
+ if (taskEvent?.tenant) {
18
+ this.container.resolve(RawTenantId).set(taskEvent.tenant);
19
+ await this.container.resolve(RequestTenantLoader).establish();
20
+ }
21
+ await runRequestContextInitializers(this.container, {
22
+ continueOnError: true
23
+ });
24
+ const ctx = {
25
+ container: this.container
26
+ };
27
+ for (const enhancer of this.container.resolveAll(GraphQLContextEnhancer))await enhancer.enhance(ctx);
28
+ for (const schema of this.container.resolveAll(GraphQLContextualSchema))await schema.build(ctx);
29
+ const lambdaContext = this.container.resolve(AwsLambdaContext);
30
+ const timer = new LambdaTimer({
31
+ getRemainingTimeInMillis: ()=>{
32
+ if (lambdaContext.isSet()) return lambdaContext.get().getRemainingTimeInMillis();
33
+ return fallbackStartTime + FALLBACK_MAX_RUNNING_MILLISECONDS - Date.now();
34
+ }
35
+ });
36
+ const runner = new TaskRunner(ctx, timer, new TaskEventValidation());
37
+ return runner.run(taskEvent);
38
+ }
39
+ }
40
+ const BackgroundTaskLambdaHandler = BackgroundTaskEventHandler.createImplementation({
41
+ implementation: BackgroundTaskLambdaHandlerImpl,
42
+ dependencies: [
43
+ RequestContainer
44
+ ]
45
+ });
46
+ export { BackgroundTaskLambdaHandler };
47
+
48
+ //# sourceMappingURL=BackgroundTaskLambdaHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BackgroundTaskLambdaHandler.js","sources":["../src/BackgroundTaskLambdaHandler.ts"],"sourcesContent":["import type { Container } from \"@webiny/feature/api\";\nimport { AwsLambdaContext } from \"@webiny/event-handler-aws/abstractions/AwsLambdaContext.js\";\nimport { BackgroundTaskEventHandler } from \"@webiny/event-handler-aws/abstractions/handlers/BackgroundTaskEventHandler.js\";\nimport { GraphQLContextEnhancer, GraphQLContextualSchema } from \"@webiny/api-graphql\";\nimport { RequestContainer, runRequestContextInitializers } from \"@webiny/event-handler-core\";\nimport {\n RawTenantId,\n RequestTenantLoader\n} from \"@webiny/api-core/features/requestContext/index.js\";\nimport type { EventContext, NextFunction } from \"@webiny/event-handler-core\";\nimport type { IBackgroundTaskEvent } from \"@webiny/event-handler-aws/eventTypes/BackgroundTaskEventType.js\";\nimport { TaskRunner } from \"@webiny/background-tasks/api/runner/index.js\";\nimport { TaskEventValidation } from \"@webiny/background-tasks/api/runner/TaskEventValidation.js\";\nimport type { Context } from \"@webiny/background-tasks/api/types.js\";\nimport { LambdaTimer } from \"~/timer/LambdaTimer.js\";\n\n/* Fallback ceiling used when there is no real Lambda context to read the remaining time from\n * (mirrors the default Lambda timeout budget handler-aws's CustomTimer uses). */\nconst FALLBACK_MAX_RUNNING_MILLISECONDS = 14 * 60 * 1000;\n\nclass BackgroundTaskLambdaHandlerImpl implements BackgroundTaskEventHandler.Interface {\n constructor(private container: Container) {}\n\n async execute(\n eventCtx: EventContext<IBackgroundTaskEvent>,\n _next: NextFunction\n ): Promise<unknown> {\n // Date-based fallback in case there is no real Lambda context (see below) — captured up\n // front so the fallback countdown starts at the beginning of this invocation.\n const fallbackStartTime = Date.now();\n // The SFN/EventBridge transport wraps the task as `{ name, payload }`; TaskRunner expects the\n // flat task event (webinyTaskId at top level), so unwrap `payload` (falling back to the event\n // itself if it's already flat).\n const taskEvent = (eventCtx.event as any)?.payload || eventCtx.event;\n\n // Background tasks have no HTTP request establisher. This is the bg-task EXTRACT step: put the\n // tenant id from the task event into RawTenantId, then run the shared LOAD step\n // (RequestTenantLoader) — same tenant-establishment path as every other transport. The\n // CRUD (TasksCrud) and downstream use cases resolve the current tenant, so it must be set\n // before the task runs.\n if (taskEvent?.tenant) {\n this.container.resolve(RawTenantId).set(taskEvent.tenant);\n await this.container.resolve(RequestTenantLoader).establish();\n }\n\n // Run the post-context initializers (register TasksCrud, FileModel, etc.). The HTTP layer does\n // this via RequestContextInitializerDecorator; the bg-task chain must do it too, before the\n // task runs — otherwise TaskControl can't resolve TasksCrud. continueOnError: a task doesn't\n // need every HTTP initializer (e.g. ACO/scheduler), and some throw in the bg-task context —\n // skip+log those so they don't fail the task, while TasksCrud/FileModel still register.\n await runRequestContextInitializers(this.container, { continueOnError: true });\n\n // TODO: remove once legacy ctx is gone — resolve services directly from the container.\n const ctx: Record<string, any> = { container: this.container };\n for (const enhancer of this.container.resolveAll(GraphQLContextEnhancer)) {\n await enhancer.enhance(ctx);\n }\n for (const schema of this.container.resolveAll(GraphQLContextualSchema)) {\n await schema.build(ctx);\n }\n\n // Use the real Lambda context's countdown when the invocation has one; otherwise fall back\n // to a Date-based countdown so the timer still winds down instead of staying static.\n const lambdaContext = this.container.resolve(AwsLambdaContext);\n const timer = new LambdaTimer({\n getRemainingTimeInMillis: () => {\n if (lambdaContext.isSet()) {\n return lambdaContext.get().getRemainingTimeInMillis();\n }\n return fallbackStartTime + FALLBACK_MAX_RUNNING_MILLISECONDS - Date.now();\n }\n });\n const runner = new TaskRunner(ctx as Context, timer, new TaskEventValidation());\n\n // Return the task result — the SFN reads `$.status` (continue/done/error) from it to drive\n // the state machine. Returning void makes the SFN see null → UnknownError → FAILED.\n return runner.run(taskEvent);\n }\n}\n\nexport const BackgroundTaskLambdaHandler = BackgroundTaskEventHandler.createImplementation({\n implementation: BackgroundTaskLambdaHandlerImpl,\n dependencies: [RequestContainer]\n});\n"],"names":["FALLBACK_MAX_RUNNING_MILLISECONDS","BackgroundTaskLambdaHandlerImpl","container","eventCtx","_next","fallbackStartTime","Date","taskEvent","RawTenantId","RequestTenantLoader","runRequestContextInitializers","ctx","enhancer","GraphQLContextEnhancer","schema","GraphQLContextualSchema","lambdaContext","AwsLambdaContext","timer","LambdaTimer","runner","TaskRunner","TaskEventValidation","BackgroundTaskLambdaHandler","BackgroundTaskEventHandler","RequestContainer"],"mappings":";;;;;;;;AAkBA,MAAMA,oCAAoC;AAE1C,MAAMC;IACF,YAAoBC,SAAoB,CAAE;aAAtBA,SAAS,GAATA;IAAuB;IAE3C,MAAM,QACFC,QAA4C,EAC5CC,KAAmB,EACH;QAGhB,MAAMC,oBAAoBC,KAAK,GAAG;QAIlC,MAAMC,YAAaJ,SAAS,KAAK,EAAU,WAAWA,SAAS,KAAK;QAOpE,IAAII,WAAW,QAAQ;YACnB,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC,aAAa,GAAG,CAACD,UAAU,MAAM;YACxD,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACE,qBAAqB,SAAS;QAC/D;QAOA,MAAMC,8BAA8B,IAAI,CAAC,SAAS,EAAE;YAAE,iBAAiB;QAAK;QAG5E,MAAMC,MAA2B;YAAE,WAAW,IAAI,CAAC,SAAS;QAAC;QAC7D,KAAK,MAAMC,YAAY,IAAI,CAAC,SAAS,CAAC,UAAU,CAACC,wBAC7C,MAAMD,SAAS,OAAO,CAACD;QAE3B,KAAK,MAAMG,UAAU,IAAI,CAAC,SAAS,CAAC,UAAU,CAACC,yBAC3C,MAAMD,OAAO,KAAK,CAACH;QAKvB,MAAMK,gBAAgB,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QAC7C,MAAMC,QAAQ,IAAIC,YAAY;YAC1B,0BAA0B;gBACtB,IAAIH,cAAc,KAAK,IACnB,OAAOA,cAAc,GAAG,GAAG,wBAAwB;gBAEvD,OAAOX,oBAAoBL,oCAAoCM,KAAK,GAAG;YAC3E;QACJ;QACA,MAAMc,SAAS,IAAIC,WAAWV,KAAgBO,OAAO,IAAII;QAIzD,OAAOF,OAAO,GAAG,CAACb;IACtB;AACJ;AAEO,MAAMgB,8BAA8BC,2BAA2B,oBAAoB,CAAC;IACvF,gBAAgBvB;IAChB,cAAc;QAACwB;KAAiB;AACpC"}
@@ -0,0 +1,4 @@
1
+ export declare const BackgroundTasksAwsFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,13 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { StepFunctionService } from "./service/StepFunctionService.js";
3
+ import { BackgroundTaskLambdaHandler } from "./BackgroundTaskLambdaHandler.js";
4
+ const BackgroundTasksAwsFeature = createFeature({
5
+ name: "BackgroundTasksAws",
6
+ register (container) {
7
+ container.register(BackgroundTaskLambdaHandler);
8
+ container.register(StepFunctionService);
9
+ }
10
+ });
11
+ export { BackgroundTasksAwsFeature };
12
+
13
+ //# sourceMappingURL=BackgroundTasksAwsFeature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BackgroundTasksAwsFeature.js","sources":["../src/BackgroundTasksAwsFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { StepFunctionService } from \"~/service/StepFunctionService.js\";\nimport { BackgroundTaskLambdaHandler } from \"~/BackgroundTaskLambdaHandler.js\";\n\nexport const BackgroundTasksAwsFeature = createFeature({\n name: \"BackgroundTasksAws\",\n register(container) {\n container.register(BackgroundTaskLambdaHandler);\n container.register(StepFunctionService);\n }\n});\n"],"names":["BackgroundTasksAwsFeature","createFeature","container","BackgroundTaskLambdaHandler","StepFunctionService"],"mappings":";;;AAIO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;IACvB;AACJ"}
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Webiny
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # @webiny/background-tasks-aws
2
+
3
+ > [!NOTE]
4
+ > This package is part of the [Webiny](https://www.webiny.com) monorepo.
5
+ > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
6
+
7
+ 📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
8
+
9
+ ---
10
+
11
+ _This README file is automatically generated during the publish process._
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { BackgroundTasksAwsFeature } from "./BackgroundTasksAwsFeature.js";
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export { BackgroundTasksAwsFeature } from "./BackgroundTasksAwsFeature.js";
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@webiny/background-tasks-aws",
3
+ "version": "0.0.0-unstable.0d717d18dd",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./index.js",
7
+ "./*": "./*"
8
+ },
9
+ "description": "AWS transport for Webiny background tasks (Step Functions, EventBridge, Lambda).",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/webiny/webiny-js.git",
13
+ "directory": "packages/background-tasks-aws"
14
+ },
15
+ "license": "MIT",
16
+ "dependencies": {
17
+ "@webiny/api-core": "0.0.0-unstable.0d717d18dd",
18
+ "@webiny/api-graphql": "0.0.0-unstable.0d717d18dd",
19
+ "@webiny/aws-sdk": "0.0.0-unstable.0d717d18dd",
20
+ "@webiny/background-tasks": "0.0.0-unstable.0d717d18dd",
21
+ "@webiny/event-handler-aws": "0.0.0-unstable.0d717d18dd",
22
+ "@webiny/event-handler-core": "0.0.0-unstable.0d717d18dd",
23
+ "@webiny/feature": "0.0.0-unstable.0d717d18dd",
24
+ "@webiny/utils": "0.0.0-unstable.0d717d18dd"
25
+ },
26
+ "devDependencies": {
27
+ "@webiny/build-tools": "0.0.0-unstable.0d717d18dd",
28
+ "@webiny/di": "1.0.2",
29
+ "rimraf": "6.1.3",
30
+ "typescript": "7.0.2",
31
+ "vitest": "4.1.10"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "webiny": {
37
+ "publishFrom": "dist"
38
+ }
39
+ }
@@ -0,0 +1,24 @@
1
+ import type { DescribeExecutionCommandOutput } from "@webiny/aws-sdk/client-sfn/index.js";
2
+ import { TaskService } from "@webiny/background-tasks/api/domain/TaskService.js";
3
+ import { TenantContext } from "@webiny/api-core/exports/api/tenancy.js";
4
+ export type IStepFunctionServiceFetchResult = DescribeExecutionCommandOutput;
5
+ export interface IDetailWrapper<T> {
6
+ detail: T;
7
+ }
8
+ declare class StepFunctionServiceImpl implements TaskService.Interface {
9
+ private readonly tenantContext;
10
+ private readonly trigger;
11
+ private readonly get;
12
+ constructor(tenantContext: TenantContext.Interface);
13
+ send(task: TaskService.SendTaskParams, delay: number): Promise<{
14
+ $metadata: import("@smithy/types").ResponseMetadata;
15
+ executionArn: string | undefined;
16
+ startDate: Date | undefined;
17
+ name: string;
18
+ } | null>;
19
+ fetch(task: TaskService.Task): Promise<IStepFunctionServiceFetchResult | null>;
20
+ }
21
+ export declare const StepFunctionService: typeof StepFunctionServiceImpl & {
22
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/background-tasks/api/domain/TaskService.js").ITaskService>;
23
+ };
24
+ export {};
@@ -0,0 +1,81 @@
1
+ import { createStepFunctionClient, describeExecutionFactory, triggerStepFunctionFactory } from "@webiny/aws-sdk/client-sfn/index.js";
2
+ import { generateAlphaNumericId } from "@webiny/utils";
3
+ import { ServiceDiscovery } from "@webiny/api-core/features/serviceDiscovery/index.js";
4
+ import { TaskService } from "@webiny/background-tasks/api/domain/TaskService.js";
5
+ import { TenantContext } from "@webiny/api-core/exports/api/tenancy.js";
6
+ class StepFunctionServiceImpl {
7
+ constructor(tenantContext){
8
+ this.tenantContext = tenantContext;
9
+ const client = createStepFunctionClient();
10
+ this.trigger = triggerStepFunctionFactory(client);
11
+ this.get = describeExecutionFactory(client);
12
+ }
13
+ async send(task, delay) {
14
+ const manifest = await ServiceDiscovery.load();
15
+ if (!manifest) {
16
+ console.error("Service manifest not found.");
17
+ return null;
18
+ }
19
+ const { bgTaskSfn } = manifest.api || {};
20
+ if (!bgTaskSfn) {
21
+ console.error("Background task state machine not found.");
22
+ return null;
23
+ }
24
+ const tenant = this.tenantContext.getTenant();
25
+ if (!tenant) {
26
+ console.error("Tenant not found.");
27
+ return null;
28
+ }
29
+ const input = {
30
+ webinyTaskId: task.id,
31
+ webinyTaskDefinitionId: task.definitionId,
32
+ tenant: tenant.id,
33
+ delay
34
+ };
35
+ const name = `${task.definitionId}_${task.id}_${generateAlphaNumericId(10)}`;
36
+ try {
37
+ const result = await this.trigger({
38
+ input: {
39
+ detail: input
40
+ },
41
+ stateMachineArn: bgTaskSfn,
42
+ name
43
+ });
44
+ return {
45
+ ...result,
46
+ name
47
+ };
48
+ } catch (ex) {
49
+ console.log("Could not trigger a step function.");
50
+ console.error(ex);
51
+ return null;
52
+ }
53
+ }
54
+ async fetch(task) {
55
+ const executionArn = task.eventResponse?.executionArn;
56
+ if (!executionArn) {
57
+ console.error(`Execution ARN not found in task "${task.id}".`);
58
+ return null;
59
+ }
60
+ try {
61
+ const result = await this.get({
62
+ executionArn
63
+ });
64
+ if (!result) return null;
65
+ return JSON.parse(JSON.stringify(result));
66
+ } catch (ex) {
67
+ console.log("Could not get the execution details.");
68
+ console.error(ex);
69
+ return null;
70
+ }
71
+ }
72
+ }
73
+ const StepFunctionService = TaskService.createImplementation({
74
+ implementation: StepFunctionServiceImpl,
75
+ dependencies: [
76
+ TenantContext
77
+ ]
78
+ });
79
+ export { StepFunctionService };
80
+
81
+ //# sourceMappingURL=StepFunctionService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service/StepFunctionService.js","sources":["../../src/service/StepFunctionService.ts"],"sourcesContent":["import 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 \"@webiny/background-tasks/api/handler/types.js\";\nimport { generateAlphaNumericId } from \"@webiny/utils\";\nimport { ServiceDiscovery } from \"@webiny/api-core/features/serviceDiscovery/index.js\";\nimport { TaskService } from \"@webiny/background-tasks/api/domain/TaskService.js\";\nimport { TenantContext } from \"@webiny/api-core/exports/api/tenancy.js\";\n\nexport type IStepFunctionServiceFetchResult = DescribeExecutionCommandOutput;\n\nexport interface IDetailWrapper<T> {\n detail: T;\n}\n\nclass StepFunctionServiceImpl implements TaskService.Interface {\n private readonly trigger;\n private readonly get;\n\n public constructor(private readonly tenantContext: TenantContext.Interface) {\n // TODO client must be injectable at some point via some factory + cache\n const client = createStepFunctionClient();\n this.trigger = triggerStepFunctionFactory(client);\n this.get = describeExecutionFactory(client);\n }\n public async send(task: TaskService.SendTaskParams, 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 const tenant = this.tenantContext.getTenant();\n if (!tenant) {\n console.error(\"Tenant not found.\");\n return null;\n }\n\n const input: ITaskEventInput = {\n webinyTaskId: task.id,\n webinyTaskDefinitionId: task.definitionId,\n tenant: tenant.id,\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: TaskService.Task): 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 const StepFunctionService = TaskService.createImplementation({\n implementation: StepFunctionServiceImpl,\n dependencies: [TenantContext]\n});\n"],"names":["StepFunctionServiceImpl","tenantContext","client","createStepFunctionClient","triggerStepFunctionFactory","describeExecutionFactory","task","delay","manifest","ServiceDiscovery","console","bgTaskSfn","tenant","input","name","generateAlphaNumericId","result","ex","executionArn","JSON","StepFunctionService","TaskService","TenantContext"],"mappings":";;;;;AAkBA,MAAMA;IAIF,YAAoCC,aAAsC,CAAE;aAAxCA,aAAa,GAAbA;QAEhC,MAAMC,SAASC;QACf,IAAI,CAAC,OAAO,GAAGC,2BAA2BF;QAC1C,IAAI,CAAC,GAAG,GAAGG,yBAAyBH;IACxC;IACA,MAAa,KAAKI,IAAgC,EAAEC,KAAa,EAAE;QAC/D,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;QACA,MAAME,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,IAAI,CAACA,QAAQ;YACTF,QAAQ,KAAK,CAAC;YACd,OAAO;QACX;QAEA,MAAMG,QAAyB;YAC3B,cAAcP,KAAK,EAAE;YACrB,wBAAwBA,KAAK,YAAY;YACzC,QAAQM,OAAO,EAAE;YACjBL;QACJ;QACA,MAAMO,OAAO,GAAGR,KAAK,YAAY,CAAC,CAAC,EAAEA,KAAK,EAAE,CAAC,CAAC,EAAES,uBAAuB,KAAK;QAC5E,IAAI;YACA,MAAMC,SAAS,MAAM,IAAI,CAAC,OAAO,CAAkC;gBAC/D,OAAO;oBACH,QAAQH;gBACZ;gBACA,iBAAiBF;gBACjBG;YACJ;YACA,OAAO;gBACH,GAAGE,MAAM;gBACTF;YACJ;QACJ,EAAE,OAAOG,IAAI;YACTP,QAAQ,GAAG,CAAC;YACZA,QAAQ,KAAK,CAACO;YACd,OAAO;QACX;IACJ;IAEA,MAAa,MAAMX,IAAsB,EAAmD;QACxF,MAAMY,eAAeZ,KAAK,aAAa,EAAE;QACzC,IAAI,CAACY,cAAc;YACfR,QAAQ,KAAK,CAAC,CAAC,iCAAiC,EAAEJ,KAAK,EAAE,CAAC,EAAE,CAAC;YAC7D,OAAO;QACX;QACA,IAAI;YACA,MAAMU,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;YACTP,QAAQ,GAAG,CAAC;YACZA,QAAQ,KAAK,CAACO;YACd,OAAO;QACX;IACJ;AACJ;AAEO,MAAMG,sBAAsBC,YAAY,oBAAoB,CAAC;IAChE,gBAAgBrB;IAChB,cAAc;QAACsB;KAAc;AACjC"}
@@ -0,0 +1,11 @@
1
+ import type { Timer } from "@webiny/utils/features/Timer/abstraction.js";
2
+ interface LambdaTimerFactory {
3
+ getRemainingTimeInMillis(): number;
4
+ }
5
+ export declare class LambdaTimer implements Timer.Interface {
6
+ private readonly factory;
7
+ constructor(factory: LambdaTimerFactory);
8
+ getRemainingMilliseconds(): number;
9
+ getRemainingSeconds(): number;
10
+ }
11
+ export {};
@@ -0,0 +1,14 @@
1
+ class LambdaTimer {
2
+ constructor(factory){
3
+ this.factory = factory;
4
+ }
5
+ getRemainingMilliseconds() {
6
+ return this.factory.getRemainingTimeInMillis();
7
+ }
8
+ getRemainingSeconds() {
9
+ return Math.floor(this.getRemainingMilliseconds() / 1000);
10
+ }
11
+ }
12
+ export { LambdaTimer };
13
+
14
+ //# sourceMappingURL=LambdaTimer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer/LambdaTimer.js","sources":["../../src/timer/LambdaTimer.ts"],"sourcesContent":["import type { Timer } from \"@webiny/utils/features/Timer/abstraction.js\";\n\ninterface LambdaTimerFactory {\n getRemainingTimeInMillis(): number;\n}\n\nexport class LambdaTimer implements Timer.Interface {\n private readonly factory: LambdaTimerFactory;\n\n public constructor(factory: LambdaTimerFactory) {\n this.factory = factory;\n }\n\n public getRemainingMilliseconds(): number {\n return this.factory.getRemainingTimeInMillis();\n }\n\n public getRemainingSeconds(): number {\n return Math.floor(this.getRemainingMilliseconds() / 1000);\n }\n}\n"],"names":["LambdaTimer","factory","Math"],"mappings":"AAMO,MAAMA;IAGT,YAAmBC,OAA2B,CAAE;QAC5C,IAAI,CAAC,OAAO,GAAGA;IACnB;IAEO,2BAAmC;QACtC,OAAO,IAAI,CAAC,OAAO,CAAC,wBAAwB;IAChD;IAEO,sBAA8B;QACjC,OAAOC,KAAK,KAAK,CAAC,IAAI,CAAC,wBAAwB,KAAK;IACxD;AACJ"}