import * as chalk from 'chalk'; import {command, help, namespace, option, param} from 'oo-cli'; import {die} from '../../lib/die'; import {formatError} from '../../lib/formatError'; import {formatJobStatus} from '../../lib/formatJobStatus'; import {timestampToDurationString} from '../../lib/formatTimstamp'; import { jobRuntime } from '../../lib/jobRuntime'; import {Rivendell} from '../../lib/Rivendell'; @namespace('jobs') export class RuntimeStatusCommand { @param @help('ID of Job to get the runtime status for') private jobId!: string; @option('a') @help('The availability zone that will be targeted (default: us)') private availability: string = ''; @command @help('Show the runtime status of a job') public async runtimeStatus(): Promise { try { const job = await Rivendell.fetchJob(this.jobId, this.availability); const status = await Rivendell.fetchJobRuntimeStatus(this.jobId, this.availability); if (status.status) { const jsonStatus = JSON.parse(status.status); console.log(`\n${chalk.cyanBright('Id')}\t\t\t${job.id}`); console.log(`${chalk.cyanBright('Status')}\t\t\t${formatJobStatus(job.status)}`); console.log(`${chalk.cyanBright('Triggered At')}\t\t${job.triggeredAt}`); if (job.completedAt) { console.log(`${chalk.cyanBright('Completed At')}\t\t${job.completedAt}`); } else if (job.terminatedAt) { console.log(`${chalk.cyanBright('Terminated At')}\t\t${job.terminatedAt}`); } console.log(`${chalk.cyanBright('Duration')}\t\t${timestampToDurationString(jobRuntime(job))}`); console.log(`${chalk.cyanBright('Runtime Status\n')}${JSON.stringify(jsonStatus, null, 2)}\n`); } else { die(`Runtime Status not available. This is normal for jobs that are not running.`); } } catch (e: any) { die(formatError(e)); } } }