Class JobSnapshot

java.lang.Object
ai.redouble.nucleo.harness.JobSnapshot
All Implemented Interfaces:
Identifiable, Serializable

public class JobSnapshot extends Object implements Serializable, Identifiable
Immutable snapshot of a job's identity and state at a specific point in time.

Captures job identity (jobId, userId, workflowId), human-readable metadata (displayName from @DisplayName, description from @ToolDescription), and state (timestamps, attemptNumber) frozen at a moment in time. Instances are immutable; use with* methods to create new snapshots.

The description field is extracted reflectively from @ToolDescription to avoid a compile-time dependency from Nucleo to the tools layer. Use withDescription(String) to override with a runtime value (e.g., from a prompt management system).

JSON Serialization: Included in JobEvent JSON as nested snapshot object. Fields jobClass, state, description, dependencyJobIds and metadata excluded via @JsonIgnore.

Since:
0.1 (2025-10-08)
Author:
Andrey Santrosyan
See Also:
  • Constructor Details

  • Method Details

    • extractDisplayName

      public static String extractDisplayName(Class<? extends Job> jobClass)
      Extracts human-readable name from @DisplayName annotation or falls back to class simple name.
    • extractAction

      public static String extractAction(Class<? extends Job> jobClass)
      Extracts action verb from @DisplayName annotation. Returns empty string if not specified.
    • extractDescription

      public static String extractDescription(Class<? extends Job> jobClass)
      Extracts description from @ToolDescription annotation via reflection. Uses reflective annotation lookup to avoid a dependency from Nucleo to the tools layer. Returns null if the annotation is not present or the class is not on the classpath.
    • getJobId

      public String getJobId()
      Description copied from interface: Identifiable
      Gets unique job identifier.
      Specified by:
      getJobId in interface Identifiable
      Returns:
      job ID
    • 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
    • jobClass

      public Class<? extends Job> jobClass()
    • getJobType

      public JobType getJobType()
    • getAction

      public String getAction()
    • getDescription

      public String getDescription()
    • getState

      public JobState getState()
    • getSubmittedAt

      public Instant getSubmittedAt()
    • getStartedAt

      public Instant getStartedAt()
    • getCompletedAt

      public Instant getCompletedAt()
    • dependencyJobIds

      public List<String> dependencyJobIds()
    • getMetadata

      public Map<String,Object> getMetadata()
    • getDisplayName

      public String getDisplayName()
    • getAttemptNumber

      public int getAttemptNumber()
    • withState

      public JobSnapshot withState(JobState newState)
      Returns a new snapshot with updated state.
    • withAttemptNumber

      public JobSnapshot withAttemptNumber(int attemptNumber)
      Returns a new snapshot with updated attempt number.
    • withStartedAt

      public JobSnapshot withStartedAt(Instant startedAt)
      Returns a new snapshot with started timestamp.
    • withCompletedAt

      public JobSnapshot withCompletedAt(Instant completedAt)
      Returns a new snapshot with completed timestamp.
    • withDependencyJobIds

      public JobSnapshot withDependencyJobIds(List<String> dependencyJobIds)
      Returns a new snapshot with dependency job IDs.
    • withDescription

      public JobSnapshot withDescription(String description)
      Returns a new snapshot with overridden description. Use when description comes from a runtime source (e.g., prompt management) rather than annotation.
    • withMetadata

      public JobSnapshot withMetadata(Map<String,Object> metadata)
      Returns a new snapshot with updated metadata.
    • jobType

      public String jobType()
      Gets the job type name (simple class name).