Skip to content

Commit

Permalink
fix: Don't check if the service is running to stop Percy (#581)
Browse files Browse the repository at this point in the history
This approach assumes running `percy stop` will happen in the same session. The
better approach is to send the POST request anyways & catch if it fails. That
way if the server is running (on that path/port) it will get stopped.
  • Loading branch information
Robdel12 authored Nov 18, 2020
1 parent 95dade8 commit 609ad5e
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/commands/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@ export default class Stop extends PercyCommand {
const { flags } = this.parse(Stop)
const configuration = config(flags)

if (this.processService.isRunning()) {
await this.postToRunningAgent(STOP_PATH, configuration.agent.port)
} else {
this.logger.warn('percy is already stopped.')
}
await this.postToRunningAgent(STOP_PATH, configuration.agent.port)
}

private async postToRunningAgent(path: string, port: number) {
await Axios(`http://localhost:${port}${path}`, { method: 'POST' })
.catch((error: any) => {
if (error.message === 'socket hang up') { // We expect a hangup
this.logger.info('percy stopped.')
} else if (error.code === 'ECONNREFUSED') {
this.logger.info('percy is already stopped.')
} else {
logError(error)
}
Expand Down

0 comments on commit 609ad5e

Please sign in to comment.