import { getStdout, type IEither, type Traceable } from "@liz-ci/utils"; import type { Job } from "@liz-ci/model"; type QueuePosition = string; export class QueueError extends Error {} export interface IJobQueuer { queue: ( job: TJob, ) => Promise>; } export class LaminarJobQueuer implements IJobQueuer> { constructor( private readonly queuePositionPrefix: string, ) {} public async queue(j: Traceable) { const { item: job, logger: _logger } = j; const logger = _logger.addTracer(() => `[LaminarJobQueuer.queue.${job}]`); const laminarCommand = [ "laminarc", "queue", job.type, ...Object.entries(job.arguments).map(([key, val]) => `"${key}"="${val}"`), ]; logger.log( `im so excited to see how this queue job will end!! (>ᴗ<)`, laminarCommand, ); return (await getStdout(j.map(() => laminarCommand))).mapRight( (stdout) => { logger.log(stdout); const [jobName, jobId] = stdout.split(":"); const jobUrl = `${this.queuePositionPrefix}/jobs/${jobName}/${jobId}`; logger.log(`all queued up and weady to go~ (˘ω˘) => ${jobUrl}\n`); return jobUrl; }, ); } }