@nest-batch/core 0.2.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/LICENSE +21 -0
- package/README.md +368 -0
- package/dist/src/adapters/in-process.adapter.d.ts +140 -0
- package/dist/src/adapters/in-process.adapter.d.ts.map +1 -0
- package/dist/src/adapters/in-process.adapter.js +86 -0
- package/dist/src/adapters/in-process.adapter.js.map +1 -0
- package/dist/src/adapters/index.d.ts +18 -0
- package/dist/src/adapters/index.d.ts.map +1 -0
- package/dist/src/adapters/index.js +35 -0
- package/dist/src/adapters/index.js.map +1 -0
- package/dist/src/builder/batch-builder.d.ts +26 -0
- package/dist/src/builder/batch-builder.d.ts.map +1 -0
- package/dist/src/builder/batch-builder.js +25 -0
- package/dist/src/builder/batch-builder.js.map +1 -0
- package/dist/src/builder/flow-builder.d.ts +59 -0
- package/dist/src/builder/flow-builder.d.ts.map +1 -0
- package/dist/src/builder/flow-builder.js +115 -0
- package/dist/src/builder/flow-builder.js.map +1 -0
- package/dist/src/builder/index.d.ts +5 -0
- package/dist/src/builder/index.d.ts.map +1 -0
- package/dist/src/builder/index.js +23 -0
- package/dist/src/builder/index.js.map +1 -0
- package/dist/src/builder/job-builder.d.ts +76 -0
- package/dist/src/builder/job-builder.d.ts.map +1 -0
- package/dist/src/builder/job-builder.js +166 -0
- package/dist/src/builder/job-builder.js.map +1 -0
- package/dist/src/builder/step-builder.d.ts +74 -0
- package/dist/src/builder/step-builder.d.ts.map +1 -0
- package/dist/src/builder/step-builder.js +144 -0
- package/dist/src/builder/step-builder.js.map +1 -0
- package/dist/src/compiler/builder-types.d.ts +20 -0
- package/dist/src/compiler/builder-types.d.ts.map +1 -0
- package/dist/src/compiler/builder-types.js +6 -0
- package/dist/src/compiler/builder-types.js.map +1 -0
- package/dist/src/compiler/definition-compiler.d.ts +99 -0
- package/dist/src/compiler/definition-compiler.d.ts.map +1 -0
- package/dist/src/compiler/definition-compiler.js +257 -0
- package/dist/src/compiler/definition-compiler.js.map +1 -0
- package/dist/src/compiler/index.d.ts +3 -0
- package/dist/src/compiler/index.d.ts.map +1 -0
- package/dist/src/compiler/index.js +21 -0
- package/dist/src/compiler/index.js.map +1 -0
- package/dist/src/core/errors.d.ts +77 -0
- package/dist/src/core/errors.d.ts.map +1 -0
- package/dist/src/core/errors.js +170 -0
- package/dist/src/core/errors.js.map +1 -0
- package/dist/src/core/execution-context/index.d.ts +4 -0
- package/dist/src/core/execution-context/index.d.ts.map +1 -0
- package/dist/src/core/execution-context/index.js +22 -0
- package/dist/src/core/execution-context/index.js.map +1 -0
- package/dist/src/core/execution-context/json-value.d.ts +5 -0
- package/dist/src/core/execution-context/json-value.d.ts.map +1 -0
- package/dist/src/core/execution-context/json-value.js +6 -0
- package/dist/src/core/execution-context/json-value.js.map +1 -0
- package/dist/src/core/execution-context/serializer.d.ts +4 -0
- package/dist/src/core/execution-context/serializer.d.ts.map +1 -0
- package/dist/src/core/execution-context/serializer.js +34 -0
- package/dist/src/core/execution-context/serializer.js.map +1 -0
- package/dist/src/core/execution-context/validator.d.ts +18 -0
- package/dist/src/core/execution-context/validator.d.ts.map +1 -0
- package/dist/src/core/execution-context/validator.js +90 -0
- package/dist/src/core/execution-context/validator.js.map +1 -0
- package/dist/src/core/index.d.ts +8 -0
- package/dist/src/core/index.d.ts.map +1 -0
- package/dist/src/core/index.js +26 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/ir/decider-definition.d.ts +20 -0
- package/dist/src/core/ir/decider-definition.d.ts.map +1 -0
- package/dist/src/core/ir/decider-definition.js +6 -0
- package/dist/src/core/ir/decider-definition.js.map +1 -0
- package/dist/src/core/ir/index.d.ts +8 -0
- package/dist/src/core/ir/index.d.ts.map +1 -0
- package/dist/src/core/ir/index.js +26 -0
- package/dist/src/core/ir/index.js.map +1 -0
- package/dist/src/core/ir/job-definition.d.ts +15 -0
- package/dist/src/core/ir/job-definition.d.ts.map +1 -0
- package/dist/src/core/ir/job-definition.js +6 -0
- package/dist/src/core/ir/job-definition.js.map +1 -0
- package/dist/src/core/ir/listener-definition.d.ts +10 -0
- package/dist/src/core/ir/listener-definition.d.ts.map +1 -0
- package/dist/src/core/ir/listener-definition.js +6 -0
- package/dist/src/core/ir/listener-definition.js.map +1 -0
- package/dist/src/core/ir/policy-config.d.ts +24 -0
- package/dist/src/core/ir/policy-config.d.ts.map +1 -0
- package/dist/src/core/ir/policy-config.js +6 -0
- package/dist/src/core/ir/policy-config.js.map +1 -0
- package/dist/src/core/ir/refs.d.ts +42 -0
- package/dist/src/core/ir/refs.d.ts.map +1 -0
- package/dist/src/core/ir/refs.js +18 -0
- package/dist/src/core/ir/refs.js.map +1 -0
- package/dist/src/core/ir/step-definition.d.ts +59 -0
- package/dist/src/core/ir/step-definition.d.ts.map +1 -0
- package/dist/src/core/ir/step-definition.js +6 -0
- package/dist/src/core/ir/step-definition.js.map +1 -0
- package/dist/src/core/ir/transition-definition.d.ts +8 -0
- package/dist/src/core/ir/transition-definition.d.ts.map +1 -0
- package/dist/src/core/ir/transition-definition.js +6 -0
- package/dist/src/core/ir/transition-definition.js.map +1 -0
- package/dist/src/core/item/index.d.ts +2 -0
- package/dist/src/core/item/index.d.ts.map +1 -0
- package/dist/src/core/item/index.js +20 -0
- package/dist/src/core/item/index.js.map +1 -0
- package/dist/src/core/item/interfaces.d.ts +64 -0
- package/dist/src/core/item/interfaces.d.ts.map +1 -0
- package/dist/src/core/item/interfaces.js +6 -0
- package/dist/src/core/item/interfaces.js.map +1 -0
- package/dist/src/core/repository/index.d.ts +3 -0
- package/dist/src/core/repository/index.d.ts.map +1 -0
- package/dist/src/core/repository/index.js +21 -0
- package/dist/src/core/repository/index.js.map +1 -0
- package/dist/src/core/repository/job-repository.d.ts +60 -0
- package/dist/src/core/repository/job-repository.d.ts.map +1 -0
- package/dist/src/core/repository/job-repository.js +27 -0
- package/dist/src/core/repository/job-repository.js.map +1 -0
- package/dist/src/core/repository/types.d.ts +84 -0
- package/dist/src/core/repository/types.d.ts.map +1 -0
- package/dist/src/core/repository/types.js +6 -0
- package/dist/src/core/repository/types.js.map +1 -0
- package/dist/src/core/status.d.ts +29 -0
- package/dist/src/core/status.d.ts.map +1 -0
- package/dist/src/core/status.js +58 -0
- package/dist/src/core/status.js.map +1 -0
- package/dist/src/core/transaction/index.d.ts +2 -0
- package/dist/src/core/transaction/index.d.ts.map +1 -0
- package/dist/src/core/transaction/index.js +20 -0
- package/dist/src/core/transaction/index.js.map +1 -0
- package/dist/src/core/transaction/transaction-manager.d.ts +8 -0
- package/dist/src/core/transaction/transaction-manager.d.ts.map +1 -0
- package/dist/src/core/transaction/transaction-manager.js +14 -0
- package/dist/src/core/transaction/transaction-manager.js.map +1 -0
- package/dist/src/core/validation/definition-validator.d.ts +46 -0
- package/dist/src/core/validation/definition-validator.d.ts.map +1 -0
- package/dist/src/core/validation/definition-validator.js +177 -0
- package/dist/src/core/validation/definition-validator.js.map +1 -0
- package/dist/src/core/validation/index.d.ts +2 -0
- package/dist/src/core/validation/index.d.ts.map +1 -0
- package/dist/src/core/validation/index.js +20 -0
- package/dist/src/core/validation/index.js.map +1 -0
- package/dist/src/decorators/constants.d.ts +10 -0
- package/dist/src/decorators/constants.d.ts.map +1 -0
- package/dist/src/decorators/constants.js +50 -0
- package/dist/src/decorators/constants.js.map +1 -0
- package/dist/src/decorators/flow.decorator.d.ts +25 -0
- package/dist/src/decorators/flow.decorator.d.ts.map +1 -0
- package/dist/src/decorators/flow.decorator.js +19 -0
- package/dist/src/decorators/flow.decorator.js.map +1 -0
- package/dist/src/decorators/index.d.ts +8 -0
- package/dist/src/decorators/index.d.ts.map +1 -0
- package/dist/src/decorators/index.js +26 -0
- package/dist/src/decorators/index.js.map +1 -0
- package/dist/src/decorators/item.decorators.d.ts +32 -0
- package/dist/src/decorators/item.decorators.d.ts.map +1 -0
- package/dist/src/decorators/item.decorators.js +40 -0
- package/dist/src/decorators/item.decorators.js.map +1 -0
- package/dist/src/decorators/job.decorator.d.ts +11 -0
- package/dist/src/decorators/job.decorator.d.ts.map +1 -0
- package/dist/src/decorators/job.decorator.js +17 -0
- package/dist/src/decorators/job.decorator.js.map +1 -0
- package/dist/src/decorators/listener.decorators.d.ts +56 -0
- package/dist/src/decorators/listener.decorators.d.ts.map +1 -0
- package/dist/src/decorators/listener.decorators.js +157 -0
- package/dist/src/decorators/listener.decorators.js.map +1 -0
- package/dist/src/decorators/step.decorator.d.ts +25 -0
- package/dist/src/decorators/step.decorator.d.ts.map +1 -0
- package/dist/src/decorators/step.decorator.js +21 -0
- package/dist/src/decorators/step.decorator.js.map +1 -0
- package/dist/src/decorators/tasklet.decorator.d.ts +7 -0
- package/dist/src/decorators/tasklet.decorator.d.ts.map +1 -0
- package/dist/src/decorators/tasklet.decorator.js +21 -0
- package/dist/src/decorators/tasklet.decorator.js.map +1 -0
- package/dist/src/execution/batch-worker-runner.d.ts +27 -0
- package/dist/src/execution/batch-worker-runner.d.ts.map +1 -0
- package/dist/src/execution/batch-worker-runner.js +147 -0
- package/dist/src/execution/batch-worker-runner.js.map +1 -0
- package/dist/src/execution/chunk-step-executor.d.ts +86 -0
- package/dist/src/execution/chunk-step-executor.d.ts.map +1 -0
- package/dist/src/execution/chunk-step-executor.js +482 -0
- package/dist/src/execution/chunk-step-executor.js.map +1 -0
- package/dist/src/execution/execution-strategy.d.ts +110 -0
- package/dist/src/execution/execution-strategy.d.ts.map +1 -0
- package/dist/src/execution/execution-strategy.js +13 -0
- package/dist/src/execution/execution-strategy.js.map +1 -0
- package/dist/src/execution/external-task-execution-strategy.d.ts +36 -0
- package/dist/src/execution/external-task-execution-strategy.d.ts.map +1 -0
- package/dist/src/execution/external-task-execution-strategy.js +97 -0
- package/dist/src/execution/external-task-execution-strategy.js.map +1 -0
- package/dist/src/execution/in-process-execution-strategy.d.ts +129 -0
- package/dist/src/execution/in-process-execution-strategy.d.ts.map +1 -0
- package/dist/src/execution/in-process-execution-strategy.js +141 -0
- package/dist/src/execution/in-process-execution-strategy.js.map +1 -0
- package/dist/src/execution/index.d.ts +14 -0
- package/dist/src/execution/index.d.ts.map +1 -0
- package/dist/src/execution/index.js +32 -0
- package/dist/src/execution/index.js.map +1 -0
- package/dist/src/execution/job-executor.d.ts +145 -0
- package/dist/src/execution/job-executor.d.ts.map +1 -0
- package/dist/src/execution/job-executor.js +475 -0
- package/dist/src/execution/job-executor.js.map +1 -0
- package/dist/src/execution/job-explorer.d.ts +15 -0
- package/dist/src/execution/job-explorer.d.ts.map +1 -0
- package/dist/src/execution/job-explorer.js +84 -0
- package/dist/src/execution/job-explorer.js.map +1 -0
- package/dist/src/execution/job-key.d.ts +3 -0
- package/dist/src/execution/job-key.d.ts.map +1 -0
- package/dist/src/execution/job-key.js +43 -0
- package/dist/src/execution/job-key.js.map +1 -0
- package/dist/src/execution/job-launcher.d.ts +75 -0
- package/dist/src/execution/job-launcher.d.ts.map +1 -0
- package/dist/src/execution/job-launcher.js +112 -0
- package/dist/src/execution/job-launcher.js.map +1 -0
- package/dist/src/execution/job-operator.d.ts +22 -0
- package/dist/src/execution/job-operator.d.ts.map +1 -0
- package/dist/src/execution/job-operator.js +125 -0
- package/dist/src/execution/job-operator.js.map +1 -0
- package/dist/src/execution/listener-invoker.d.ts +164 -0
- package/dist/src/execution/listener-invoker.d.ts.map +1 -0
- package/dist/src/execution/listener-invoker.js +246 -0
- package/dist/src/execution/listener-invoker.js.map +1 -0
- package/dist/src/execution/ref-resolver.d.ts +40 -0
- package/dist/src/execution/ref-resolver.d.ts.map +1 -0
- package/dist/src/execution/ref-resolver.js +41 -0
- package/dist/src/execution/ref-resolver.js.map +1 -0
- package/dist/src/execution/tasklet-step-executor.d.ts +79 -0
- package/dist/src/execution/tasklet-step-executor.d.ts.map +1 -0
- package/dist/src/execution/tasklet-step-executor.js +138 -0
- package/dist/src/execution/tasklet-step-executor.js.map +1 -0
- package/dist/src/explorer/batch-explorer.d.ts +138 -0
- package/dist/src/explorer/batch-explorer.d.ts.map +1 -0
- package/dist/src/explorer/batch-explorer.js +167 -0
- package/dist/src/explorer/batch-explorer.js.map +1 -0
- package/dist/src/explorer/index.d.ts +2 -0
- package/dist/src/explorer/index.d.ts.map +1 -0
- package/dist/src/explorer/index.js +20 -0
- package/dist/src/explorer/index.js.map +1 -0
- package/dist/src/flow/flow-evaluator.d.ts +30 -0
- package/dist/src/flow/flow-evaluator.d.ts.map +1 -0
- package/dist/src/flow/flow-evaluator.js +80 -0
- package/dist/src/flow/flow-evaluator.js.map +1 -0
- package/dist/src/flow/index.d.ts +2 -0
- package/dist/src/flow/index.d.ts.map +1 -0
- package/dist/src/flow/index.js +20 -0
- package/dist/src/flow/index.js.map +1 -0
- package/dist/src/index.d.ts +18 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +90 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/io/checkpoint.d.ts +7 -0
- package/dist/src/io/checkpoint.d.ts.map +1 -0
- package/dist/src/io/checkpoint.js +56 -0
- package/dist/src/io/checkpoint.js.map +1 -0
- package/dist/src/io/database.d.ts +50 -0
- package/dist/src/io/database.d.ts.map +1 -0
- package/dist/src/io/database.js +108 -0
- package/dist/src/io/database.js.map +1 -0
- package/dist/src/io/file-readers.d.ts +54 -0
- package/dist/src/io/file-readers.d.ts.map +1 -0
- package/dist/src/io/file-readers.js +167 -0
- package/dist/src/io/file-readers.js.map +1 -0
- package/dist/src/io/file-writers.d.ts +31 -0
- package/dist/src/io/file-writers.d.ts.map +1 -0
- package/dist/src/io/file-writers.js +80 -0
- package/dist/src/io/file-writers.js.map +1 -0
- package/dist/src/io/index.d.ts +6 -0
- package/dist/src/io/index.d.ts.map +1 -0
- package/dist/src/io/index.js +24 -0
- package/dist/src/io/index.js.map +1 -0
- package/dist/src/io/s3.d.ts +50 -0
- package/dist/src/io/s3.d.ts.map +1 -0
- package/dist/src/io/s3.js +96 -0
- package/dist/src/io/s3.js.map +1 -0
- package/dist/src/listeners/builtin-listeners.d.ts +77 -0
- package/dist/src/listeners/builtin-listeners.d.ts.map +1 -0
- package/dist/src/listeners/builtin-listeners.js +108 -0
- package/dist/src/listeners/builtin-listeners.js.map +1 -0
- package/dist/src/listeners/index.d.ts +8 -0
- package/dist/src/listeners/index.d.ts.map +1 -0
- package/dist/src/listeners/index.js +25 -0
- package/dist/src/listeners/index.js.map +1 -0
- package/dist/src/module/adapter-options.d.ts +39 -0
- package/dist/src/module/adapter-options.d.ts.map +1 -0
- package/dist/src/module/adapter-options.js +34 -0
- package/dist/src/module/adapter-options.js.map +1 -0
- package/dist/src/module/adapter.d.ts +157 -0
- package/dist/src/module/adapter.d.ts.map +1 -0
- package/dist/src/module/adapter.js +80 -0
- package/dist/src/module/adapter.js.map +1 -0
- package/dist/src/module/batch-schedule-registry.d.ts +110 -0
- package/dist/src/module/batch-schedule-registry.d.ts.map +1 -0
- package/dist/src/module/batch-schedule-registry.js +0 -0
- package/dist/src/module/batch-schedule-registry.js.map +1 -0
- package/dist/src/module/index.d.ts +14 -0
- package/dist/src/module/index.d.ts.map +1 -0
- package/dist/src/module/index.js +31 -0
- package/dist/src/module/index.js.map +1 -0
- package/dist/src/module/nest-batch.module.d.ts +236 -0
- package/dist/src/module/nest-batch.module.d.ts.map +1 -0
- package/dist/src/module/nest-batch.module.js +475 -0
- package/dist/src/module/nest-batch.module.js.map +1 -0
- package/dist/src/module/tokens.d.ts +83 -0
- package/dist/src/module/tokens.d.ts.map +1 -0
- package/dist/src/module/tokens.js +58 -0
- package/dist/src/module/tokens.js.map +1 -0
- package/dist/src/observability/event-types.d.ts +55 -0
- package/dist/src/observability/event-types.d.ts.map +1 -0
- package/dist/src/observability/event-types.js +36 -0
- package/dist/src/observability/event-types.js.map +1 -0
- package/dist/src/observability/exporters.d.ts +35 -0
- package/dist/src/observability/exporters.d.ts.map +1 -0
- package/dist/src/observability/exporters.js +93 -0
- package/dist/src/observability/exporters.js.map +1 -0
- package/dist/src/observability/index.d.ts +3 -0
- package/dist/src/observability/index.d.ts.map +1 -0
- package/dist/src/observability/index.js +21 -0
- package/dist/src/observability/index.js.map +1 -0
- package/dist/src/partition-helpers.d.ts +127 -0
- package/dist/src/partition-helpers.d.ts.map +1 -0
- package/dist/src/partition-helpers.js +136 -0
- package/dist/src/partition-helpers.js.map +1 -0
- package/dist/src/policies/backoff.d.ts +3 -0
- package/dist/src/policies/backoff.d.ts.map +1 -0
- package/dist/src/policies/backoff.js +34 -0
- package/dist/src/policies/backoff.js.map +1 -0
- package/dist/src/policies/index.d.ts +4 -0
- package/dist/src/policies/index.d.ts.map +1 -0
- package/dist/src/policies/index.js +22 -0
- package/dist/src/policies/index.js.map +1 -0
- package/dist/src/policies/retry-policy.d.ts +13 -0
- package/dist/src/policies/retry-policy.d.ts.map +1 -0
- package/dist/src/policies/retry-policy.js +55 -0
- package/dist/src/policies/retry-policy.js.map +1 -0
- package/dist/src/policies/skip-policy.d.ts +12 -0
- package/dist/src/policies/skip-policy.d.ts.map +1 -0
- package/dist/src/policies/skip-policy.js +44 -0
- package/dist/src/policies/skip-policy.js.map +1 -0
- package/dist/src/registry/index.d.ts +2 -0
- package/dist/src/registry/index.d.ts.map +1 -0
- package/dist/src/registry/index.js +20 -0
- package/dist/src/registry/index.js.map +1 -0
- package/dist/src/registry/job-registry.d.ts +16 -0
- package/dist/src/registry/job-registry.d.ts.map +1 -0
- package/dist/src/registry/job-registry.js +50 -0
- package/dist/src/registry/job-registry.js.map +1 -0
- package/dist/src/repository/id-generator.d.ts +18 -0
- package/dist/src/repository/id-generator.d.ts.map +1 -0
- package/dist/src/repository/id-generator.js +37 -0
- package/dist/src/repository/id-generator.js.map +1 -0
- package/dist/src/repository/in-memory/in-memory-job-repository.d.ts +49 -0
- package/dist/src/repository/in-memory/in-memory-job-repository.d.ts.map +1 -0
- package/dist/src/repository/in-memory/in-memory-job-repository.js +291 -0
- package/dist/src/repository/in-memory/in-memory-job-repository.js.map +1 -0
- package/dist/src/repository/in-memory/index.d.ts +2 -0
- package/dist/src/repository/in-memory/index.d.ts.map +1 -0
- package/dist/src/repository/in-memory/index.js +20 -0
- package/dist/src/repository/in-memory/index.js.map +1 -0
- package/dist/src/repository/index.d.ts +4 -0
- package/dist/src/repository/index.d.ts.map +1 -0
- package/dist/src/repository/index.js +22 -0
- package/dist/src/repository/index.js.map +1 -0
- package/dist/src/repository/uuid-v7.d.ts +20 -0
- package/dist/src/repository/uuid-v7.d.ts.map +1 -0
- package/dist/src/repository/uuid-v7.js +31 -0
- package/dist/src/repository/uuid-v7.js.map +1 -0
- package/dist/src/scheduling/batch-scheduled.d.ts +87 -0
- package/dist/src/scheduling/batch-scheduled.d.ts.map +1 -0
- package/dist/src/scheduling/batch-scheduled.js +170 -0
- package/dist/src/scheduling/batch-scheduled.js.map +1 -0
- package/dist/src/transaction/in-memory-transaction-manager.d.ts +16 -0
- package/dist/src/transaction/in-memory-transaction-manager.d.ts.map +1 -0
- package/dist/src/transaction/in-memory-transaction-manager.js +33 -0
- package/dist/src/transaction/in-memory-transaction-manager.js.map +1 -0
- package/dist/src/transaction/index.d.ts +2 -0
- package/dist/src/transaction/index.d.ts.map +1 -0
- package/dist/src/transaction/index.js +20 -0
- package/dist/src/transaction/index.js.map +1 -0
- package/dist/tests/contracts/index.d.ts +26 -0
- package/dist/tests/contracts/index.d.ts.map +1 -0
- package/dist/tests/contracts/index.js +37 -0
- package/dist/tests/contracts/index.js.map +1 -0
- package/dist/tests/contracts/job-repository.contract.d.ts +46 -0
- package/dist/tests/contracts/job-repository.contract.d.ts.map +1 -0
- package/dist/tests/contracts/job-repository.contract.js +644 -0
- package/dist/tests/contracts/job-repository.contract.js.map +1 -0
- package/package.json +80 -0
- package/src/adapters/in-process.adapter.ts +182 -0
- package/src/adapters/index.ts +17 -0
- package/src/builder/batch-builder.ts +32 -0
- package/src/builder/flow-builder.ts +141 -0
- package/src/builder/index.ts +4 -0
- package/src/builder/job-builder.ts +206 -0
- package/src/builder/step-builder.ts +190 -0
- package/src/compiler/builder-types.ts +27 -0
- package/src/compiler/definition-compiler.ts +325 -0
- package/src/compiler/index.ts +2 -0
- package/src/core/errors.ts +125 -0
- package/src/core/execution-context/index.ts +3 -0
- package/src/core/execution-context/json-value.ts +3 -0
- package/src/core/execution-context/serializer.ts +21 -0
- package/src/core/execution-context/validator.ts +103 -0
- package/src/core/index.ts +7 -0
- package/src/core/ir/decider-definition.ts +25 -0
- package/src/core/ir/index.ts +7 -0
- package/src/core/ir/job-definition.ts +15 -0
- package/src/core/ir/listener-definition.ts +19 -0
- package/src/core/ir/policy-config.ts +19 -0
- package/src/core/ir/refs.ts +42 -0
- package/src/core/ir/step-definition.ts +62 -0
- package/src/core/ir/transition-definition.ts +9 -0
- package/src/core/item/index.ts +1 -0
- package/src/core/item/interfaces.ts +70 -0
- package/src/core/repository/index.ts +2 -0
- package/src/core/repository/job-repository.ts +100 -0
- package/src/core/repository/types.ts +91 -0
- package/src/core/status.ts +31 -0
- package/src/core/transaction/index.ts +1 -0
- package/src/core/transaction/transaction-manager.ts +8 -0
- package/src/core/validation/definition-validator.ts +215 -0
- package/src/core/validation/index.ts +1 -0
- package/src/decorators/constants.ts +9 -0
- package/src/decorators/flow.decorator.ts +31 -0
- package/src/decorators/index.ts +7 -0
- package/src/decorators/item.decorators.ts +51 -0
- package/src/decorators/job.decorator.ts +16 -0
- package/src/decorators/listener.decorators.ts +142 -0
- package/src/decorators/step.decorator.ts +33 -0
- package/src/decorators/tasklet.decorator.ts +14 -0
- package/src/execution/batch-worker-runner.ts +142 -0
- package/src/execution/chunk-step-executor.ts +594 -0
- package/src/execution/execution-strategy.ts +115 -0
- package/src/execution/external-task-execution-strategy.ts +104 -0
- package/src/execution/in-process-execution-strategy.ts +207 -0
- package/src/execution/index.ts +13 -0
- package/src/execution/job-executor.ts +553 -0
- package/src/execution/job-explorer.ts +73 -0
- package/src/execution/job-key.ts +35 -0
- package/src/execution/job-launcher.ts +132 -0
- package/src/execution/job-operator.ts +127 -0
- package/src/execution/listener-invoker.ts +389 -0
- package/src/execution/ref-resolver.ts +64 -0
- package/src/execution/tasklet-step-executor.ts +182 -0
- package/src/explorer/batch-explorer.ts +251 -0
- package/src/explorer/index.ts +1 -0
- package/src/flow/flow-evaluator.ts +89 -0
- package/src/flow/index.ts +1 -0
- package/src/index.ts +24 -0
- package/src/io/checkpoint.ts +47 -0
- package/src/io/database.ts +114 -0
- package/src/io/file-readers.ts +191 -0
- package/src/io/file-writers.ts +99 -0
- package/src/io/index.ts +5 -0
- package/src/io/s3.ts +117 -0
- package/src/listeners/builtin-listeners.ts +151 -0
- package/src/listeners/index.ts +7 -0
- package/src/module/adapter-options.ts +38 -0
- package/src/module/adapter.ts +160 -0
- package/src/module/batch-schedule-registry.ts +0 -0
- package/src/module/index.ts +13 -0
- package/src/module/nest-batch.module.ts +674 -0
- package/src/module/tokens.ts +95 -0
- package/src/observability/event-types.ts +61 -0
- package/src/observability/exporters.ts +96 -0
- package/src/observability/index.ts +2 -0
- package/src/partition-helpers.ts +204 -0
- package/src/policies/backoff.ts +22 -0
- package/src/policies/index.ts +3 -0
- package/src/policies/retry-policy.ts +57 -0
- package/src/policies/skip-policy.ts +51 -0
- package/src/registry/index.ts +1 -0
- package/src/registry/job-registry.ts +42 -0
- package/src/repository/id-generator.ts +25 -0
- package/src/repository/in-memory/in-memory-job-repository.ts +334 -0
- package/src/repository/in-memory/index.ts +1 -0
- package/src/repository/index.ts +3 -0
- package/src/repository/uuid-v7.ts +40 -0
- package/src/scheduling/batch-scheduled.ts +257 -0
- package/src/transaction/in-memory-transaction-manager.ts +23 -0
- package/src/transaction/index.ts +1 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { JobDefinition } from '../core/ir';
|
|
2
|
+
import type { JobParameters } from '../core/repository';
|
|
3
|
+
import type { JobStatus } from '../core/status';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* NestJS DI token for the polymorphic execution strategy.
|
|
7
|
+
*
|
|
8
|
+
* `JobLauncher` is a thin facade that delegates the actual execution
|
|
9
|
+
* to whatever `IExecutionStrategy` is bound to this token. The default
|
|
10
|
+
* in-process strategy wraps the current `JobExecutor` flow; sibling
|
|
11
|
+
* packages (e.g. `@nest-batch/bullmq`) override this provider with a
|
|
12
|
+
* transport strategy that enqueues step / partition work.
|
|
13
|
+
*
|
|
14
|
+
* Injecting by token (not by class) lets the host application swap
|
|
15
|
+
* the strategy at module composition time without subclassing
|
|
16
|
+
* `JobLauncher`.
|
|
17
|
+
*
|
|
18
|
+
* Defined as a `symbol` to avoid accidental string collisions with
|
|
19
|
+
* other DI tokens in the host application. The symbol is registered
|
|
20
|
+
* in the global symbol registry under a stable, package-scoped key
|
|
21
|
+
* (`@nest-batch/core/EXECUTION_STRATEGY`) so it is unique across the
|
|
22
|
+
* process.
|
|
23
|
+
*/
|
|
24
|
+
export const EXECUTION_STRATEGY: symbol = Symbol.for(
|
|
25
|
+
'@nest-batch/core/EXECUTION_STRATEGY',
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Context handed to the strategy alongside the job definition and
|
|
30
|
+
* parameters. The launcher pre-resolves the canonical `jobKey` and
|
|
31
|
+
* the atomic instance + execution lock; the resulting identifiers
|
|
32
|
+
* are passed in `ctx` so the strategy can correlate them (e.g. a
|
|
33
|
+
* BullMQ job's `jobId` may be set to `executionId`).
|
|
34
|
+
*
|
|
35
|
+
* Field semantics:
|
|
36
|
+
* - `executionId` — fresh execution id assigned by
|
|
37
|
+
* `JobRepository.createExecutionAtomic`. The strategy uses this
|
|
38
|
+
* to load the latest persisted `JobExecution` from the
|
|
39
|
+
* repository (in the in-process case) or to stamp a queue job.
|
|
40
|
+
* - `jobExecutionId` — same value as `executionId` today (kept as
|
|
41
|
+
* a distinct field so future transport strategies that need to
|
|
42
|
+
* split "execution" from "job execution" — e.g. multi-step
|
|
43
|
+
* partition fan-out — have a stable slot to fill). Both fields
|
|
44
|
+
* are present so the contract is forward-compatible.
|
|
45
|
+
*/
|
|
46
|
+
export interface ExecutionStrategyContext {
|
|
47
|
+
/**
|
|
48
|
+
* Fresh execution id assigned by the repository's atomic create.
|
|
49
|
+
*
|
|
50
|
+
* The strategy uses this to load the latest persisted
|
|
51
|
+
* `JobExecution` from the repository (in the in-process case) or
|
|
52
|
+
* to stamp a queue job (in transport strategies).
|
|
53
|
+
*/
|
|
54
|
+
readonly executionId: string;
|
|
55
|
+
/**
|
|
56
|
+
* Job execution id. Today this mirrors `executionId`; the field
|
|
57
|
+
* is kept distinct so transport strategies can stamp the
|
|
58
|
+
* `JobExecution.id` on a queue payload without losing the
|
|
59
|
+
* underlying `executionId` correlation key, and so the contract
|
|
60
|
+
* matches the public terminology used by callers.
|
|
61
|
+
*/
|
|
62
|
+
readonly jobExecutionId: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Discriminated result returned by `IExecutionStrategy.launch`.
|
|
67
|
+
*
|
|
68
|
+
* - `kind: 'completed'` — the strategy ran the job to a terminal
|
|
69
|
+
* state in-process (or synchronously simulated it). The launcher
|
|
70
|
+
* resolves the persisted `JobExecution` (whose `status` matches
|
|
71
|
+
* the `status` field) and returns it to the caller. Public API
|
|
72
|
+
* shape is unchanged: `Promise<JobExecution>`.
|
|
73
|
+
*
|
|
74
|
+
* - `kind: 'enqueued'` — the strategy handed the job off to a
|
|
75
|
+
* transport (e.g. a BullMQ queue). The launcher still resolves
|
|
76
|
+
* the latest persisted `JobExecution` (which remains in
|
|
77
|
+
* `STARTING` / `STARTED` because the executor did not run) and
|
|
78
|
+
* returns it. The `queueJobId` is for the strategy's own
|
|
79
|
+
* bookkeeping; the public `JobLauncher.launch` API does not
|
|
80
|
+
* surface it (signature must remain stable per the plan).
|
|
81
|
+
*/
|
|
82
|
+
export type LaunchResult =
|
|
83
|
+
| { readonly kind: 'completed'; readonly status: JobStatus }
|
|
84
|
+
| { readonly kind: 'enqueued'; readonly queueJobId: string };
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Polymorphic execution contract for `JobLauncher`.
|
|
88
|
+
*
|
|
89
|
+
* Implementations decide *how* a job runs:
|
|
90
|
+
* - in-process (default, wraps `JobExecutor`),
|
|
91
|
+
* - transport-based (BullMQ, Sidekiq, custom queue, ...).
|
|
92
|
+
*
|
|
93
|
+
* The launcher owns everything *outside* the strategy boundary:
|
|
94
|
+
* - registry lookup + canonical `jobKey` derivation,
|
|
95
|
+
* - atomic get-or-create instance + concurrency lock,
|
|
96
|
+
* - translating the strategy's `LaunchResult` back to the public
|
|
97
|
+
* `JobExecution` shape.
|
|
98
|
+
*
|
|
99
|
+
* The strategy owns everything *inside* the boundary:
|
|
100
|
+
* - invoking the steps in-process,
|
|
101
|
+
* - or handing the work to a transport and returning an enqueue
|
|
102
|
+
* result.
|
|
103
|
+
*
|
|
104
|
+
* `name` is purely for diagnostics — log lines and boundary
|
|
105
|
+
* reports. Two strategies with identical behavior but different
|
|
106
|
+
* `name` values are treated as distinct by the host.
|
|
107
|
+
*/
|
|
108
|
+
export interface IExecutionStrategy {
|
|
109
|
+
readonly name: string;
|
|
110
|
+
launch(
|
|
111
|
+
job: JobDefinition,
|
|
112
|
+
params: JobParameters,
|
|
113
|
+
ctx: ExecutionStrategyContext,
|
|
114
|
+
): Promise<LaunchResult>;
|
|
115
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Inject, Injectable, Optional } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
import type { JobDefinition } from '../core/ir';
|
|
4
|
+
import type { JobParameters } from '../core/repository';
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
ExecutionStrategyContext,
|
|
8
|
+
IExecutionStrategy,
|
|
9
|
+
LaunchResult,
|
|
10
|
+
} from './execution-strategy';
|
|
11
|
+
|
|
12
|
+
export const EXTERNAL_TASK_LAUNCHER: symbol = Symbol.for(
|
|
13
|
+
'@nest-batch/core/EXTERNAL_TASK_LAUNCHER',
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export const EXTERNAL_TASK_STRATEGY_OPTIONS: symbol = Symbol.for(
|
|
17
|
+
'@nest-batch/core/EXTERNAL_TASK_STRATEGY_OPTIONS',
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export interface ExternalTaskStrategyOptions {
|
|
21
|
+
readonly workerCommand?: readonly string[];
|
|
22
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
23
|
+
readonly labels?: Readonly<Record<string, string>>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ExternalTaskLaunchRequest {
|
|
27
|
+
readonly jobId: string;
|
|
28
|
+
readonly jobExecutionId: string;
|
|
29
|
+
readonly params: JobParameters;
|
|
30
|
+
readonly workerArgs: readonly string[];
|
|
31
|
+
readonly env: Readonly<Record<string, string>>;
|
|
32
|
+
readonly labels: Readonly<Record<string, string>>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ExternalTaskLaunchResult {
|
|
36
|
+
readonly provider: string;
|
|
37
|
+
readonly externalId: string;
|
|
38
|
+
readonly metadata?: Readonly<Record<string, string>>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ExternalTaskLauncher {
|
|
42
|
+
readonly name: string;
|
|
43
|
+
launch(request: ExternalTaskLaunchRequest): Promise<ExternalTaskLaunchResult>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Injectable()
|
|
47
|
+
export class ExternalTaskExecutionStrategy implements IExecutionStrategy {
|
|
48
|
+
readonly name: string;
|
|
49
|
+
|
|
50
|
+
constructor(
|
|
51
|
+
@Inject(EXTERNAL_TASK_LAUNCHER)
|
|
52
|
+
private readonly launcher: ExternalTaskLauncher,
|
|
53
|
+
@Optional()
|
|
54
|
+
@Inject(EXTERNAL_TASK_STRATEGY_OPTIONS)
|
|
55
|
+
private readonly options: ExternalTaskStrategyOptions = {},
|
|
56
|
+
) {
|
|
57
|
+
this.name = launcher.name;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async launch(
|
|
61
|
+
job: JobDefinition,
|
|
62
|
+
params: JobParameters,
|
|
63
|
+
ctx: ExecutionStrategyContext,
|
|
64
|
+
): Promise<LaunchResult> {
|
|
65
|
+
const workerArgs = this.buildWorkerArgs(job.id, ctx.jobExecutionId, params);
|
|
66
|
+
const result = await this.launcher.launch({
|
|
67
|
+
jobId: job.id,
|
|
68
|
+
jobExecutionId: ctx.jobExecutionId,
|
|
69
|
+
params,
|
|
70
|
+
workerArgs,
|
|
71
|
+
env: {
|
|
72
|
+
...(this.options.env ?? {}),
|
|
73
|
+
NEST_BATCH_JOB_ID: job.id,
|
|
74
|
+
NEST_BATCH_JOB_EXECUTION_ID: ctx.jobExecutionId,
|
|
75
|
+
},
|
|
76
|
+
labels: {
|
|
77
|
+
...(this.options.labels ?? {}),
|
|
78
|
+
'nest-batch/job-id': job.id,
|
|
79
|
+
'nest-batch/job-execution-id': ctx.jobExecutionId,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
kind: 'enqueued',
|
|
85
|
+
queueJobId: `${result.provider}:${result.externalId}`,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private buildWorkerArgs(
|
|
90
|
+
jobId: string,
|
|
91
|
+
jobExecutionId: string,
|
|
92
|
+
params: JobParameters,
|
|
93
|
+
): readonly string[] {
|
|
94
|
+
return [
|
|
95
|
+
...(this.options.workerCommand ?? ['batch-worker']),
|
|
96
|
+
'--job-id',
|
|
97
|
+
jobId,
|
|
98
|
+
'--job-execution-id',
|
|
99
|
+
jobExecutionId,
|
|
100
|
+
'--params-json',
|
|
101
|
+
JSON.stringify(params),
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { Inject, Injectable, Logger, Optional, forwardRef } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
import { JobRepository, type JobExecution, type JobParameters } from '../core/repository';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
EXECUTION_STRATEGY,
|
|
8
|
+
type ExecutionStrategyContext,
|
|
9
|
+
type IExecutionStrategy,
|
|
10
|
+
type LaunchResult,
|
|
11
|
+
} from './execution-strategy';
|
|
12
|
+
import { JobExecutor } from './job-executor';
|
|
13
|
+
|
|
14
|
+
import type { JobDefinition } from '../core/ir';
|
|
15
|
+
import { BatchError } from '../core/errors';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* How `InProcessExecutionStrategy` reacts when a chunk step is
|
|
19
|
+
* configured with `partitions.count > 1` — a state the in-process
|
|
20
|
+
* transport cannot honour (it is single-threaded by design).
|
|
21
|
+
*
|
|
22
|
+
* - `'throw'` (default): fail the launch with
|
|
23
|
+
* `InProcessPartitionsNotSupportedError`. The host sees a loud
|
|
24
|
+
* failure and is forced to either drop the partitions config
|
|
25
|
+
* or wire up a real transport.
|
|
26
|
+
* - `'warn'`: log a warning and continue with a single-partition
|
|
27
|
+
* execution. The host gets a clear signal in the logs but the
|
|
28
|
+
* step still runs. Useful for local dev / smoke tests where a
|
|
29
|
+
* full transport wiring is overkill.
|
|
30
|
+
*
|
|
31
|
+
* Pinned by `docs/RELEASE-0.2.0.md §6.3`.
|
|
32
|
+
*/
|
|
33
|
+
export type InProcessPartitionViolationMode = 'throw' | 'warn';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* DI token for the `InProcessPartitionViolationMode` option. The
|
|
37
|
+
* host wires it via `NestBatchModule.forRoot({ inProcess: {
|
|
38
|
+
* onPartitionViolation: 'warn' } })` (the module reads it from
|
|
39
|
+
* the options bag and binds the value under this token).
|
|
40
|
+
*
|
|
41
|
+
* The default is `'throw'`, so a host that does not opt in gets
|
|
42
|
+
* the loud failure behaviour. The token is exported so tests can
|
|
43
|
+
* wire a custom mode without going through the module.
|
|
44
|
+
*/
|
|
45
|
+
export const IN_PROCESS_PARTITION_VIOLATION_MODE =
|
|
46
|
+
Symbol.for('@nest-batch/core/IN_PROCESS_PARTITION_VIOLATION_MODE');
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Default in-process execution strategy.
|
|
50
|
+
*
|
|
51
|
+
* Wraps the current `JobExecutor.execute` flow behind the
|
|
52
|
+
* polymorphic `IExecutionStrategy` contract so the public
|
|
53
|
+
* `JobLauncher.launch()` API can stay stable while the actual
|
|
54
|
+
* execution target becomes swappable.
|
|
55
|
+
*
|
|
56
|
+
* Lifecycle:
|
|
57
|
+
* 1. The `JobLauncher` pre-creates a `JobExecution` (in `STARTING`)
|
|
58
|
+
* via the atomic repository helper and passes the resulting
|
|
59
|
+
* `executionId` in `ctx`.
|
|
60
|
+
* 2. This strategy re-fetches the same `JobExecution` (the in-process
|
|
61
|
+
* executor needs the full object, not just the id) and hands it to
|
|
62
|
+
* `JobExecutor.execute`, which drives the steps to a terminal
|
|
63
|
+
* status (`COMPLETED` / `FAILED`) and persists updates along the
|
|
64
|
+
* way.
|
|
65
|
+
* 3. The executor returns the final, persisted `JobExecution`; we
|
|
66
|
+
* translate it into the discriminated `LaunchResult` the contract
|
|
67
|
+
* requires: `{ kind: 'completed', status }`. The launcher then
|
|
68
|
+
* re-reads the latest persisted `JobExecution` and hands it to the
|
|
69
|
+
* caller, keeping the public `Promise<JobExecution>` shape intact.
|
|
70
|
+
*
|
|
71
|
+
* Why `forwardRef` on `JobExecutor`?
|
|
72
|
+
* `JobLauncher` already uses `forwardRef(() => JobExecutor)` to
|
|
73
|
+
* keep the dependency graph stable against future refactors. This
|
|
74
|
+
* strategy is a sibling consumer of the same `JobExecutor`; using
|
|
75
|
+
* the same `forwardRef` pattern keeps the cyclic-DI safety net
|
|
76
|
+
* uniform across the launcher and the default strategy.
|
|
77
|
+
*/
|
|
78
|
+
@Injectable()
|
|
79
|
+
export class InProcessExecutionStrategy implements IExecutionStrategy {
|
|
80
|
+
readonly name = 'in-process';
|
|
81
|
+
|
|
82
|
+
private readonly logger = new Logger(InProcessExecutionStrategy.name);
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The configured partition-violation mode. Tests construct the
|
|
86
|
+
* strategy with a non-default mode; production uses the default
|
|
87
|
+
* ('throw') wired by `IN_PROCESS_EXECUTION_STRATEGY_PROVIDER`.
|
|
88
|
+
*/
|
|
89
|
+
private readonly onPartitionViolation: InProcessPartitionViolationMode;
|
|
90
|
+
|
|
91
|
+
constructor(
|
|
92
|
+
private readonly repository: JobRepository,
|
|
93
|
+
@Inject(forwardRef(() => JobExecutor))
|
|
94
|
+
private readonly jobExecutor: JobExecutor,
|
|
95
|
+
/**
|
|
96
|
+
* Optional injection token for the partition-violation mode.
|
|
97
|
+
* Wired by the host via `NestBatchModule.forRoot({ inProcess: {
|
|
98
|
+
* onPartitionViolation: 'warn' } })`; defaults to `'throw'`
|
|
99
|
+
* when the host does not opt in. The `@Optional()` decorator
|
|
100
|
+
* keeps the constructor backward-compatible with hosts that
|
|
101
|
+
* have not opted in (the test suite for T1-T7 does not bind
|
|
102
|
+
* this token, and the runtime must still work for them).
|
|
103
|
+
*/
|
|
104
|
+
@Optional()
|
|
105
|
+
@Inject(IN_PROCESS_PARTITION_VIOLATION_MODE)
|
|
106
|
+
onPartitionViolation: InProcessPartitionViolationMode = 'throw',
|
|
107
|
+
) {
|
|
108
|
+
this.onPartitionViolation = onPartitionViolation;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async launch(
|
|
112
|
+
job: JobDefinition,
|
|
113
|
+
_params: JobParameters,
|
|
114
|
+
ctx: ExecutionStrategyContext,
|
|
115
|
+
): Promise<LaunchResult> {
|
|
116
|
+
// The in-process strategy is intentionally single-threaded; it
|
|
117
|
+
// cannot fan out across multiple processes or workers. Per
|
|
118
|
+
// `docs/RELEASE-0.2.0.md §6.3`, partition orchestration is the
|
|
119
|
+
// transport's job — when a host configures a chunk step with
|
|
120
|
+
// `partitions.count > 1` against the in-process strategy, we
|
|
121
|
+
// surface the misconfiguration rather than silently single-
|
|
122
|
+
// partitioning. The exact behaviour is controlled by the
|
|
123
|
+
// `onPartitionViolation` constructor option (throw by default,
|
|
124
|
+
// or `warn` to log and proceed with a single partition).
|
|
125
|
+
this.assertPartitionsSupported(job);
|
|
126
|
+
|
|
127
|
+
// The launcher pre-created the execution; load the full object
|
|
128
|
+
// the executor needs. If the lookup fails here, the launcher's
|
|
129
|
+
// own state is broken — surface that loudly rather than silently
|
|
130
|
+
// running with `undefined`.
|
|
131
|
+
const execution: JobExecution | null = await this.repository.getJobExecution(ctx.executionId);
|
|
132
|
+
if (execution === null) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
`[InProcessExecutionStrategy] expected JobExecution ${ctx.executionId} to exist`,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
const finished = await this.jobExecutor.execute(execution, job);
|
|
138
|
+
return { kind: 'completed', status: finished.status };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Guard against partitioned chunk steps. Throws by default; logs a
|
|
143
|
+
* warning and continues with a single-partition execution when the
|
|
144
|
+
* host wires up `onPartitionViolation: 'warn'`. The default
|
|
145
|
+
* (throw) is the safer choice because it surfaces the
|
|
146
|
+
* misconfiguration at launch time rather than letting the step
|
|
147
|
+
* run with a silent single-partition semantics.
|
|
148
|
+
*/
|
|
149
|
+
private assertPartitionsSupported(job: JobDefinition): void {
|
|
150
|
+
for (const stepId of Object.keys(job.steps)) {
|
|
151
|
+
const step = job.steps[stepId];
|
|
152
|
+
if (step === undefined) continue;
|
|
153
|
+
if (step.kind !== 'chunk') continue;
|
|
154
|
+
const count = step.partitions?.count;
|
|
155
|
+
if (count === undefined || count <= 1) continue;
|
|
156
|
+
if (this.onPartitionViolation === 'warn') {
|
|
157
|
+
this.logger.warn(
|
|
158
|
+
`InProcessExecutionStrategy: step "${stepId}" declares partitions.count=${count} ` +
|
|
159
|
+
'but the in-process strategy cannot fan out. Running as a single partition; ' +
|
|
160
|
+
'configure a transport (BullMQ / Kafka) for true parallel partitioning.',
|
|
161
|
+
);
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
throw new InProcessPartitionsNotSupportedError(stepId, count);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Thrown by `InProcessExecutionStrategy` when a chunk step is
|
|
171
|
+
* configured with `partitions.count > 1`. The error is stable —
|
|
172
|
+
* callers that want to switch on it can match `code`. Distinct
|
|
173
|
+
* from `InvalidPartitionsError` (which fires on a structurally
|
|
174
|
+
* invalid config at compile time) because the in-process guard
|
|
175
|
+
* fires on a *valid* config that the chosen transport cannot honour.
|
|
176
|
+
*/
|
|
177
|
+
export class InProcessPartitionsNotSupportedError extends BatchError {
|
|
178
|
+
readonly code = 'IN_PROCESS_PARTITIONS_NOT_SUPPORTED';
|
|
179
|
+
constructor(stepId: string, count: number) {
|
|
180
|
+
super(
|
|
181
|
+
`InProcessExecutionStrategy does not support partitions.count > 1 (step "${stepId}" declares count=${count}). ` +
|
|
182
|
+
'Use a transport strategy (BullMQ / Kafka) for parallel partitioning.',
|
|
183
|
+
{ stepId, count },
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Nest DI provider record that binds `InProcessExecutionStrategy` to
|
|
190
|
+
* the `EXECUTION_STRATEGY` token. Sibling packages (e.g.
|
|
191
|
+
* `@nest-batch/bullmq`) override this binding with their own transport
|
|
192
|
+
* strategy to switch the launcher's execution target without touching
|
|
193
|
+
* the launcher itself.
|
|
194
|
+
*
|
|
195
|
+
* `NestBatchModule.forRoot()` re-exports this provider so apps can add
|
|
196
|
+
* it to their own `providers` array (the strategy needs
|
|
197
|
+
* `JobRepository` and `JobExecutor` to be in the same DI scope, and
|
|
198
|
+
* those are app-owned runtime deps — see the module's docstring for
|
|
199
|
+
* the rationale). Apps that build a `JobLauncher` by hand (no Nest
|
|
200
|
+
* module) can either provide their own `EXECUTION_STRATEGY` binding
|
|
201
|
+
* or rely on the `@Optional()` fallback in `JobLauncher`, which
|
|
202
|
+
* delegates directly to `JobExecutor` when no strategy is injected.
|
|
203
|
+
*/
|
|
204
|
+
export const IN_PROCESS_EXECUTION_STRATEGY_PROVIDER = {
|
|
205
|
+
provide: EXECUTION_STRATEGY,
|
|
206
|
+
useExisting: InProcessExecutionStrategy,
|
|
207
|
+
} as const;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './listener-invoker';
|
|
2
|
+
export * from './tasklet-step-executor';
|
|
3
|
+
export * from './chunk-step-executor';
|
|
4
|
+
export * from './job-executor';
|
|
5
|
+
export * from './job-launcher';
|
|
6
|
+
export * from './job-explorer';
|
|
7
|
+
export * from './job-operator';
|
|
8
|
+
export * from './batch-worker-runner';
|
|
9
|
+
export * from './external-task-execution-strategy';
|
|
10
|
+
export * from './job-key';
|
|
11
|
+
export * from './execution-strategy';
|
|
12
|
+
export * from './ref-resolver';
|
|
13
|
+
export * from './in-process-execution-strategy';
|