Skip to content

Commit

Permalink
feat(heartbeat): print pingUrl in the console after deploy for hear…
Browse files Browse the repository at this point in the history
…tbeat checks [sc-17085]
  • Loading branch information
shiini2 committed Aug 8, 2023
1 parent 25a7080 commit 75d2eaf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ export default class Deploy extends AuthCommand {
if (!preview) {
await ux.wait(500)
this.log(`Successfully deployed project "${project.name}" to account "${account.name}".`)

// Print the ping URL for heartbeat checks.
data.diff.forEach(async (check) => {
if (check.checkId) {
const { data: { pingUrl, name } } = await api.heartbeatCheck.get(check.checkId)
this.log(`The ping URL for the heartbeat check ${chalk.greenBright(name)} is available at ${chalk.italic.underline.cyanBright(pingUrl)}.`)
}
})
}
} catch (err: any) {
if (err?.response?.status === 400) {
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/rest/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import PrivateLocations from './private-locations'
import Locations from './locations'
import TestSessions from './test-sessions'
import EnvironmentVariables from './environment-variables'
import HeartbeatChecks from './heartbeat-checks'

export function getDefaults () {
const apiKey = config.getApiKey()
Expand Down Expand Up @@ -76,3 +77,4 @@ export const locations = new Locations(api)
export const privateLocations = new PrivateLocations(api)
export const testSessions = new TestSessions(api)
export const environmentVariables = new EnvironmentVariables(api)
export const heartbeatCheck = new HeartbeatChecks(api)
24 changes: 24 additions & 0 deletions packages/cli/src/rest/heartbeat-checks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { AxiosInstance } from 'axios'

export interface HeartbeatCheck {
pingUrl: string
name: string
}

class HeartbeatChecks {
api: AxiosInstance
constructor (api: AxiosInstance) {
this.api = api
}

get (id: string) {
return this.api.get<HeartbeatCheck>(`/v1/checks/${id}`, {
transformResponse: (data: any) => {
const { heartbeat: { pingUrl }, name } = JSON.parse(data)
return { pingUrl, name }
},
})
}
}

export default HeartbeatChecks
1 change: 1 addition & 0 deletions packages/cli/src/rest/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ProjectResponse = Project & { id: string, created_at: string }
export interface Change {
logicalId: string,
physicalId?: string,
checkId?: string,
type: string,
action: string
}
Expand Down

0 comments on commit 75d2eaf

Please sign in to comment.