summaryrefslogtreecommitdiff
path: root/hooks/queuer.ts
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2025-05-12 23:05:27 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2025-05-12 23:33:52 -0700
commite49fda41176d025a671802be76c219d66167276f (patch)
tree6791f0ffe26b2405e13436a7e0c8d05d60e2b3bc /hooks/queuer.ts
parentbbaea13ee7125a9d289a74f0c173e7e75177e53c (diff)
downloadci-e49fda41176d025a671802be76c219d66167276f.tar.gz
ci-e49fda41176d025a671802be76c219d66167276f.zip
snapshot
Diffstat (limited to 'hooks/queuer.ts')
-rw-r--r--hooks/queuer.ts47
1 files changed, 47 insertions, 0 deletions
diff --git a/hooks/queuer.ts b/hooks/queuer.ts
new file mode 100644
index 0000000..1461809
--- /dev/null
+++ b/hooks/queuer.ts
@@ -0,0 +1,47 @@
+import type { IEither, ITraceable, ITraceableLogger } from "@liz-ci/utils";
+import type { Job } from "@liz-ci/model";
+
+type QueuePosition = string;
+export class QueueError extends Error {}
+export interface IJobQueuer<TJob> {
+ queue: <L extends ITraceableLogger<L>>(
+ job: ITraceable<TJob, L>,
+ ) => Promise<IEither<QueueError, QueuePosition>>;
+}
+
+export class LaminarJobQueuer implements IJobQueuer<Job> {
+ constructor(
+ private readonly queuePositionPrefix: string,
+ ) {}
+
+ public async queue({ item: job, logger }: Traceable<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(laminarCommand)).mapBoth(
+ (e) => {
+ const err = `we bwoke oh noesss D:`;
+ logger.error(err, e);
+ return Either.left<QueueError, QueuePosition>(e);
+ },
+ (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 Either.right<QueueError, QueuePosition>(jobUrl);
+ },
+ );
+ }
+}