Class TaskExecution

java.lang.Object
titan.scheduler.TaskExecution

class TaskExecution extends Object
Represents the execution status of a specific task within the scheduler. This class encapsulates all relevant information about a task's lifecycle, including its assigned worker, start and end times, current status, and any output or error messages. It is crucial for monitoring, logging, and dashboard display within the scheduler system.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) Worker
    The worker instance to which this task was assigned for execution.
    (package private) long
    The timestamp (in milliseconds) when the task execution completed or failed.
    (package private) String
    The unique identifier for the job associated with this task execution.
    (package private) String
    Stores the result, output, or error message generated by the task execution.
    (package private) long
    The timestamp (in milliseconds) when the task execution started.
    (package private) Job.Status
    The current status of the task execution (e.g., Job.Status.RUNNING, Job.Status.COMPLETED, Job.Status.FAILED).
  • Constructor Summary

    Constructors
    Constructor
    Description
    TaskExecution(String jobId, Worker worker)
    Constructs a new TaskExecution instance, initializing it for a running task.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    complete(String output)
    Marks the task execution as completed successfully.
    void
    fail(String error)
    Marks the task execution as failed.
    long
    Calculates the duration of the task execution.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • jobId

      String jobId
      The unique identifier for the job associated with this task execution.
    • assignedWorker

      Worker assignedWorker
      The worker instance to which this task was assigned for execution.
    • startTime

      long startTime
      The timestamp (in milliseconds) when the task execution started.
    • endTime

      long endTime
      The timestamp (in milliseconds) when the task execution completed or failed. This value will be 0 if the task is still running.
    • status

      Job.Status status
      The current status of the task execution (e.g., Job.Status.RUNNING, Job.Status.COMPLETED, Job.Status.FAILED).
    • output

      String output
      Stores the result, output, or error message generated by the task execution. For example, "RESULT: 5050" for a successful completion or an error log for a failure.
  • Constructor Details

    • TaskExecution

      public TaskExecution(String jobId, Worker worker)
      Constructs a new TaskExecution instance, initializing it for a running task. Sets the job ID, assigns the worker, records the start time, and sets the initial status to Job.Status.RUNNING.
      Parameters:
      jobId - The unique identifier of the job.
      worker - The worker instance assigned to execute this task.
  • Method Details

    • complete

      public void complete(String output)
      Marks the task execution as completed successfully. Updates the task's status to Job.Status.COMPLETED, records the end time, and stores the provided output.
      Parameters:
      output - The successful output or result generated by the task.
    • fail

      public void fail(String error)
      Marks the task execution as failed. Updates the task's status to Job.Status.FAILED, records the end time, and stores the provided error message.
      Parameters:
      error - The error message or exception details that caused the task to fail.
    • getDuration

      public long getDuration()
      Calculates the duration of the task execution. If the task has completed or failed, it returns the difference between endTime and startTime. If the task is still running (i.e., endTime is 0), it returns the duration from startTime to the current time.
      Returns:
      The duration of the task execution in milliseconds.