jobOfRow
uses node:util
A row of the queue as a Job: its function by name, its arguments as they'd print, its trace's id.
import { decode } from "#codebase/tcmts/cli/codec"; import type { Job } from "#codebase/tcmts/studio"; import { inspect } from "node:util"; export function jobOfRow(r: Record<string, unknown>): Job { let args: string; try { args = inspect(decode(String(r.args)), { depth: 4, breakLength: 100 }); } catch { args = String(r.args); } const trace = /^00-([0-9a-f]{32})-/.exec(String(r.traceparent ?? ""))?.[1]; return { id: String(r.id), name: String(r.fn_name), hash: String(r.fn_hash), status: String(r.status), attempts: Number(r.attempts), maxAttempts: Number(r.max_attempts), runAt: Number(r.run_at), created: Number(r.created), ...(r.finished ? { finished: Number(r.finished) } : {}), ...(r.last_error ? { error: String(r.last_error) } : {}), args, ...(r.slot ? { slot: String(r.slot) } : {}), ...(trace ? { trace } : {}), }; }