Skip to content

Commit

Permalink
Merge pull request #19 from geekcell/long-running-tasks
Browse files Browse the repository at this point in the history
Add new input "task-stopped-wait-for-max-attempts" to allow usage for…
  • Loading branch information
Ic3w0lf authored Dec 4, 2023
2 parents 234f3c5 + 91a2778 commit f20339b
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 36 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ Will pass the following command to the container on the AWS ECS Fargate task:
| cluster | Which ECS cluster to start the task in. | `false` | |
| override-container | Will use `containerOverrides` to run a custom command on the container. If provided, `override-container-command` must also be set. | `false` | |
| override-container-command | The command to run on the container if `override-container` is passed. | `false` | |
| override-container-environment | Add or override existing environment variables if `override-container` is passed. Provide one per line in key=value format. | `false` | |
| 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 |
| 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 |
<!-- action-docs-inputs -->

<!-- action-docs-outputs -->
Expand Down
14 changes: 14 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,47 @@ inputs:
description: >-
The name or the ARN of the task definition to use for the task.
required: true

subnet-ids:
description: >-
The list of subnet IDs for the task to use. If multiple they should be passed as multiline argument
with one subnet ID per line.
required: true

security-group-ids:
description: >-
List of security group IDs for the task. If multiple they should be passed as multiline argument
with one subnet ID per line.
required: true

assign-public-ip:
description: >-
Assign public a IP to the task.
Options: `['ENABLED', 'DISABLED']`
required: false
default: DISABLED

cluster:
description: >-
Which ECS cluster to start the task in.
required: false

override-container:
description: >-
Will use `containerOverrides` to run a custom command on the container. If provided, `override-container-command`
must also be set.
required: false

override-container-command:
description: >-
The command to run on the container if `override-container` is passed.
required: false

override-container-environment:
description: >-
Add or override existing environment variables if `override-container` is passed. Provide one per line in key=value format.
required: false

tail-logs:
description: >-
If set to true, will try to extract the logConfiguration for the first container in the task definition. If
Expand All @@ -52,6 +60,12 @@ inputs:
required: false
default: 'true'

task-stopped-wait-for-max-attempts:
description: >-
How many times to check if the task is stopped before failing the action. The delay between each check is 6 seconds.
required: false
default: 100

outputs:
task-arn:
description: 'The full ARN for the task that was ran.'
Expand Down
13 changes: 9 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50316,6 +50316,7 @@ const main = async () => {
const overrideContainer = core.getInput('override-container', {required: false});
const overrideContainerCommand = core.getMultilineInput('override-container-command', {required: false});
const overrideContainerEnvironment = core.getMultilineInput('override-container-environment', {required: false});
const taskStoppedWaitForMaxAttempts = parseInt(core.getInput('task-stopped-wait-for-max-attempts', {required: false}));

// Build Task parameters
const taskRequestParams = {
Expand Down Expand Up @@ -50351,7 +50352,7 @@ const main = async () => {
// Check if not the last item in array
if (arr.length - 1 !== i) {
// Prepend the current item to the next item and set current item to null
arr[i+1] = arr[i] + arr[i+1]
arr[i + 1] = arr[i] + arr[i + 1]
arr[i] = null
}
}
Expand All @@ -50364,10 +50365,10 @@ const main = async () => {
overrides.command = parsedCommand
}

if(overrideContainerEnvironment.length) {
if (overrideContainerEnvironment.length) {
core.debug(`overrideContainer and overrideContainerEnvironment has been specified. Overriding.`);
overrides.environment = overrideContainerEnvironment.map(x => {
const parts= x.split(/=(.*)/)
const parts = x.split(/=(.*)/)
return {
name: parts[0],
value: parts[1]
Expand Down Expand Up @@ -50450,7 +50451,11 @@ const main = async () => {

// Wait for Task to finish
core.debug(`Waiting for task to finish.`);
await ecs.waitFor('tasksStopped', {cluster, tasks: [taskArn]}).promise();
await ecs.waitFor('tasksStopped', {
cluster,
tasks: [taskArn],
$waiter: {delay: 6, maxAttempts: taskStoppedWaitForMaxAttempts}}
).promise();

// Close LogStream and store output
if (logFilterStream !== null) {
Expand Down
13 changes: 9 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const main = async () => {
const overrideContainer = core.getInput('override-container', {required: false});
const overrideContainerCommand = core.getMultilineInput('override-container-command', {required: false});
const overrideContainerEnvironment = core.getMultilineInput('override-container-environment', {required: false});
const taskStoppedWaitForMaxAttempts = parseInt(core.getInput('task-stopped-wait-for-max-attempts', {required: false}));

// Build Task parameters
const taskRequestParams = {
Expand Down Expand Up @@ -56,7 +57,7 @@ const main = async () => {
// Check if not the last item in array
if (arr.length - 1 !== i) {
// Prepend the current item to the next item and set current item to null
arr[i+1] = arr[i] + arr[i+1]
arr[i + 1] = arr[i] + arr[i + 1]
arr[i] = null
}
}
Expand All @@ -69,10 +70,10 @@ const main = async () => {
overrides.command = parsedCommand
}

if(overrideContainerEnvironment.length) {
if (overrideContainerEnvironment.length) {
core.debug(`overrideContainer and overrideContainerEnvironment has been specified. Overriding.`);
overrides.environment = overrideContainerEnvironment.map(x => {
const parts= x.split(/=(.*)/)
const parts = x.split(/=(.*)/)
return {
name: parts[0],
value: parts[1]
Expand Down Expand Up @@ -155,7 +156,11 @@ const main = async () => {

// Wait for Task to finish
core.debug(`Waiting for task to finish.`);
await ecs.waitFor('tasksStopped', {cluster, tasks: [taskArn]}).promise();
await ecs.waitFor('tasksStopped', {
cluster,
tasks: [taskArn],
$waiter: {delay: 6, maxAttempts: taskStoppedWaitForMaxAttempts}}
).promise();

// Close LogStream and store output
if (logFilterStream !== null) {
Expand Down
102 changes: 74 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"lint": "eslint **.js",
"build": "ncc build index.js -o dist",
"update-readme": "action-docs -u",
"test": "eslint **.js && jest --coverage"
},
"repository": {
Expand All @@ -29,6 +30,7 @@
},
"devDependencies": {
"@vercel/ncc": "^0.34.0",
"action-docs": "^1.2.0",
"eslint": "^8.26.0",
"jest": "^29.2.2"
}
Expand Down

0 comments on commit f20339b

Please sign in to comment.