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
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 Summary
FieldsModifier and TypeFieldDescriptionprotected DurationMaximum time before the dispatcher times out and kills this job.protected intHow many transparent re-runs the dispatcher may give this job on an upstream retry signal; seeJob.getUpstreamRetries().Fields inherited from interface Job
DEFAULT_UPSTREAM_RETRIES -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractJob(Identifiable parent, String idPrefix) Primary constructor for lineage-aware jobs. -
Method Summary
Modifier and TypeMethodDescriptionfinal StringgetId()Gets the unique job ID.getName()Gets the user-friendly name for this job.Gets parent job ID.intGets the job priority (higher values = higher priority).Maximum time before the dispatcher times out and kills this job.intHow 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.Gets workflow owner.Gets workflow identifier (root job's ID).protected static StringThe framework's readable-id tail: the last two segments of a random UUID (e.g.protected voidsetTimeout(Duration timeout) voidsetUpstreamRetries(int upstreamRetries) The transparent re-runs this job may claim on an upstream retry signal; seeJob.getUpstreamRetries().toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Job
execute, getDisplayName, getJobId, getJobType, getRequirements, postExecute, preExecute
-
Field Details
-
timeout
Maximum time before the dispatcher times out and kills this job. Subclasses set this in their constructor viasetTimeout(Duration). -
upstreamRetries
protected int upstreamRetriesHow many transparent re-runs the dispatcher may give this job on an upstream retry signal; seeJob.getUpstreamRetries(). Set per job throughsetUpstreamRetries(int), by the job's constructor or by its caller.
-
-
Constructor Details
-
AbstractJob
Primary constructor for lineage-aware jobs. All jobs must provide an Identifiable parent for lineage tracking. UseJob.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
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
-
getTimeout
Description copied from interface:JobMaximum 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:
getTimeoutin interfaceJob<T>- Returns:
- the timeout duration, or null for no timeout (default 30 minutes)
-
setTimeout
-
getUpstreamRetries
public int getUpstreamRetries()Description copied from interface:JobHow 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:
getUpstreamRetriesin interfaceJob<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; seeJob.getUpstreamRetries(). -
getPriority
public int getPriority()Description copied from interface:JobGets the job priority (higher values = higher priority).- Specified by:
getPriorityin interfaceJob<T>- Returns:
- the priority
-
getParentJobId
Description copied from interface:IdentifiableGets parent job ID.- Specified by:
getParentJobIdin interfaceIdentifiable- Returns:
- parent job ID, or null for root
-
getWorkflowId
Description copied from interface:IdentifiableGets workflow identifier (root job's ID).- Specified by:
getWorkflowIdin interfaceIdentifiable- Returns:
- workflow ID
-
getUserId
Description copied from interface:IdentifiableGets workflow owner.- Specified by:
getUserIdin interfaceIdentifiable- Returns:
- user ID
-
getName
-
toString
-