Skip to content

Commit

Permalink
refactor: update display message
Browse files Browse the repository at this point in the history
  • Loading branch information
fredliang44 committed Jul 14, 2021
1 parent 91f142c commit e392fc3
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
const core = require('@actions/core');
const github = require('@actions/github');
const fetch = require('node-fetch');
let round = 1;

try {

var result = fetchDeploymentResult();
core.setOutput("result", result);
console.log(`finshed check up deploy result: ${result}.`);

fetchDeploymentResult();
} catch (error) {
core.setFailed(error.message);
}
Expand All @@ -17,7 +14,7 @@ function fetchDeploymentResult() {
const nomadToken = core.getInput('nomad-token');
const nomadJobName = core.getInput('nomad-job-name');
const nomadNamespace = core.getInput('nomad-namespace');

fetch(`${nomadEndpoint}/v1/job/${nomadJobName}/deployment?namespace=${nomadNamespace}&index=1`, {
"headers": {
"accept": "*/*",
Expand All @@ -36,18 +33,26 @@ function fetchDeploymentResult() {
.then(res => res.json())
.then((jsonData) => {
result = jsonData.Status
console.log(jsonData.Status)

if (result === "failed") {
console.log("deployment description:", jsonData.StatusDescription);
core.setFailed(jsonData.StatusDescription);
return result
}
else if (result === "successful") {
core.setOutput("result", result);
console.log("deployment description:", jsonData.StatusDescription);
console.log(`finshed check up deploy result: ${result}.`);

return result
} else {
var waitTill = new Date(new Date().getTime() + 4 * 1000);
while(waitTill > new Date()){}
while (waitTill > new Date()) { }

console.log(jsonData.Status, ", round:", round)
// add round counter
round += 1

fetchDeploymentResult()
}
})
Expand Down

0 comments on commit e392fc3

Please sign in to comment.