Skip to content

Commit 249654d

Browse files
ltkmhanberg
andauthored
Update how release health is determined (#17)
* Prefer Number() to parseInt(). Resolves #7 * Fix issue where action stalls for apps using >1 replica. Fixes #12 * Bump version to 0.4.0, update changelog * Update CHANGELOG.md per PR suggestion Co-authored-by: Mitchell Hanberg <mitch@mitchellhanberg.com> Co-authored-by: Mitchell Hanberg <mitch@mitchellhanberg.com>
1 parent 81e866e commit 249654d

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## v0.4.0
4+
5+
- Fixed an issue where the action would get stuck at 'Getting current replicas' for apps requesting more than one replica
6+
- Does a health check every 10 seconds instead of increasing the wait time exponentially. Times out now after 10 minutes.
7+
38
## v0.3.0
49

510
- Only add private key and wait for deploy if we are migrating [(#9)](https://github.com/mhanberg/gigalixir-action/pull/9)

dist/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -975,20 +975,20 @@ async function isNextReleaseHealthy(release, app) {
975975
await exec.exec(`gigalixir ps -a ${app}`, [], options);
976976
});
977977

978-
const pods = JSON.parse(releasesOutput).pods;
979-
const pod = pods[0];
980-
981-
return pods.length === 1 && parseInt(pod.version) === release && pod.status === "Healthy";
978+
const releases = JSON.parse(releasesOutput);
979+
const pods = releases.pods;
980+
return releases.pods.filter((pod) => (Number(pod.version) === release && pod.status === "Healthy")).length >= releases.replicas_desired;
982981
}
983982

984-
async function waitForNewRelease(oldRelease, app, multiplier) {
983+
async function waitForNewRelease(oldRelease, app, attempts) {
984+
const maxAttempts = 60;
985+
985986
if (await isNextReleaseHealthy(oldRelease + 1, app)) {
986987
return await Promise.resolve(true);
987988
} else {
988-
if (multiplier <= 10) {
989-
await wait(Math.pow(2, multiplier));
990-
991-
await waitForNewRelease(oldRelease, app, multiplier + 1);
989+
if (attempts <= maxAttempts) {
990+
await wait(10);
991+
await waitForNewRelease(oldRelease, app, attempts + 1);
992992
} else {
993993
throw "Taking too long for new release to deploy";
994994
}
@@ -1010,7 +1010,7 @@ async function getCurrentRelease(app) {
10101010
await exec.exec(`gigalixir releases -a ${app}`, [], options);
10111011
});
10121012

1013-
const currentRelease = parseInt(JSON.parse(releasesOutput)[0].version);
1013+
const currentRelease = Number(JSON.parse(releasesOutput)[0].version);
10141014

10151015
return currentRelease;
10161016
}

index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ async function isNextReleaseHealthy(release, app) {
2929
await exec.exec(`gigalixir ps -a ${app}`, [], options);
3030
});
3131

32-
const pods = JSON.parse(releasesOutput).pods;
33-
const pod = pods[0];
34-
35-
return pods.length === 1 && parseInt(pod.version) === release && pod.status === "Healthy";
32+
const releases = JSON.parse(releasesOutput);
33+
const pods = releases.pods;
34+
return releases.pods.filter((pod) => (Number(pod.version) === release && pod.status === "Healthy")).length >= releases.replicas_desired;
3635
}
3736

38-
async function waitForNewRelease(oldRelease, app, multiplier) {
37+
async function waitForNewRelease(oldRelease, app, attempts) {
38+
const maxAttempts = 60;
39+
3940
if (await isNextReleaseHealthy(oldRelease + 1, app)) {
4041
return await Promise.resolve(true);
4142
} else {
42-
if (multiplier <= 10) {
43-
await wait(Math.pow(2, multiplier));
44-
45-
await waitForNewRelease(oldRelease, app, multiplier + 1);
43+
if (attempts <= maxAttempts) {
44+
await wait(10);
45+
await waitForNewRelease(oldRelease, app, attempts + 1);
4646
} else {
4747
throw "Taking too long for new release to deploy";
4848
}
@@ -64,7 +64,7 @@ async function getCurrentRelease(app) {
6464
await exec.exec(`gigalixir releases -a ${app}`, [], options);
6565
});
6666

67-
const currentRelease = parseInt(JSON.parse(releasesOutput)[0].version);
67+
const currentRelease = Number(JSON.parse(releasesOutput)[0].version);
6868

6969
return currentRelease;
7070
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gigalixir-action",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "Action to deploy to gigalixir",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)