Class AbstractJob<T>

java.lang.Object
ai.redouble.nucleo.harness.AbstractJob<T>
Type Parameters:
T - the type of result this job produces
All Implemented Interfaces:
Identifiable, Job<T>
Direct Known Subclasses:
AbstractGuardrail, AbstractTool

public abstract class AbstractJob<T> extends Object implements Job<T>
Base class for all jobs that can be submitted to the job processing system. Jobs are units of work that declare their resource requirements and execute with provided resources. The constructor mints the job's identity (a readable prefix, the class simple name when none is given, plus a random tail) and inherits its lineage from the parent it is handed; a root job's parent is Job.workflow(String, String).

IMPORTANT: Jobs must be stateless or idempotent! The same Job instance is executed again when the dispatcher re-runs an attempt (an upstream throttle, a truncated answer, a correction). Do not rely on mutable instance fields that change during execution. Instead, use immutable fields set in the constructor or fetch state from the database on each execution.

Good practice: - Store IDs in final fields - Fetch entities from database in execute() - Don't accumulate state in instance variables

Since:
0.1 (2025-08-10)
Author:
Andrey Santrosyan
  • Field Details

    • timeout

      protected Duration timeout
      Maximum time before the dispatcher times out and kills this job. Subclasses set this in their constructor via setTimeout(Duration).
    • upstreamRetries

      protected int upstreamRetries
      How many transparent re-runs the dispatcher may give this job on an upstream retry signal; see Job.getUpstreamRetries(). Set per job through setUpstreamRetries(int), by the job's constructor or by its caller.
  • Constructor Details

    • AbstractJob

      protected AbstractJob(Identifiable parent, String idPrefix)
      Primary constructor for lineage-aware jobs. All jobs must provide an Identifiable parent for lineage tracking. Use Job.workflow(String, String) for root jobs.
      Parameters:
      parent - the parent identity (use Job.workflow() for root jobs)
      idPrefix - prefix for the job ID, or null to use class name
      Throws:
      IllegalArgumentException - if parent is null
  • Method Details

    • randomIdSuffix

      protected static String randomIdSuffix()
      The framework's readable-id tail: the last two segments of a random UUID (e.g. a26f-52b01fa3bd75). Prefixed with a human-readable name it makes every framework identity - job ids here, minted conversation ids in thinkers - scannable in logs and DB rows while staying unique enough for their lifetimes.
    • getId

      public final String getId()
      Gets the unique job ID. This is final to prevent subclasses from overriding.
      Specified by:
      getId in interface Job<T>
      Returns:
      the job ID
    • getTimeout

      public Duration getTimeout()
      Description copied from interface: Job
      Maximum time before the dispatcher times out and kills this job. Null means no deadline - the dispatcher schedules no killer (used by orchestrators, which only wait on tools).
      Specified by:
      getTimeout in interface Job<T>
      Returns:
      the timeout duration, or null for no timeout (default 30 minutes)
    • setTimeout

      protected void setTimeout(Duration timeout)
    • getUpstreamRetries

      public int getUpstreamRetries()
      Description copied from interface: Job
      How many transparent re-runs the dispatcher may give this job when the upstream fails with a retry signal (a 429, a 529, a plain 5xx or a connection failure), on one shared counter per execution; past them the job fails with the last signal as cause. The budget is this job's alone: a job that awaits this one receives that failure and fails once, without running its own body again, so budgets do not multiply with the depth of the job tree. The pacing window scales by attempt, so every re-run is minutes a caller waits behind: a job whose caller waits interactively sets fewer, an unattended pipeline may set more.
      Specified by:
      getUpstreamRetries in interface Job<T>
      Returns:
      the budget (default Job.DEFAULT_UPSTREAM_RETRIES)
    • setUpstreamRetries

      public void setUpstreamRetries(int upstreamRetries)
      The transparent re-runs this job may claim on an upstream retry signal; see Job.getUpstreamRetries().
    • getPriority

      public int getPriority()
      Description copied from interface: Job
      Gets the job priority (higher values = higher priority).
      Specified by:
      getPriority in interface Job<T>
      Returns:
      the priority
    • getParentJobId

      public String getParentJobId()
      Description copied from interface: Identifiable
      Gets parent job ID.
      Specified by:
      getParentJobId in interface Identifiable
      Returns:
      parent job ID, or null for root
    • getWorkflowId

      public String getWorkflowId()
      Description copied from interface: Identifiable
      Gets workflow identifier (root job's ID).
      Specified by:
      getWorkflowId in interface Identifiable
      Returns:
      workflow ID
    • getUserId

      public String getUserId()
      Description copied from interface: Identifiable
      Gets workflow owner.
      Specified by:
      getUserId in interface Identifiable
      Returns:
      user ID
    • getName

      public String getName()
      Description copied from interface: Job
      Gets the user-friendly name for this job.
      Specified by:
      getName in interface Job<T>
      Returns:
      the job name
    • toString

      public String toString()
      Overrides:
      toString in class Object