@webiny/background-tasks-aws 6.6.0-alpha.0 → 6.6.0-alpha.2

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.
@@ -1,7 +1,7 @@
1
1
  import { AwsLambdaContext } from "@webiny/event-handler-aws/abstractions/AwsLambdaContext.js";
2
2
  import { BackgroundTaskEventHandler } from "@webiny/event-handler-aws/abstractions/handlers/BackgroundTaskEventHandler.js";
3
3
  import { GraphQLContextEnhancer, GraphQLContextualSchema } from "@webiny/api-graphql";
4
- import { RequestContainer, runRequestContextInitializers } from "@webiny/event-handler-core";
4
+ import { RequestContainer } from "@webiny/event-handler-core";
5
5
  import { RawTenantId, RequestTenantLoader } from "@webiny/api-core/features/requestContext/index.js";
6
6
  import { TaskRunner } from "@webiny/background-tasks/api/runner/index.js";
7
7
  import { TaskEventValidation } from "@webiny/background-tasks/api/runner/TaskEventValidation.js";
@@ -18,9 +18,6 @@ class BackgroundTaskLambdaHandlerImpl {
18
18
  this.container.resolve(RawTenantId).set(taskEvent.tenant);
19
19
  await this.container.resolve(RequestTenantLoader).establish();
20
20
  }
21
- await runRequestContextInitializers(this.container, {
22
- continueOnError: true
23
- });
24
21
  const ctx = {
25
22
  container: this.container
26
23
  };
@@ -1 +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"}
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 } 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 // 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","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;QAGA,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,OAAOV,oBAAoBL,oCAAoCM,KAAK,GAAG;YAC3E;QACJ;QACA,MAAMa,SAAS,IAAIC,WAAWV,KAAgBO,OAAO,IAAII;QAIzD,OAAOF,OAAO,GAAG,CAACZ;IACtB;AACJ;AAEO,MAAMe,8BAA8BC,2BAA2B,oBAAoB,CAAC;IACvF,gBAAgBtB;IAChB,cAAc;QAACuB;KAAiB;AACpC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/background-tasks-aws",
3
- "version": "6.6.0-alpha.0",
3
+ "version": "6.6.0-alpha.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -14,21 +14,21 @@
14
14
  },
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
- "@webiny/api-core": "6.6.0-alpha.0",
18
- "@webiny/api-graphql": "6.6.0-alpha.0",
19
- "@webiny/aws-sdk": "6.6.0-alpha.0",
20
- "@webiny/background-tasks": "6.6.0-alpha.0",
21
- "@webiny/event-handler-aws": "6.6.0-alpha.0",
22
- "@webiny/event-handler-core": "6.6.0-alpha.0",
23
- "@webiny/feature": "6.6.0-alpha.0",
24
- "@webiny/utils": "6.6.0-alpha.0"
17
+ "@webiny/api-core": "6.6.0-alpha.2",
18
+ "@webiny/api-graphql": "6.6.0-alpha.2",
19
+ "@webiny/aws-sdk": "6.6.0-alpha.2",
20
+ "@webiny/background-tasks": "6.6.0-alpha.2",
21
+ "@webiny/event-handler-aws": "6.6.0-alpha.2",
22
+ "@webiny/event-handler-core": "6.6.0-alpha.2",
23
+ "@webiny/feature": "6.6.0-alpha.2",
24
+ "@webiny/utils": "6.6.0-alpha.2"
25
25
  },
26
26
  "devDependencies": {
27
- "@webiny/build-tools": "6.6.0-alpha.0",
28
- "@webiny/di": "1.0.2",
27
+ "@webiny/build-tools": "6.6.0-alpha.2",
28
+ "@webiny/di": "1.1.0",
29
29
  "rimraf": "6.1.3",
30
30
  "typescript": "7.0.2",
31
- "vitest": "4.1.10"
31
+ "vitest": "4.1.11"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"