From d756fdeac9b313b41be2b9ebabe0c70e67f2367b Mon Sep 17 00:00:00 2001 From: Wil Wilsman Date: Wed, 30 Sep 2020 18:20:22 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Wait=20for=20healthcheck=20to=20?= =?UTF-8?q?fail=20for=20exec:stop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/cli-exec/src/commands/exec/stop.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/cli-exec/src/commands/exec/stop.js b/packages/cli-exec/src/commands/exec/stop.js index ca961df06..131cf6290 100644 --- a/packages/cli-exec/src/commands/exec/stop.js +++ b/packages/cli-exec/src/commands/exec/stop.js @@ -12,19 +12,27 @@ export class Stop extends Command { }; async run() { + let { port } = this.flags; + if (!this.isPercyEnabled()) { log.info('Percy is disabled'); return; } try { - let { port } = this.flags; await request(`http://localhost:${port}/percy/stop`, { method: 'POST' }); - log.info('Percy has stopped'); } catch (err) { log.error('Percy is not running'); log.debug(err); this.exit(1); } + + // retry heathcheck until it fails + await new Promise(function check(resolve) { + return request(`http://localhost:${port}/percy/healthcheck`, { method: 'GET' }) + .then(() => setTimeout(check, 100, resolve)).catch(resolve); + }); + + log.info('Percy has stopped'); } }