Skip to content

Commit

Permalink
fix healthchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaGanzin committed Feb 4, 2023
1 parent 40af0c3 commit 754cb55
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion callmemaybe.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ program.command('start')
.catch(console.error)
})

return c.healthcheck ? healthcheck(c, question.name, opts, true) : wait(300)
return c.healthcheck ? healthcheck(c, question.name, 10, opts) : wait(300)
})
.then(async () => {
if(c.redirect) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "callmemaybe",
"version": "0.6.0",
"version": "0.7.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
30 changes: 16 additions & 14 deletions run.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,35 @@ const run = async (command, name, opts = {}) => {
return Promise.resolve(r)
}

const shell = String(opts.shell || 'bash')
const [shell, ...args] = String(opts.shell || 'bash -c').split(/\s+/)
opts.shell = false
delete opts.input
console.log(shell, opts)
// r = execa('"""'+command+'"""', [], opts)
r = execa(shell, ['-c', `"""${command}"""`], opts)
.then(console.log)
.catch(console.error)
console.log(shell, args)
r = execa(shell, concat(args, [command]), opts)
if (name) running[name] = r
r.stdout.pipe(process.stdout)
r.stderr.pipe(process.stderr)
// console.log({running})
return r
}

const healthcheck = (c, name, wait, opts) => {
const r = running[name]
if (r) return Promise.resolve()
const healthcheck = (c, name, retry, opts) => {
const r = running[name]
if (r)
return Promise.resolve()

if (c.healthcheck)
return run(c.healthcheck, `healthcheck ${name}`, opts)
.catch(e => {
if (wait) return healthcheck(c, name, wait)
throw e
})
if (!c.healthcheck)
return Promise.reject({})

return run(c.healthcheck, `healthcheck ${name}`, opts)
.catch(e => {
if (retry > 0) return wait(100)
.then(() => healthcheck(c, name, retry-1, opts))
throw e
})

return Promise.reject({})
}

const user2uid = user => execa(`id -u ${user}`)
Expand Down

0 comments on commit 754cb55

Please sign in to comment.