Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give up checking after a while #56

Merged
merged 2 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [Unreleased](https://github.com/dotenv-org/dotenv-vault/compare/v1.5.0...master)
## [Unreleased](https://github.com/dotenv-org/dotenv-vault/compare/v1.5.1...master)

## 1.5.1

### Added

- Time out check on `new` and `login` after a couple minutes 🧹([#56](https://github.com/dotenv-org/dotenv-vault/pull/56))

## 1.5.0

Expand Down
8 changes: 7 additions & 1 deletion src/services/login-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class LoginService {
public requestUid;
public controller;
public abort;
public checkCount;

constructor(attrs: LoginServiceAttrs = {} as LoginServiceAttrs) {
this.cmd = attrs.cmd
Expand All @@ -28,6 +29,7 @@ class LoginService {

const rand = crypto.randomBytes(32).toString('hex')
this.requestUid = `req_${rand}`
this.checkCount = 0
}

async run(): Promise<void> {
Expand Down Expand Up @@ -72,6 +74,7 @@ class LoginService {

let resp
try {
this.checkCount += 1
resp = await axios(options)
} catch (error: any) {
resp = error.response
Expand All @@ -86,10 +89,13 @@ class LoginService {
this.log.plain('')
this.log.plain(`Next run ${chalk.bold('npx dotenv-vault@latest pull')} or ${chalk.bold('npx dotenv-vault@latest push')}`)
}
} else {
} else if (this.checkCount < 50) {
// 404 - keep trying
await CliUx.ux.wait(2000) // check every 2 seconds
await this.check(tip) // check again
} else {
CliUx.ux.action.stop('giving up')
this.log.local('Things were taking too long... gave up. Please try again.')
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/services/new-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class NewService {
public requestUid;
public controller;
public abort;
public checkCount;

constructor(attrs: NewServiceAttrs = {} as NewServiceAttrs) {
this.cmd = attrs.cmd
Expand All @@ -31,6 +32,7 @@ class NewService {

const rand = crypto.randomBytes(32).toString('hex')
this.requestUid = `req_${rand}`
this.checkCount = 0
}

async run(): Promise<void> {
Expand Down Expand Up @@ -88,6 +90,7 @@ class NewService {

let resp
try {
this.checkCount += 1
resp = await axios(options)
} catch (error: any) {
resp = error.response
Expand All @@ -100,10 +103,13 @@ class NewService {
this.log.local(`Added to ${vars.vaultFilename} (${vars.vaultKey}=${vaultUid.slice(0, 9)}...)`)
this.log.plain('')
this.log.plain(`Next run ${chalk.bold('npx dotenv-vault@latest login')}`)
} else {
} else if (this.checkCount < 50) {
// 404 - keep trying
await CliUx.ux.wait(2000) // check every 2 seconds
await this.check() // check again
} else {
CliUx.ux.action.stop('giving up')
this.log.local('Things were taking too long... gave up. Please try again.')
}
}
}
Expand Down