Skip to content

Commit

Permalink
Merge pull request #145 from livecycle/fix-retry-urls-in-app
Browse files Browse the repository at this point in the history
fix: tunnels query retry in up
  • Loading branch information
Roy Razon authored Jul 26, 2023
2 parents 097da0e + ac33e15 commit 7f66448
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions packages/cli/src/commands/up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
telemetryEmitter,
} from '@preevy/core'
import { tunnelServerFlags } from '@preevy/cli-common'
import { inspect } from 'util'
import { tunnelServerHello } from '../tunnel-server-client'
import MachineCreationDriverCommand from '../machine-creation-driver-command'
import { envIdFlags, urlFlags } from '../common-flags'
Expand Down Expand Up @@ -90,6 +91,12 @@ export default class Up extends MachineCreationDriverCommand<typeof Up> {
envId,
tunnelingKey,
includeAccessCredentials: flags['include-access-credentials'],
retryOpts: {
minTimeout: 1000,
maxTimeout: 2000,
retries: 10,
onFailedAttempt: e => { this.logger.debug(`Failed to query tunnels: ${inspect(e)}`) },
},
})

const urls = await filterUrls({
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export default class Urls extends ProfileCommand<typeof Urls> {
serviceAndPort: args.service ? { service: args.service, port: args.port } : undefined,
tunnelingKey,
includeAccessCredentials: flags['include-access-credentials'],
retryOpts: { retries: 2 },
})

const urls = await filterUrls({
Expand Down
14 changes: 12 additions & 2 deletions packages/core/src/commands/urls.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
import retry from 'p-retry'
import { generateBasicAuthCredentials, jwtGenerator } from '../credentials'
import { queryTunnels } from '../compose-tunnel-agent-client'
import { flattenTunnels, tunnelUrlsForEnv } from '../tunneling'

export const urls = async ({ envId, rootUrl, clientId, serviceAndPort, tunnelingKey, includeAccessCredentials }: {
export const urls = async ({
envId,
rootUrl,
clientId,
serviceAndPort,
tunnelingKey,
includeAccessCredentials,
retryOpts,
}: {
envId: string
rootUrl: string
clientId: string
serviceAndPort?: { service: string; port?: number }
tunnelingKey: string | Buffer
includeAccessCredentials: boolean
retryOpts: retry.Options
}) => {
const tunnelUrlsForService = tunnelUrlsForEnv({ envId, rootUrl: new URL(rootUrl), clientId })

const credentials = await generateBasicAuthCredentials(jwtGenerator(tunnelingKey))

const { tunnels } = await queryTunnels({
tunnelUrlsForService,
retryOpts: { retries: 2 },
retryOpts,
credentials,
includeAccessCredentials,
})
Expand Down

0 comments on commit 7f66448

Please sign in to comment.