Skip to content

Commit f20339b

Browse files
authored
Merge pull request #19 from geekcell/long-running-tasks
Add new input "task-stopped-wait-for-max-attempts" to allow usage for…
2 parents 234f3c5 + 91a2778 commit f20339b

File tree

6 files changed

+110
-36
lines changed

6 files changed

+110
-36
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ Will pass the following command to the container on the AWS ECS Fargate task:
9595
| cluster | Which ECS cluster to start the task in. | `false` | |
9696
| override-container | Will use `containerOverrides` to run a custom command on the container. If provided, `override-container-command` must also be set. | `false` | |
9797
| override-container-command | The command to run on the container if `override-container` is passed. | `false` | |
98+
| override-container-environment | Add or override existing environment variables if `override-container` is passed. Provide one per line in key=value format. | `false` | |
9899
| tail-logs | If set to true, will try to extract the logConfiguration for the first container in the task definition. If `override-container` is passed, it will extract the logConfiguration from that container. Tailing logs is only possible if the provided container uses the `awslogs` logDriver. | `false` | true |
100+
| task-stopped-wait-for-max-attempts | How many times to check if the task is stopped before failing the action. The delay between each check is 6 seconds. | `false` | 100 |
99101
<!-- action-docs-inputs -->
100102

101103
<!-- action-docs-outputs -->

action.yml

+14
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,47 @@ inputs:
1111
description: >-
1212
The name or the ARN of the task definition to use for the task.
1313
required: true
14+
1415
subnet-ids:
1516
description: >-
1617
The list of subnet IDs for the task to use. If multiple they should be passed as multiline argument
1718
with one subnet ID per line.
1819
required: true
20+
1921
security-group-ids:
2022
description: >-
2123
List of security group IDs for the task. If multiple they should be passed as multiline argument
2224
with one subnet ID per line.
2325
required: true
26+
2427
assign-public-ip:
2528
description: >-
2629
Assign public a IP to the task.
2730
Options: `['ENABLED', 'DISABLED']`
2831
required: false
2932
default: DISABLED
33+
3034
cluster:
3135
description: >-
3236
Which ECS cluster to start the task in.
3337
required: false
38+
3439
override-container:
3540
description: >-
3641
Will use `containerOverrides` to run a custom command on the container. If provided, `override-container-command`
3742
must also be set.
3843
required: false
44+
3945
override-container-command:
4046
description: >-
4147
The command to run on the container if `override-container` is passed.
4248
required: false
49+
4350
override-container-environment:
4451
description: >-
4552
Add or override existing environment variables if `override-container` is passed. Provide one per line in key=value format.
4653
required: false
54+
4755
tail-logs:
4856
description: >-
4957
If set to true, will try to extract the logConfiguration for the first container in the task definition. If
@@ -52,6 +60,12 @@ inputs:
5260
required: false
5361
default: 'true'
5462

63+
task-stopped-wait-for-max-attempts:
64+
description: >-
65+
How many times to check if the task is stopped before failing the action. The delay between each check is 6 seconds.
66+
required: false
67+
default: 100
68+
5569
outputs:
5670
task-arn:
5771
description: 'The full ARN for the task that was ran.'

dist/index.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -50316,6 +50316,7 @@ const main = async () => {
5031650316
const overrideContainer = core.getInput('override-container', {required: false});
5031750317
const overrideContainerCommand = core.getMultilineInput('override-container-command', {required: false});
5031850318
const overrideContainerEnvironment = core.getMultilineInput('override-container-environment', {required: false});
50319+
const taskStoppedWaitForMaxAttempts = parseInt(core.getInput('task-stopped-wait-for-max-attempts', {required: false}));
5031950320

5032050321
// Build Task parameters
5032150322
const taskRequestParams = {
@@ -50351,7 +50352,7 @@ const main = async () => {
5035150352
// Check if not the last item in array
5035250353
if (arr.length - 1 !== i) {
5035350354
// Prepend the current item to the next item and set current item to null
50354-
arr[i+1] = arr[i] + arr[i+1]
50355+
arr[i + 1] = arr[i] + arr[i + 1]
5035550356
arr[i] = null
5035650357
}
5035750358
}
@@ -50364,10 +50365,10 @@ const main = async () => {
5036450365
overrides.command = parsedCommand
5036550366
}
5036650367

50367-
if(overrideContainerEnvironment.length) {
50368+
if (overrideContainerEnvironment.length) {
5036850369
core.debug(`overrideContainer and overrideContainerEnvironment has been specified. Overriding.`);
5036950370
overrides.environment = overrideContainerEnvironment.map(x => {
50370-
const parts= x.split(/=(.*)/)
50371+
const parts = x.split(/=(.*)/)
5037150372
return {
5037250373
name: parts[0],
5037350374
value: parts[1]
@@ -50450,7 +50451,11 @@ const main = async () => {
5045050451

5045150452
// Wait for Task to finish
5045250453
core.debug(`Waiting for task to finish.`);
50453-
await ecs.waitFor('tasksStopped', {cluster, tasks: [taskArn]}).promise();
50454+
await ecs.waitFor('tasksStopped', {
50455+
cluster,
50456+
tasks: [taskArn],
50457+
$waiter: {delay: 6, maxAttempts: taskStoppedWaitForMaxAttempts}}
50458+
).promise();
5045450459

5045550460
// Close LogStream and store output
5045650461
if (logFilterStream !== null) {

index.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const main = async () => {
2121
const overrideContainer = core.getInput('override-container', {required: false});
2222
const overrideContainerCommand = core.getMultilineInput('override-container-command', {required: false});
2323
const overrideContainerEnvironment = core.getMultilineInput('override-container-environment', {required: false});
24+
const taskStoppedWaitForMaxAttempts = parseInt(core.getInput('task-stopped-wait-for-max-attempts', {required: false}));
2425

2526
// Build Task parameters
2627
const taskRequestParams = {
@@ -56,7 +57,7 @@ const main = async () => {
5657
// Check if not the last item in array
5758
if (arr.length - 1 !== i) {
5859
// Prepend the current item to the next item and set current item to null
59-
arr[i+1] = arr[i] + arr[i+1]
60+
arr[i + 1] = arr[i] + arr[i + 1]
6061
arr[i] = null
6162
}
6263
}
@@ -69,10 +70,10 @@ const main = async () => {
6970
overrides.command = parsedCommand
7071
}
7172

72-
if(overrideContainerEnvironment.length) {
73+
if (overrideContainerEnvironment.length) {
7374
core.debug(`overrideContainer and overrideContainerEnvironment has been specified. Overriding.`);
7475
overrides.environment = overrideContainerEnvironment.map(x => {
75-
const parts= x.split(/=(.*)/)
76+
const parts = x.split(/=(.*)/)
7677
return {
7778
name: parts[0],
7879
value: parts[1]
@@ -155,7 +156,11 @@ const main = async () => {
155156

156157
// Wait for Task to finish
157158
core.debug(`Waiting for task to finish.`);
158-
await ecs.waitFor('tasksStopped', {cluster, tasks: [taskArn]}).promise();
159+
await ecs.waitFor('tasksStopped', {
160+
cluster,
161+
tasks: [taskArn],
162+
$waiter: {delay: 6, maxAttempts: taskStoppedWaitForMaxAttempts}}
163+
).promise();
159164

160165
// Close LogStream and store output
161166
if (logFilterStream !== null) {

package-lock.json

+74-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"lint": "eslint **.js",
88
"build": "ncc build index.js -o dist",
9+
"update-readme": "action-docs -u",
910
"test": "eslint **.js && jest --coverage"
1011
},
1112
"repository": {
@@ -29,6 +30,7 @@
2930
},
3031
"devDependencies": {
3132
"@vercel/ncc": "^0.34.0",
33+
"action-docs": "^1.2.0",
3234
"eslint": "^8.26.0",
3335
"jest": "^29.2.2"
3436
}

0 commit comments

Comments
 (0)