@nest-batch/aws-batch 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 +33 -0
- package/dist/src/aws-batch-job-launcher.d.ts +12 -0
- package/dist/src/aws-batch-job-launcher.d.ts.map +1 -0
- package/dist/src/aws-batch-job-launcher.js +106 -0
- package/dist/src/aws-batch-job-launcher.js.map +1 -0
- package/dist/src/aws-batch.adapter.d.ts +8 -0
- package/dist/src/aws-batch.adapter.d.ts.map +1 -0
- package/dist/src/aws-batch.adapter.js +90 -0
- package/dist/src/aws-batch.adapter.js.map +1 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +22 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/module-options.d.ts +68 -0
- package/dist/src/module-options.d.ts.map +1 -0
- package/dist/src/module-options.js +65 -0
- package/dist/src/module-options.js.map +1 -0
- package/package.json +54 -0
- package/src/aws-batch-job-launcher.ts +77 -0
- package/src/aws-batch.adapter.ts +78 -0
- package/src/index.ts +3 -0
- package/src/module-options.ts +78 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 easdkr
|
|
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,33 @@
|
|
|
1
|
+
# @nest-batch/aws-batch
|
|
2
|
+
|
|
3
|
+
AWS Batch submit-job adapter for `@nest-batch/core`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @nest-batch/aws-batch @nest-batch/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Peer dependencies:
|
|
12
|
+
|
|
13
|
+
- `@nest-batch/core@^0.2.0`
|
|
14
|
+
- `@nestjs/common@^10 || ^11`
|
|
15
|
+
- `@nestjs/core@^10 || ^11`
|
|
16
|
+
|
|
17
|
+
## What this package provides
|
|
18
|
+
|
|
19
|
+
- `AwsBatchAdapter`
|
|
20
|
+
- `AwsBatchJobLauncher`
|
|
21
|
+
- AWS Batch module option types
|
|
22
|
+
|
|
23
|
+
Use this package when a launcher service should submit batch work to AWS Batch.
|
|
24
|
+
The package is an execution adapter. It does not define jobs, own persistence,
|
|
25
|
+
or create AWS infrastructure.
|
|
26
|
+
|
|
27
|
+
## Build and test
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pnpm --filter @nest-batch/aws-batch build
|
|
31
|
+
pnpm --filter @nest-batch/aws-batch test
|
|
32
|
+
pnpm --filter @nest-batch/aws-batch typecheck
|
|
33
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ExternalTaskLauncher, ExternalTaskLaunchRequest, ExternalTaskLaunchResult } from '@nest-batch/core';
|
|
2
|
+
import { type AwsBatchSubmitJobInput, type ResolvedAwsBatchModuleOptions } from './module-options';
|
|
3
|
+
export declare const AWS_BATCH_STRATEGY_NAME = "aws-batch";
|
|
4
|
+
export declare class AwsBatchJobLauncher implements ExternalTaskLauncher {
|
|
5
|
+
private readonly options;
|
|
6
|
+
readonly name = "aws-batch";
|
|
7
|
+
constructor(options: ResolvedAwsBatchModuleOptions);
|
|
8
|
+
launch(request: ExternalTaskLaunchRequest): Promise<ExternalTaskLaunchResult>;
|
|
9
|
+
buildSubmitJobInput(request: ExternalTaskLaunchRequest): AwsBatchSubmitJobInput;
|
|
10
|
+
private buildJobName;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=aws-batch-job-launcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws-batch-job-launcher.d.ts","sourceRoot":"","sources":["../../src/aws-batch-job-launcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,yBAAyB,EACzB,wBAAwB,EACzB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAEL,KAAK,sBAAsB,EAC3B,KAAK,6BAA6B,EACnC,MAAM,kBAAkB,CAAC;AAE1B,eAAO,MAAM,uBAAuB,cAAc,CAAC;AAEnD,qBACa,mBAAoB,YAAW,oBAAoB;IAK5D,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,QAAQ,CAAC,IAAI,eAA2B;gBAIrB,OAAO,EAAE,6BAA6B;IAGnD,MAAM,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAiBnF,mBAAmB,CAAC,OAAO,EAAE,yBAAyB,GAAG,sBAAsB;IA+B/E,OAAO,CAAC,YAAY;CAIrB"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get AWS_BATCH_STRATEGY_NAME () {
|
|
13
|
+
return AWS_BATCH_STRATEGY_NAME;
|
|
14
|
+
},
|
|
15
|
+
get AwsBatchJobLauncher () {
|
|
16
|
+
return AwsBatchJobLauncher;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _common = require("@nestjs/common");
|
|
20
|
+
const _moduleoptions = require("./module-options");
|
|
21
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
22
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
23
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
24
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
25
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
26
|
+
}
|
|
27
|
+
function _ts_metadata(k, v) {
|
|
28
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
29
|
+
}
|
|
30
|
+
function _ts_param(paramIndex, decorator) {
|
|
31
|
+
return function(target, key) {
|
|
32
|
+
decorator(target, key, paramIndex);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const AWS_BATCH_STRATEGY_NAME = 'aws-batch';
|
|
36
|
+
let AwsBatchJobLauncher = class AwsBatchJobLauncher {
|
|
37
|
+
options;
|
|
38
|
+
name = AWS_BATCH_STRATEGY_NAME;
|
|
39
|
+
constructor(options){
|
|
40
|
+
this.options = options;
|
|
41
|
+
}
|
|
42
|
+
async launch(request) {
|
|
43
|
+
const input = this.buildSubmitJobInput(request);
|
|
44
|
+
const output = await this.options.client.submitJob(input);
|
|
45
|
+
if (output.jobId === undefined || output.jobId.length === 0) {
|
|
46
|
+
throw new Error('AWS Batch SubmitJob did not return a jobId');
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
provider: this.name,
|
|
50
|
+
externalId: output.jobId,
|
|
51
|
+
metadata: {
|
|
52
|
+
jobName: output.jobName ?? input.jobName,
|
|
53
|
+
jobQueue: this.options.jobQueue,
|
|
54
|
+
jobDefinition: this.options.jobDefinition
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
buildSubmitJobInput(request) {
|
|
59
|
+
return {
|
|
60
|
+
jobName: this.buildJobName(request.jobExecutionId),
|
|
61
|
+
jobQueue: this.options.jobQueue,
|
|
62
|
+
jobDefinition: this.options.jobDefinition,
|
|
63
|
+
parameters: {
|
|
64
|
+
...this.options.parameters,
|
|
65
|
+
jobId: request.jobId,
|
|
66
|
+
jobExecutionId: request.jobExecutionId
|
|
67
|
+
},
|
|
68
|
+
containerOverrides: {
|
|
69
|
+
command: [
|
|
70
|
+
...request.workerArgs
|
|
71
|
+
],
|
|
72
|
+
environment: Object.entries(request.env).map(([name, value])=>({
|
|
73
|
+
name,
|
|
74
|
+
value
|
|
75
|
+
}))
|
|
76
|
+
},
|
|
77
|
+
...this.options.arrayProperties !== undefined ? {
|
|
78
|
+
arrayProperties: this.options.arrayProperties
|
|
79
|
+
} : {},
|
|
80
|
+
...this.options.retryStrategy !== undefined ? {
|
|
81
|
+
retryStrategy: this.options.retryStrategy
|
|
82
|
+
} : {},
|
|
83
|
+
...this.options.timeout !== undefined ? {
|
|
84
|
+
timeout: this.options.timeout
|
|
85
|
+
} : {},
|
|
86
|
+
tags: {
|
|
87
|
+
...this.options.tags,
|
|
88
|
+
...request.labels
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
buildJobName(jobExecutionId) {
|
|
93
|
+
const suffix = jobExecutionId.replace(/[^A-Za-z0-9_-]/g, '-');
|
|
94
|
+
return `${this.options.jobNamePrefix}-${suffix}`.slice(0, 128);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
AwsBatchJobLauncher = _ts_decorate([
|
|
98
|
+
(0, _common.Injectable)(),
|
|
99
|
+
_ts_param(0, (0, _common.Inject)(_moduleoptions.AWS_BATCH_MODULE_OPTIONS)),
|
|
100
|
+
_ts_metadata("design:type", Function),
|
|
101
|
+
_ts_metadata("design:paramtypes", [
|
|
102
|
+
typeof ResolvedAwsBatchModuleOptions === "undefined" ? Object : ResolvedAwsBatchModuleOptions
|
|
103
|
+
])
|
|
104
|
+
], AwsBatchJobLauncher);
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=aws-batch-job-launcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/aws-batch-job-launcher.ts"],"sourcesContent":["import { Inject, Injectable } from '@nestjs/common';\nimport type {\n ExternalTaskLauncher,\n ExternalTaskLaunchRequest,\n ExternalTaskLaunchResult,\n} from '@nest-batch/core';\n\nimport {\n AWS_BATCH_MODULE_OPTIONS,\n type AwsBatchSubmitJobInput,\n type ResolvedAwsBatchModuleOptions,\n} from './module-options';\n\nexport const AWS_BATCH_STRATEGY_NAME = 'aws-batch';\n\n@Injectable()\nexport class AwsBatchJobLauncher implements ExternalTaskLauncher {\n readonly name = AWS_BATCH_STRATEGY_NAME;\n\n constructor(\n @Inject(AWS_BATCH_MODULE_OPTIONS)\n private readonly options: ResolvedAwsBatchModuleOptions,\n ) {}\n\n async launch(request: ExternalTaskLaunchRequest): Promise<ExternalTaskLaunchResult> {\n const input = this.buildSubmitJobInput(request);\n const output = await this.options.client.submitJob(input);\n if (output.jobId === undefined || output.jobId.length === 0) {\n throw new Error('AWS Batch SubmitJob did not return a jobId');\n }\n return {\n provider: this.name,\n externalId: output.jobId,\n metadata: {\n jobName: output.jobName ?? input.jobName,\n jobQueue: this.options.jobQueue,\n jobDefinition: this.options.jobDefinition,\n },\n };\n }\n\n buildSubmitJobInput(request: ExternalTaskLaunchRequest): AwsBatchSubmitJobInput {\n return {\n jobName: this.buildJobName(request.jobExecutionId),\n jobQueue: this.options.jobQueue,\n jobDefinition: this.options.jobDefinition,\n parameters: {\n ...this.options.parameters,\n jobId: request.jobId,\n jobExecutionId: request.jobExecutionId,\n },\n containerOverrides: {\n command: [...request.workerArgs],\n environment: Object.entries(request.env).map(([name, value]) => ({\n name,\n value,\n })),\n },\n ...(this.options.arrayProperties !== undefined\n ? { arrayProperties: this.options.arrayProperties }\n : {}),\n ...(this.options.retryStrategy !== undefined\n ? { retryStrategy: this.options.retryStrategy }\n : {}),\n ...(this.options.timeout !== undefined ? { timeout: this.options.timeout } : {}),\n tags: {\n ...this.options.tags,\n ...request.labels,\n },\n };\n }\n\n private buildJobName(jobExecutionId: string): string {\n const suffix = jobExecutionId.replace(/[^A-Za-z0-9_-]/g, '-');\n return `${this.options.jobNamePrefix}-${suffix}`.slice(0, 128);\n }\n}\n"],"names":["AWS_BATCH_STRATEGY_NAME","AwsBatchJobLauncher","name","options","launch","request","input","buildSubmitJobInput","output","client","submitJob","jobId","undefined","length","Error","provider","externalId","metadata","jobName","jobQueue","jobDefinition","buildJobName","jobExecutionId","parameters","containerOverrides","command","workerArgs","environment","Object","entries","env","map","value","arrayProperties","retryStrategy","timeout","tags","labels","suffix","replace","jobNamePrefix","slice"],"mappings":";;;;;;;;;;;QAaaA;eAAAA;;QAGAC;eAAAA;;;wBAhBsB;+BAW5B;;;;;;;;;;;;;;;AAEA,MAAMD,0BAA0B;AAGhC,IAAA,AAAMC,sBAAN,MAAMA;;IACFC,OAAOF,wBAAwB;IAExC,YACE,AACiBG,OAAsC,CACvD;aADiBA,UAAAA;IAChB;IAEH,MAAMC,OAAOC,OAAkC,EAAqC;QAClF,MAAMC,QAAQ,IAAI,CAACC,mBAAmB,CAACF;QACvC,MAAMG,SAAS,MAAM,IAAI,CAACL,OAAO,CAACM,MAAM,CAACC,SAAS,CAACJ;QACnD,IAAIE,OAAOG,KAAK,KAAKC,aAAaJ,OAAOG,KAAK,CAACE,MAAM,KAAK,GAAG;YAC3D,MAAM,IAAIC,MAAM;QAClB;QACA,OAAO;YACLC,UAAU,IAAI,CAACb,IAAI;YACnBc,YAAYR,OAAOG,KAAK;YACxBM,UAAU;gBACRC,SAASV,OAAOU,OAAO,IAAIZ,MAAMY,OAAO;gBACxCC,UAAU,IAAI,CAAChB,OAAO,CAACgB,QAAQ;gBAC/BC,eAAe,IAAI,CAACjB,OAAO,CAACiB,aAAa;YAC3C;QACF;IACF;IAEAb,oBAAoBF,OAAkC,EAA0B;QAC9E,OAAO;YACLa,SAAS,IAAI,CAACG,YAAY,CAAChB,QAAQiB,cAAc;YACjDH,UAAU,IAAI,CAAChB,OAAO,CAACgB,QAAQ;YAC/BC,eAAe,IAAI,CAACjB,OAAO,CAACiB,aAAa;YACzCG,YAAY;gBACV,GAAG,IAAI,CAACpB,OAAO,CAACoB,UAAU;gBAC1BZ,OAAON,QAAQM,KAAK;gBACpBW,gBAAgBjB,QAAQiB,cAAc;YACxC;YACAE,oBAAoB;gBAClBC,SAAS;uBAAIpB,QAAQqB,UAAU;iBAAC;gBAChCC,aAAaC,OAAOC,OAAO,CAACxB,QAAQyB,GAAG,EAAEC,GAAG,CAAC,CAAC,CAAC7B,MAAM8B,MAAM,GAAM,CAAA;wBAC/D9B;wBACA8B;oBACF,CAAA;YACF;YACA,GAAI,IAAI,CAAC7B,OAAO,CAAC8B,eAAe,KAAKrB,YACjC;gBAAEqB,iBAAiB,IAAI,CAAC9B,OAAO,CAAC8B,eAAe;YAAC,IAChD,CAAC,CAAC;YACN,GAAI,IAAI,CAAC9B,OAAO,CAAC+B,aAAa,KAAKtB,YAC/B;gBAAEsB,eAAe,IAAI,CAAC/B,OAAO,CAAC+B,aAAa;YAAC,IAC5C,CAAC,CAAC;YACN,GAAI,IAAI,CAAC/B,OAAO,CAACgC,OAAO,KAAKvB,YAAY;gBAAEuB,SAAS,IAAI,CAAChC,OAAO,CAACgC,OAAO;YAAC,IAAI,CAAC,CAAC;YAC/EC,MAAM;gBACJ,GAAG,IAAI,CAACjC,OAAO,CAACiC,IAAI;gBACpB,GAAG/B,QAAQgC,MAAM;YACnB;QACF;IACF;IAEQhB,aAAaC,cAAsB,EAAU;QACnD,MAAMgB,SAAShB,eAAeiB,OAAO,CAAC,mBAAmB;QACzD,OAAO,GAAG,IAAI,CAACpC,OAAO,CAACqC,aAAa,CAAC,CAAC,EAAEF,QAAQ,CAACG,KAAK,CAAC,GAAG;IAC5D;AACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type BatchAdapter } from '@nest-batch/core';
|
|
2
|
+
import { type AwsBatchModuleOptions } from './module-options';
|
|
3
|
+
export declare class AwsBatchModule {
|
|
4
|
+
}
|
|
5
|
+
export declare class AwsBatchAdapter {
|
|
6
|
+
static forRoot(options: AwsBatchModuleOptions): BatchAdapter;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=aws-batch.adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws-batch.adapter.d.ts","sourceRoot":"","sources":["../../src/aws-batch.adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,KAAK,YAAY,EAClB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAEL,KAAK,qBAAqB,EAG3B,MAAM,kBAAkB,CAAC;AAE1B,qBACa,cAAc;CAAG;AAa9B,qBAAa,eAAe;IAC1B,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,qBAAqB,GAAG,YAAY;CAS7D"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get AwsBatchAdapter () {
|
|
13
|
+
return AwsBatchAdapter;
|
|
14
|
+
},
|
|
15
|
+
get AwsBatchModule () {
|
|
16
|
+
return AwsBatchModule;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _common = require("@nestjs/common");
|
|
20
|
+
const _core = require("@nest-batch/core");
|
|
21
|
+
const _awsbatchjoblauncher = require("./aws-batch-job-launcher");
|
|
22
|
+
const _moduleoptions = require("./module-options");
|
|
23
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
24
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
25
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
26
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
27
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
28
|
+
}
|
|
29
|
+
let AwsBatchModule = class AwsBatchModule {
|
|
30
|
+
};
|
|
31
|
+
AwsBatchModule = _ts_decorate([
|
|
32
|
+
(0, _common.Module)({})
|
|
33
|
+
], AwsBatchModule);
|
|
34
|
+
const ADAPTER_EXPORTS = [
|
|
35
|
+
_core.EXECUTION_STRATEGY,
|
|
36
|
+
_core.EXTERNAL_TASK_LAUNCHER,
|
|
37
|
+
_core.EXTERNAL_TASK_STRATEGY_OPTIONS,
|
|
38
|
+
_moduleoptions.AWS_BATCH_MODULE_OPTIONS,
|
|
39
|
+
_core.ExternalTaskExecutionStrategy,
|
|
40
|
+
_awsbatchjoblauncher.AwsBatchJobLauncher
|
|
41
|
+
];
|
|
42
|
+
let AwsBatchAdapter = class AwsBatchAdapter {
|
|
43
|
+
static forRoot(options) {
|
|
44
|
+
const resolved = (0, _moduleoptions.resolveAwsBatchOptions)(options);
|
|
45
|
+
return {
|
|
46
|
+
name: 'aws-batch',
|
|
47
|
+
module: buildAwsBatchDynamicModule({
|
|
48
|
+
providers: buildStaticProviders(resolved)
|
|
49
|
+
})
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
function buildStaticProviders(resolved) {
|
|
54
|
+
return [
|
|
55
|
+
_awsbatchjoblauncher.AwsBatchJobLauncher,
|
|
56
|
+
_core.ExternalTaskExecutionStrategy,
|
|
57
|
+
{
|
|
58
|
+
provide: _core.EXECUTION_STRATEGY,
|
|
59
|
+
useExisting: _core.ExternalTaskExecutionStrategy
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
provide: _core.EXTERNAL_TASK_LAUNCHER,
|
|
63
|
+
useExisting: _awsbatchjoblauncher.AwsBatchJobLauncher
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
provide: _core.EXTERNAL_TASK_STRATEGY_OPTIONS,
|
|
67
|
+
useValue: {
|
|
68
|
+
workerCommand: resolved.workerCommand,
|
|
69
|
+
env: resolved.env,
|
|
70
|
+
labels: resolved.labels
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
provide: _moduleoptions.AWS_BATCH_MODULE_OPTIONS,
|
|
75
|
+
useValue: resolved
|
|
76
|
+
}
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
function buildAwsBatchDynamicModule(args) {
|
|
80
|
+
return {
|
|
81
|
+
module: AwsBatchModule,
|
|
82
|
+
global: true,
|
|
83
|
+
providers: args.providers,
|
|
84
|
+
exports: [
|
|
85
|
+
...ADAPTER_EXPORTS
|
|
86
|
+
]
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=aws-batch.adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/aws-batch.adapter.ts"],"sourcesContent":["import { Module, type DynamicModule, type Provider } from '@nestjs/common';\nimport {\n EXECUTION_STRATEGY,\n EXTERNAL_TASK_LAUNCHER,\n EXTERNAL_TASK_STRATEGY_OPTIONS,\n ExternalTaskExecutionStrategy,\n type BatchAdapter,\n} from '@nest-batch/core';\n\nimport { AwsBatchJobLauncher } from './aws-batch-job-launcher';\nimport {\n AWS_BATCH_MODULE_OPTIONS,\n type AwsBatchModuleOptions,\n type ResolvedAwsBatchModuleOptions,\n resolveAwsBatchOptions,\n} from './module-options';\n\n@Module({})\nexport class AwsBatchModule {}\n\nconst ADAPTER_EXPORTS: ReadonlyArray<\n symbol | typeof ExternalTaskExecutionStrategy | typeof AwsBatchJobLauncher\n> = [\n EXECUTION_STRATEGY,\n EXTERNAL_TASK_LAUNCHER,\n EXTERNAL_TASK_STRATEGY_OPTIONS,\n AWS_BATCH_MODULE_OPTIONS,\n ExternalTaskExecutionStrategy,\n AwsBatchJobLauncher,\n];\n\nexport class AwsBatchAdapter {\n static forRoot(options: AwsBatchModuleOptions): BatchAdapter {\n const resolved = resolveAwsBatchOptions(options);\n return {\n name: 'aws-batch',\n module: buildAwsBatchDynamicModule({\n providers: buildStaticProviders(resolved),\n }),\n };\n }\n}\n\nfunction buildStaticProviders(resolved: ResolvedAwsBatchModuleOptions): Provider[] {\n return [\n AwsBatchJobLauncher,\n ExternalTaskExecutionStrategy,\n {\n provide: EXECUTION_STRATEGY,\n useExisting: ExternalTaskExecutionStrategy,\n },\n {\n provide: EXTERNAL_TASK_LAUNCHER,\n useExisting: AwsBatchJobLauncher,\n },\n {\n provide: EXTERNAL_TASK_STRATEGY_OPTIONS,\n useValue: {\n workerCommand: resolved.workerCommand,\n env: resolved.env,\n labels: resolved.labels,\n },\n },\n {\n provide: AWS_BATCH_MODULE_OPTIONS,\n useValue: resolved,\n },\n ];\n}\n\nfunction buildAwsBatchDynamicModule(args: { providers: Provider[] }): DynamicModule {\n return {\n module: AwsBatchModule,\n global: true,\n providers: args.providers,\n exports: [...ADAPTER_EXPORTS],\n };\n}\n"],"names":["AwsBatchAdapter","AwsBatchModule","ADAPTER_EXPORTS","EXECUTION_STRATEGY","EXTERNAL_TASK_LAUNCHER","EXTERNAL_TASK_STRATEGY_OPTIONS","AWS_BATCH_MODULE_OPTIONS","ExternalTaskExecutionStrategy","AwsBatchJobLauncher","forRoot","options","resolved","resolveAwsBatchOptions","name","module","buildAwsBatchDynamicModule","providers","buildStaticProviders","provide","useExisting","useValue","workerCommand","env","labels","args","global","exports"],"mappings":";;;;;;;;;;;QA+BaA;eAAAA;;QAbAC;eAAAA;;;wBAlB6C;sBAOnD;qCAE6B;+BAM7B;;;;;;;AAGA,IAAA,AAAMA,iBAAN,MAAMA;AAAgB;;;;AAE7B,MAAMC,kBAEF;IACFC,wBAAkB;IAClBC,4BAAsB;IACtBC,oCAA8B;IAC9BC,uCAAwB;IACxBC,mCAA6B;IAC7BC,wCAAmB;CACpB;AAEM,IAAA,AAAMR,kBAAN,MAAMA;IACX,OAAOS,QAAQC,OAA8B,EAAgB;QAC3D,MAAMC,WAAWC,IAAAA,qCAAsB,EAACF;QACxC,OAAO;YACLG,MAAM;YACNC,QAAQC,2BAA2B;gBACjCC,WAAWC,qBAAqBN;YAClC;QACF;IACF;AACF;AAEA,SAASM,qBAAqBN,QAAuC;IACnE,OAAO;QACLH,wCAAmB;QACnBD,mCAA6B;QAC7B;YACEW,SAASf,wBAAkB;YAC3BgB,aAAaZ,mCAA6B;QAC5C;QACA;YACEW,SAASd,4BAAsB;YAC/Be,aAAaX,wCAAmB;QAClC;QACA;YACEU,SAASb,oCAA8B;YACvCe,UAAU;gBACRC,eAAeV,SAASU,aAAa;gBACrCC,KAAKX,SAASW,GAAG;gBACjBC,QAAQZ,SAASY,MAAM;YACzB;QACF;QACA;YACEL,SAASZ,uCAAwB;YACjCc,UAAUT;QACZ;KACD;AACH;AAEA,SAASI,2BAA2BS,IAA+B;IACjE,OAAO;QACLV,QAAQb;QACRwB,QAAQ;QACRT,WAAWQ,KAAKR,SAAS;QACzBU,SAAS;eAAIxB;SAAgB;IAC/B;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./module-options"), exports);
|
|
6
|
+
_export_star(require("./aws-batch-job-launcher"), exports);
|
|
7
|
+
_export_star(require("./aws-batch.adapter"), exports);
|
|
8
|
+
function _export_star(from, to) {
|
|
9
|
+
Object.keys(from).forEach(function(k) {
|
|
10
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
11
|
+
Object.defineProperty(to, k, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function() {
|
|
14
|
+
return from[k];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return from;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './module-options';\nexport * from './aws-batch-job-launcher';\nexport * from './aws-batch.adapter';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ExternalTaskStrategyOptions } from '@nest-batch/core';
|
|
2
|
+
export declare const AWS_BATCH_MODULE_OPTIONS: symbol;
|
|
3
|
+
export interface AwsBatchSubmitJobInput {
|
|
4
|
+
readonly jobName: string;
|
|
5
|
+
readonly jobQueue: string;
|
|
6
|
+
readonly jobDefinition: string;
|
|
7
|
+
readonly parameters?: Readonly<Record<string, string>>;
|
|
8
|
+
readonly containerOverrides?: {
|
|
9
|
+
readonly command?: readonly string[];
|
|
10
|
+
readonly environment?: readonly {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly value: string;
|
|
13
|
+
}[];
|
|
14
|
+
};
|
|
15
|
+
readonly arrayProperties?: {
|
|
16
|
+
readonly size: number;
|
|
17
|
+
};
|
|
18
|
+
readonly retryStrategy?: {
|
|
19
|
+
readonly attempts?: number;
|
|
20
|
+
};
|
|
21
|
+
readonly timeout?: {
|
|
22
|
+
readonly attemptDurationSeconds?: number;
|
|
23
|
+
};
|
|
24
|
+
readonly tags?: Readonly<Record<string, string>>;
|
|
25
|
+
}
|
|
26
|
+
export interface AwsBatchSubmitJobOutput {
|
|
27
|
+
readonly jobId?: string;
|
|
28
|
+
readonly jobName?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface AwsBatchSubmitJobClient {
|
|
31
|
+
submitJob(input: AwsBatchSubmitJobInput): Promise<AwsBatchSubmitJobOutput>;
|
|
32
|
+
}
|
|
33
|
+
export interface AwsBatchModuleOptions extends ExternalTaskStrategyOptions {
|
|
34
|
+
readonly client: AwsBatchSubmitJobClient;
|
|
35
|
+
readonly jobQueue: string;
|
|
36
|
+
readonly jobDefinition: string;
|
|
37
|
+
readonly jobNamePrefix?: string;
|
|
38
|
+
readonly parameters?: Readonly<Record<string, string>>;
|
|
39
|
+
readonly arrayProperties?: {
|
|
40
|
+
readonly size: number;
|
|
41
|
+
};
|
|
42
|
+
readonly retryStrategy?: {
|
|
43
|
+
readonly attempts?: number;
|
|
44
|
+
};
|
|
45
|
+
readonly timeout?: {
|
|
46
|
+
readonly attemptDurationSeconds?: number;
|
|
47
|
+
};
|
|
48
|
+
readonly tags?: Readonly<Record<string, string>>;
|
|
49
|
+
}
|
|
50
|
+
export interface ResolvedAwsBatchModuleOptions extends ExternalTaskStrategyOptions {
|
|
51
|
+
readonly client: AwsBatchSubmitJobClient;
|
|
52
|
+
readonly jobQueue: string;
|
|
53
|
+
readonly jobDefinition: string;
|
|
54
|
+
readonly jobNamePrefix: string;
|
|
55
|
+
readonly parameters: Readonly<Record<string, string>>;
|
|
56
|
+
readonly arrayProperties?: {
|
|
57
|
+
readonly size: number;
|
|
58
|
+
};
|
|
59
|
+
readonly retryStrategy?: {
|
|
60
|
+
readonly attempts?: number;
|
|
61
|
+
};
|
|
62
|
+
readonly timeout?: {
|
|
63
|
+
readonly attemptDurationSeconds?: number;
|
|
64
|
+
};
|
|
65
|
+
readonly tags: Readonly<Record<string, string>>;
|
|
66
|
+
}
|
|
67
|
+
export declare function resolveAwsBatchOptions(options: AwsBatchModuleOptions): ResolvedAwsBatchModuleOptions;
|
|
68
|
+
//# sourceMappingURL=module-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-options.d.ts","sourceRoot":"","sources":["../../src/module-options.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get AWS_BATCH_MODULE_OPTIONS () {
|
|
13
|
+
return AWS_BATCH_MODULE_OPTIONS;
|
|
14
|
+
},
|
|
15
|
+
get resolveAwsBatchOptions () {
|
|
16
|
+
return resolveAwsBatchOptions;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const AWS_BATCH_MODULE_OPTIONS = Symbol.for('@nest-batch/aws-batch/AWS_BATCH_MODULE_OPTIONS');
|
|
20
|
+
function resolveAwsBatchOptions(options) {
|
|
21
|
+
return Object.freeze({
|
|
22
|
+
client: options.client,
|
|
23
|
+
jobQueue: options.jobQueue,
|
|
24
|
+
jobDefinition: options.jobDefinition,
|
|
25
|
+
jobNamePrefix: options.jobNamePrefix ?? 'nest-batch',
|
|
26
|
+
parameters: Object.freeze({
|
|
27
|
+
...options.parameters ?? {}
|
|
28
|
+
}),
|
|
29
|
+
...options.arrayProperties !== undefined ? {
|
|
30
|
+
arrayProperties: Object.freeze({
|
|
31
|
+
...options.arrayProperties
|
|
32
|
+
})
|
|
33
|
+
} : {},
|
|
34
|
+
...options.retryStrategy !== undefined ? {
|
|
35
|
+
retryStrategy: Object.freeze({
|
|
36
|
+
...options.retryStrategy
|
|
37
|
+
})
|
|
38
|
+
} : {},
|
|
39
|
+
...options.timeout !== undefined ? {
|
|
40
|
+
timeout: Object.freeze({
|
|
41
|
+
...options.timeout
|
|
42
|
+
})
|
|
43
|
+
} : {},
|
|
44
|
+
tags: Object.freeze({
|
|
45
|
+
...options.tags ?? {}
|
|
46
|
+
}),
|
|
47
|
+
...options.workerCommand !== undefined ? {
|
|
48
|
+
workerCommand: Object.freeze([
|
|
49
|
+
...options.workerCommand
|
|
50
|
+
])
|
|
51
|
+
} : {},
|
|
52
|
+
...options.env !== undefined ? {
|
|
53
|
+
env: Object.freeze({
|
|
54
|
+
...options.env
|
|
55
|
+
})
|
|
56
|
+
} : {},
|
|
57
|
+
...options.labels !== undefined ? {
|
|
58
|
+
labels: Object.freeze({
|
|
59
|
+
...options.labels
|
|
60
|
+
})
|
|
61
|
+
} : {}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=module-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/module-options.ts"],"sourcesContent":["import type { ExternalTaskStrategyOptions } from '@nest-batch/core';\n\nexport const AWS_BATCH_MODULE_OPTIONS: symbol = Symbol.for(\n '@nest-batch/aws-batch/AWS_BATCH_MODULE_OPTIONS',\n);\n\nexport interface AwsBatchSubmitJobInput {\n readonly jobName: string;\n readonly jobQueue: string;\n readonly jobDefinition: string;\n readonly parameters?: Readonly<Record<string, string>>;\n readonly containerOverrides?: {\n readonly command?: readonly string[];\n readonly environment?: readonly { readonly name: string; readonly value: string }[];\n };\n readonly arrayProperties?: { readonly size: number };\n readonly retryStrategy?: { readonly attempts?: number };\n readonly timeout?: { readonly attemptDurationSeconds?: number };\n readonly tags?: Readonly<Record<string, string>>;\n}\n\nexport interface AwsBatchSubmitJobOutput {\n readonly jobId?: string;\n readonly jobName?: string;\n}\n\nexport interface AwsBatchSubmitJobClient {\n submitJob(input: AwsBatchSubmitJobInput): Promise<AwsBatchSubmitJobOutput>;\n}\n\nexport interface AwsBatchModuleOptions extends ExternalTaskStrategyOptions {\n readonly client: AwsBatchSubmitJobClient;\n readonly jobQueue: string;\n readonly jobDefinition: string;\n readonly jobNamePrefix?: string;\n readonly parameters?: Readonly<Record<string, string>>;\n readonly arrayProperties?: { readonly size: number };\n readonly retryStrategy?: { readonly attempts?: number };\n readonly timeout?: { readonly attemptDurationSeconds?: number };\n readonly tags?: Readonly<Record<string, string>>;\n}\n\nexport interface ResolvedAwsBatchModuleOptions extends ExternalTaskStrategyOptions {\n readonly client: AwsBatchSubmitJobClient;\n readonly jobQueue: string;\n readonly jobDefinition: string;\n readonly jobNamePrefix: string;\n readonly parameters: Readonly<Record<string, string>>;\n readonly arrayProperties?: { readonly size: number };\n readonly retryStrategy?: { readonly attempts?: number };\n readonly timeout?: { readonly attemptDurationSeconds?: number };\n readonly tags: Readonly<Record<string, string>>;\n}\n\nexport function resolveAwsBatchOptions(\n options: AwsBatchModuleOptions,\n): ResolvedAwsBatchModuleOptions {\n return Object.freeze({\n client: options.client,\n jobQueue: options.jobQueue,\n jobDefinition: options.jobDefinition,\n jobNamePrefix: options.jobNamePrefix ?? 'nest-batch',\n parameters: Object.freeze({ ...(options.parameters ?? {}) }),\n ...(options.arrayProperties !== undefined\n ? { arrayProperties: Object.freeze({ ...options.arrayProperties }) }\n : {}),\n ...(options.retryStrategy !== undefined\n ? { retryStrategy: Object.freeze({ ...options.retryStrategy }) }\n : {}),\n ...(options.timeout !== undefined ? { timeout: Object.freeze({ ...options.timeout }) } : {}),\n tags: Object.freeze({ ...(options.tags ?? {}) }),\n ...(options.workerCommand !== undefined\n ? { workerCommand: Object.freeze([...options.workerCommand]) }\n : {}),\n ...(options.env !== undefined ? { env: Object.freeze({ ...options.env }) } : {}),\n ...(options.labels !== undefined ? { labels: Object.freeze({ ...options.labels }) } : {}),\n });\n}\n"],"names":["AWS_BATCH_MODULE_OPTIONS","resolveAwsBatchOptions","Symbol","for","options","Object","freeze","client","jobQueue","jobDefinition","jobNamePrefix","parameters","arrayProperties","undefined","retryStrategy","timeout","tags","workerCommand","env","labels"],"mappings":";;;;;;;;;;;QAEaA;eAAAA;;QAoDGC;eAAAA;;;AApDT,MAAMD,2BAAmCE,OAAOC,GAAG,CACxD;AAmDK,SAASF,uBACdG,OAA8B;IAE9B,OAAOC,OAAOC,MAAM,CAAC;QACnBC,QAAQH,QAAQG,MAAM;QACtBC,UAAUJ,QAAQI,QAAQ;QAC1BC,eAAeL,QAAQK,aAAa;QACpCC,eAAeN,QAAQM,aAAa,IAAI;QACxCC,YAAYN,OAAOC,MAAM,CAAC;YAAE,GAAIF,QAAQO,UAAU,IAAI,CAAC,CAAC;QAAE;QAC1D,GAAIP,QAAQQ,eAAe,KAAKC,YAC5B;YAAED,iBAAiBP,OAAOC,MAAM,CAAC;gBAAE,GAAGF,QAAQQ,eAAe;YAAC;QAAG,IACjE,CAAC,CAAC;QACN,GAAIR,QAAQU,aAAa,KAAKD,YAC1B;YAAEC,eAAeT,OAAOC,MAAM,CAAC;gBAAE,GAAGF,QAAQU,aAAa;YAAC;QAAG,IAC7D,CAAC,CAAC;QACN,GAAIV,QAAQW,OAAO,KAAKF,YAAY;YAAEE,SAASV,OAAOC,MAAM,CAAC;gBAAE,GAAGF,QAAQW,OAAO;YAAC;QAAG,IAAI,CAAC,CAAC;QAC3FC,MAAMX,OAAOC,MAAM,CAAC;YAAE,GAAIF,QAAQY,IAAI,IAAI,CAAC,CAAC;QAAE;QAC9C,GAAIZ,QAAQa,aAAa,KAAKJ,YAC1B;YAAEI,eAAeZ,OAAOC,MAAM,CAAC;mBAAIF,QAAQa,aAAa;aAAC;QAAE,IAC3D,CAAC,CAAC;QACN,GAAIb,QAAQc,GAAG,KAAKL,YAAY;YAAEK,KAAKb,OAAOC,MAAM,CAAC;gBAAE,GAAGF,QAAQc,GAAG;YAAC;QAAG,IAAI,CAAC,CAAC;QAC/E,GAAId,QAAQe,MAAM,KAAKN,YAAY;YAAEM,QAAQd,OAAOC,MAAM,CAAC;gBAAE,GAAGF,QAAQe,MAAM;YAAC;QAAG,IAAI,CAAC,CAAC;IAC1F;AACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nest-batch/aws-batch",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "AWS Batch submit-job adapter for @nest-batch/core.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "easdkr",
|
|
7
|
+
"homepage": "https://github.com/easdkr/nest-batch/tree/main/packages/aws-batch#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/easdkr/nest-batch.git",
|
|
11
|
+
"directory": "packages/aws-batch"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/easdkr/nest-batch/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"nestjs",
|
|
18
|
+
"batch",
|
|
19
|
+
"aws",
|
|
20
|
+
"aws-batch"
|
|
21
|
+
],
|
|
22
|
+
"main": "dist/src/index.js",
|
|
23
|
+
"types": "dist/src/index.d.ts",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist/src",
|
|
26
|
+
"src",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@nestjs/common": "^10 || ^11",
|
|
34
|
+
"@nestjs/core": "^10 || ^11",
|
|
35
|
+
"@nest-batch/core": "^0.2.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@nestjs/common": "^11.0.0",
|
|
39
|
+
"@nestjs/core": "^11.0.0",
|
|
40
|
+
"@swc/cli": "^0.7.0",
|
|
41
|
+
"@swc/core": "^1.10.7",
|
|
42
|
+
"@types/node": "^22.0.0",
|
|
43
|
+
"reflect-metadata": "^0.2.2",
|
|
44
|
+
"typescript": "^5.5.0",
|
|
45
|
+
"vitest": "^2.0.0",
|
|
46
|
+
"@nest-batch/core": "0.2.0"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "swc src -d dist --config-file ../../.swcrc && tsc --emitDeclarationOnly -p tsconfig.build.json",
|
|
50
|
+
"test": "vitest run",
|
|
51
|
+
"test:watch": "vitest",
|
|
52
|
+
"typecheck": "tsc --noEmit"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Inject, Injectable } from '@nestjs/common';
|
|
2
|
+
import type {
|
|
3
|
+
ExternalTaskLauncher,
|
|
4
|
+
ExternalTaskLaunchRequest,
|
|
5
|
+
ExternalTaskLaunchResult,
|
|
6
|
+
} from '@nest-batch/core';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
AWS_BATCH_MODULE_OPTIONS,
|
|
10
|
+
type AwsBatchSubmitJobInput,
|
|
11
|
+
type ResolvedAwsBatchModuleOptions,
|
|
12
|
+
} from './module-options';
|
|
13
|
+
|
|
14
|
+
export const AWS_BATCH_STRATEGY_NAME = 'aws-batch';
|
|
15
|
+
|
|
16
|
+
@Injectable()
|
|
17
|
+
export class AwsBatchJobLauncher implements ExternalTaskLauncher {
|
|
18
|
+
readonly name = AWS_BATCH_STRATEGY_NAME;
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
@Inject(AWS_BATCH_MODULE_OPTIONS)
|
|
22
|
+
private readonly options: ResolvedAwsBatchModuleOptions,
|
|
23
|
+
) {}
|
|
24
|
+
|
|
25
|
+
async launch(request: ExternalTaskLaunchRequest): Promise<ExternalTaskLaunchResult> {
|
|
26
|
+
const input = this.buildSubmitJobInput(request);
|
|
27
|
+
const output = await this.options.client.submitJob(input);
|
|
28
|
+
if (output.jobId === undefined || output.jobId.length === 0) {
|
|
29
|
+
throw new Error('AWS Batch SubmitJob did not return a jobId');
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
provider: this.name,
|
|
33
|
+
externalId: output.jobId,
|
|
34
|
+
metadata: {
|
|
35
|
+
jobName: output.jobName ?? input.jobName,
|
|
36
|
+
jobQueue: this.options.jobQueue,
|
|
37
|
+
jobDefinition: this.options.jobDefinition,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
buildSubmitJobInput(request: ExternalTaskLaunchRequest): AwsBatchSubmitJobInput {
|
|
43
|
+
return {
|
|
44
|
+
jobName: this.buildJobName(request.jobExecutionId),
|
|
45
|
+
jobQueue: this.options.jobQueue,
|
|
46
|
+
jobDefinition: this.options.jobDefinition,
|
|
47
|
+
parameters: {
|
|
48
|
+
...this.options.parameters,
|
|
49
|
+
jobId: request.jobId,
|
|
50
|
+
jobExecutionId: request.jobExecutionId,
|
|
51
|
+
},
|
|
52
|
+
containerOverrides: {
|
|
53
|
+
command: [...request.workerArgs],
|
|
54
|
+
environment: Object.entries(request.env).map(([name, value]) => ({
|
|
55
|
+
name,
|
|
56
|
+
value,
|
|
57
|
+
})),
|
|
58
|
+
},
|
|
59
|
+
...(this.options.arrayProperties !== undefined
|
|
60
|
+
? { arrayProperties: this.options.arrayProperties }
|
|
61
|
+
: {}),
|
|
62
|
+
...(this.options.retryStrategy !== undefined
|
|
63
|
+
? { retryStrategy: this.options.retryStrategy }
|
|
64
|
+
: {}),
|
|
65
|
+
...(this.options.timeout !== undefined ? { timeout: this.options.timeout } : {}),
|
|
66
|
+
tags: {
|
|
67
|
+
...this.options.tags,
|
|
68
|
+
...request.labels,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private buildJobName(jobExecutionId: string): string {
|
|
74
|
+
const suffix = jobExecutionId.replace(/[^A-Za-z0-9_-]/g, '-');
|
|
75
|
+
return `${this.options.jobNamePrefix}-${suffix}`.slice(0, 128);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Module, type DynamicModule, type Provider } from '@nestjs/common';
|
|
2
|
+
import {
|
|
3
|
+
EXECUTION_STRATEGY,
|
|
4
|
+
EXTERNAL_TASK_LAUNCHER,
|
|
5
|
+
EXTERNAL_TASK_STRATEGY_OPTIONS,
|
|
6
|
+
ExternalTaskExecutionStrategy,
|
|
7
|
+
type BatchAdapter,
|
|
8
|
+
} from '@nest-batch/core';
|
|
9
|
+
|
|
10
|
+
import { AwsBatchJobLauncher } from './aws-batch-job-launcher';
|
|
11
|
+
import {
|
|
12
|
+
AWS_BATCH_MODULE_OPTIONS,
|
|
13
|
+
type AwsBatchModuleOptions,
|
|
14
|
+
type ResolvedAwsBatchModuleOptions,
|
|
15
|
+
resolveAwsBatchOptions,
|
|
16
|
+
} from './module-options';
|
|
17
|
+
|
|
18
|
+
@Module({})
|
|
19
|
+
export class AwsBatchModule {}
|
|
20
|
+
|
|
21
|
+
const ADAPTER_EXPORTS: ReadonlyArray<
|
|
22
|
+
symbol | typeof ExternalTaskExecutionStrategy | typeof AwsBatchJobLauncher
|
|
23
|
+
> = [
|
|
24
|
+
EXECUTION_STRATEGY,
|
|
25
|
+
EXTERNAL_TASK_LAUNCHER,
|
|
26
|
+
EXTERNAL_TASK_STRATEGY_OPTIONS,
|
|
27
|
+
AWS_BATCH_MODULE_OPTIONS,
|
|
28
|
+
ExternalTaskExecutionStrategy,
|
|
29
|
+
AwsBatchJobLauncher,
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
export class AwsBatchAdapter {
|
|
33
|
+
static forRoot(options: AwsBatchModuleOptions): BatchAdapter {
|
|
34
|
+
const resolved = resolveAwsBatchOptions(options);
|
|
35
|
+
return {
|
|
36
|
+
name: 'aws-batch',
|
|
37
|
+
module: buildAwsBatchDynamicModule({
|
|
38
|
+
providers: buildStaticProviders(resolved),
|
|
39
|
+
}),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function buildStaticProviders(resolved: ResolvedAwsBatchModuleOptions): Provider[] {
|
|
45
|
+
return [
|
|
46
|
+
AwsBatchJobLauncher,
|
|
47
|
+
ExternalTaskExecutionStrategy,
|
|
48
|
+
{
|
|
49
|
+
provide: EXECUTION_STRATEGY,
|
|
50
|
+
useExisting: ExternalTaskExecutionStrategy,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
provide: EXTERNAL_TASK_LAUNCHER,
|
|
54
|
+
useExisting: AwsBatchJobLauncher,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
provide: EXTERNAL_TASK_STRATEGY_OPTIONS,
|
|
58
|
+
useValue: {
|
|
59
|
+
workerCommand: resolved.workerCommand,
|
|
60
|
+
env: resolved.env,
|
|
61
|
+
labels: resolved.labels,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
provide: AWS_BATCH_MODULE_OPTIONS,
|
|
66
|
+
useValue: resolved,
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function buildAwsBatchDynamicModule(args: { providers: Provider[] }): DynamicModule {
|
|
72
|
+
return {
|
|
73
|
+
module: AwsBatchModule,
|
|
74
|
+
global: true,
|
|
75
|
+
providers: args.providers,
|
|
76
|
+
exports: [...ADAPTER_EXPORTS],
|
|
77
|
+
};
|
|
78
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ExternalTaskStrategyOptions } from '@nest-batch/core';
|
|
2
|
+
|
|
3
|
+
export const AWS_BATCH_MODULE_OPTIONS: symbol = Symbol.for(
|
|
4
|
+
'@nest-batch/aws-batch/AWS_BATCH_MODULE_OPTIONS',
|
|
5
|
+
);
|
|
6
|
+
|
|
7
|
+
export interface AwsBatchSubmitJobInput {
|
|
8
|
+
readonly jobName: string;
|
|
9
|
+
readonly jobQueue: string;
|
|
10
|
+
readonly jobDefinition: string;
|
|
11
|
+
readonly parameters?: Readonly<Record<string, string>>;
|
|
12
|
+
readonly containerOverrides?: {
|
|
13
|
+
readonly command?: readonly string[];
|
|
14
|
+
readonly environment?: readonly { readonly name: string; readonly value: string }[];
|
|
15
|
+
};
|
|
16
|
+
readonly arrayProperties?: { readonly size: number };
|
|
17
|
+
readonly retryStrategy?: { readonly attempts?: number };
|
|
18
|
+
readonly timeout?: { readonly attemptDurationSeconds?: number };
|
|
19
|
+
readonly tags?: Readonly<Record<string, string>>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface AwsBatchSubmitJobOutput {
|
|
23
|
+
readonly jobId?: string;
|
|
24
|
+
readonly jobName?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface AwsBatchSubmitJobClient {
|
|
28
|
+
submitJob(input: AwsBatchSubmitJobInput): Promise<AwsBatchSubmitJobOutput>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface AwsBatchModuleOptions extends ExternalTaskStrategyOptions {
|
|
32
|
+
readonly client: AwsBatchSubmitJobClient;
|
|
33
|
+
readonly jobQueue: string;
|
|
34
|
+
readonly jobDefinition: string;
|
|
35
|
+
readonly jobNamePrefix?: string;
|
|
36
|
+
readonly parameters?: Readonly<Record<string, string>>;
|
|
37
|
+
readonly arrayProperties?: { readonly size: number };
|
|
38
|
+
readonly retryStrategy?: { readonly attempts?: number };
|
|
39
|
+
readonly timeout?: { readonly attemptDurationSeconds?: number };
|
|
40
|
+
readonly tags?: Readonly<Record<string, string>>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ResolvedAwsBatchModuleOptions extends ExternalTaskStrategyOptions {
|
|
44
|
+
readonly client: AwsBatchSubmitJobClient;
|
|
45
|
+
readonly jobQueue: string;
|
|
46
|
+
readonly jobDefinition: string;
|
|
47
|
+
readonly jobNamePrefix: string;
|
|
48
|
+
readonly parameters: Readonly<Record<string, string>>;
|
|
49
|
+
readonly arrayProperties?: { readonly size: number };
|
|
50
|
+
readonly retryStrategy?: { readonly attempts?: number };
|
|
51
|
+
readonly timeout?: { readonly attemptDurationSeconds?: number };
|
|
52
|
+
readonly tags: Readonly<Record<string, string>>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function resolveAwsBatchOptions(
|
|
56
|
+
options: AwsBatchModuleOptions,
|
|
57
|
+
): ResolvedAwsBatchModuleOptions {
|
|
58
|
+
return Object.freeze({
|
|
59
|
+
client: options.client,
|
|
60
|
+
jobQueue: options.jobQueue,
|
|
61
|
+
jobDefinition: options.jobDefinition,
|
|
62
|
+
jobNamePrefix: options.jobNamePrefix ?? 'nest-batch',
|
|
63
|
+
parameters: Object.freeze({ ...(options.parameters ?? {}) }),
|
|
64
|
+
...(options.arrayProperties !== undefined
|
|
65
|
+
? { arrayProperties: Object.freeze({ ...options.arrayProperties }) }
|
|
66
|
+
: {}),
|
|
67
|
+
...(options.retryStrategy !== undefined
|
|
68
|
+
? { retryStrategy: Object.freeze({ ...options.retryStrategy }) }
|
|
69
|
+
: {}),
|
|
70
|
+
...(options.timeout !== undefined ? { timeout: Object.freeze({ ...options.timeout }) } : {}),
|
|
71
|
+
tags: Object.freeze({ ...(options.tags ?? {}) }),
|
|
72
|
+
...(options.workerCommand !== undefined
|
|
73
|
+
? { workerCommand: Object.freeze([...options.workerCommand]) }
|
|
74
|
+
: {}),
|
|
75
|
+
...(options.env !== undefined ? { env: Object.freeze({ ...options.env }) } : {}),
|
|
76
|
+
...(options.labels !== undefined ? { labels: Object.freeze({ ...options.labels }) } : {}),
|
|
77
|
+
});
|
|
78
|
+
}
|