toes start/stop/restart feedback
This commit is contained in:
parent
ecac19a07f
commit
75af5f3d31
|
|
@ -16,6 +16,24 @@ export const STATE_ICONS: Record<string, string> = {
|
|||
invalid: color.red('◌'),
|
||||
}
|
||||
|
||||
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
|
||||
|
||||
async function waitForState(name: string, target: string, timeout: number): Promise<string | undefined> {
|
||||
const start = Date.now()
|
||||
while (Date.now() - start < timeout) {
|
||||
await sleep(500)
|
||||
const app: App | undefined = await get(`/api/apps/${name}`)
|
||||
if (!app) return undefined
|
||||
if (app.state === target) return target
|
||||
// Terminal failure states — stop polling
|
||||
if (target === 'running' && (app.state === 'stopped' || app.state === 'invalid')) return app.state
|
||||
if (target === 'stopped' && app.state === 'invalid') return app.state
|
||||
}
|
||||
// Timed out — return last known state
|
||||
const app: App | undefined = await get(`/api/apps/${name}`)
|
||||
return app?.state
|
||||
}
|
||||
|
||||
export async function configShow() {
|
||||
console.log(`Host: ${color.bold(HOST)}`)
|
||||
|
||||
|
|
@ -232,7 +250,15 @@ export async function renameApp(arg: string | undefined, newName: string) {
|
|||
export async function restartApp(arg?: string) {
|
||||
const name = resolveAppName(arg)
|
||||
if (!name) return
|
||||
await post(`/api/apps/${name}/restart`)
|
||||
const result = await post(`/api/apps/${name}/restart`)
|
||||
if (!result) return
|
||||
process.stdout.write(`${color.yellow('↻')} Restarting ${color.bold(name)}...`)
|
||||
const state = await waitForState(name, 'running', 15000)
|
||||
if (state === 'running') {
|
||||
console.log(` ${color.green('running')}`)
|
||||
} else {
|
||||
console.log(` ${color.red(state ?? 'unknown')}`)
|
||||
}
|
||||
}
|
||||
|
||||
export async function rmApp(arg?: string) {
|
||||
|
|
@ -264,11 +290,28 @@ export async function rmApp(arg?: string) {
|
|||
export async function startApp(arg?: string) {
|
||||
const name = resolveAppName(arg)
|
||||
if (!name) return
|
||||
await post(`/api/apps/${name}/start`)
|
||||
const result = await post(`/api/apps/${name}/start`)
|
||||
if (!result) return
|
||||
process.stdout.write(`${color.green('▶')} Starting ${color.bold(name)}...`)
|
||||
const state = await waitForState(name, 'running', 15000)
|
||||
if (state === 'running') {
|
||||
console.log(` ${color.green('running')}`)
|
||||
} else {
|
||||
console.log(` ${color.red(state ?? 'unknown')}`)
|
||||
}
|
||||
}
|
||||
|
||||
export async function stopApp(arg?: string) {
|
||||
const name = resolveAppName(arg)
|
||||
if (!name) return
|
||||
await post(`/api/apps/${name}/stop`)
|
||||
const result = await post(`/api/apps/${name}/stop`)
|
||||
if (!result) return
|
||||
process.stdout.write(`${color.red('■')} Stopping ${color.bold(name)}...`)
|
||||
const state = await waitForState(name, 'stopped', 10000)
|
||||
if (state === 'stopped') {
|
||||
console.log(` ${color.gray('stopped')}`)
|
||||
} else {
|
||||
console.log(` ${color.yellow(state ?? 'unknown')}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user