cancelJob

tcmts.studio.cancelJob · #yq3s7lbk · term · runs on the server

uses tcmts.studio.editableCodebase, which uses tcmts.share.servedCodebase, which uses process

Cancel job id, as tcm jobs cancel does: only while it's queued (one running finishes).

import { HttpError } from "#codebase/tcmts/server";
import { editableCodebase, withJobs } from "#codebase/tcmts/studio";

export async function cancelJob(id: string): Promise<void> {
  const cb = editableCodebase();
  const n = withJobs(
    cb,
    (db) =>
      db
        .prepare(
          "UPDATE jobs SET status = 'cancelled', finished = ? WHERE id = ? AND status = 'queued'",
        )
        .run(Date.now(), id).changes,
    true,
  );
  if (!n) throw new HttpError(409, "It isn't queued: running, or finished.");
}

uses

used by