Skip to content

Commit 95bb1f2

Browse files
committed
feat: use faster list machines call
Fly added a new API that is faster to do list machines by providing us a summary. Signed-off-by: Chris Goller <goller@gmail.com>
1 parent fb3f42d commit 95bb1f2

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/utils/fly/client.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ import {FLY_API_HOST, FLY_API_TOKEN, FLY_APP_ID} from '../env'
55
const authorizationHeader = `Bearer ${FLY_API_TOKEN}`
66

77
export async function listMachines(): Promise<V1Machine[]> {
8-
const res = await rest<V1Machine[]>('GET', '/machines?include_deleted=true')
9-
return res
8+
const res = await rest<MachineSummary[]>('GET', '/machines?include_deleted=true&summary=true')
9+
return res.map((m) => {
10+
return {
11+
config: m.incomplete_config,
12+
...m,
13+
}
14+
})
1015
}
1116

1217
export async function listVolumes(): Promise<Volume[]> {
@@ -239,6 +244,29 @@ export interface V1Machine {
239244
worker_status?: string
240245
}
241246

247+
// This type was added by fly to give us a faster version of list machines.
248+
export interface MachineSummary {
249+
id: string
250+
name: string
251+
state: MachineState
252+
region: string
253+
image_ref: {
254+
registry: string
255+
repository: string
256+
tag: string
257+
digest: string
258+
}
259+
instance_id: string
260+
private_ip: string
261+
created_at: string
262+
updated_at: string
263+
incomplete_config: MachineConfig
264+
checks?: CheckStatus[]
265+
events?: Event[]
266+
nonce?: string
267+
worker_status?: string
268+
}
269+
242270
export interface CheckStatus {
243271
name: string
244272
output: string

0 commit comments

Comments
 (0)