Class JobTracking

java.lang.Object
com.kingsrook.qqq.backend.core.jobs.progress.JobTracking

public final class JobTracking extends Object
Tracking jobs for work that no durable plan runs (for example an assistant turn): a jobs_job row the owner sees in the Jobs tray, with the same live progress and log as a durable job. The work itself is not durable: if this pod goes away, the reaper fails the row with an honest message.
 Integer jobId = JobTracking.start(new TrackedJobRequest().withUserId(user)
    .withLabel("Assistant answer").withProcessName("assistant.turn"));
 JobTracking.onCancel(jobId, () -> cancelTurn());
 JobTracking.progress(jobId).phases(...).phase("thinking").message("...");
 JobTracking.finish(jobId, JobStatus.COMPLETED, "Answered.");
 
Requires the durable jobs runtime to be running on this pod.
  • Method Details

    • start

      public static Integer start(TrackedJobRequest request) throws QException
      Start a RUNNING tracking job; returns its jobs_job id.
      Throws:
      QException
    • progress

      public static JobProgress progress(Integer jobId) throws QException
      A progress reporter for the tracking job (phases, counts, message, log). Keep and reuse one reporter per job: it holds the phase state.
      Throws:
      QException
    • heartbeat

      public static void heartbeat(Integer jobId) throws QException
      Record that the work is alive (progress flushes do this too).
      Throws:
      QException
    • finish

      public static void finish(Integer jobId, JobStatus status, String message) throws QException
      Finalize with COMPLETED, FAILED or CANCELLED (the first final status wins).
      Throws:
      QException
    • onCancel

      public static void onCancel(Integer jobId, Runnable listener) throws QException
      Register a listener run on this pod when a client cancels the job; it must stop the work and call finish(..., CANCELLED).
      Throws:
      QException