Package titan.scheduler
Class TaskExecution
java.lang.Object
titan.scheduler.TaskExecution
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
FieldsModifier and TypeFieldDescription(package private) WorkerThe worker instance to which this task was assigned for execution.(package private) longThe timestamp (in milliseconds) when the task execution completed or failed.(package private) StringThe unique identifier for the job associated with this task execution.(package private) StringStores the result, output, or error message generated by the task execution.(package private) longThe timestamp (in milliseconds) when the task execution started.(package private) Job.StatusThe current status of the task execution (e.g.,Job.Status.RUNNING,Job.Status.COMPLETED,Job.Status.FAILED). -
Constructor Summary
ConstructorsConstructorDescriptionTaskExecution(String jobId, Worker worker) Constructs a newTaskExecutioninstance, initializing it for a running task. -
Method Summary
Modifier and TypeMethodDescriptionvoidMarks the task execution as completed successfully.voidMarks the task execution as failed.longCalculates the duration of the task execution.
-
Field Details
-
jobId
String jobIdThe unique identifier for the job associated with this task execution. -
assignedWorker
Worker assignedWorkerThe worker instance to which this task was assigned for execution. -
startTime
long startTimeThe timestamp (in milliseconds) when the task execution started. -
endTime
long endTimeThe timestamp (in milliseconds) when the task execution completed or failed. This value will be 0 if the task is still running. -
status
Job.Status statusThe current status of the task execution (e.g.,Job.Status.RUNNING,Job.Status.COMPLETED,Job.Status.FAILED). -
output
String outputStores 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
Constructs a newTaskExecutioninstance, initializing it for a running task. Sets the job ID, assigns the worker, records the start time, and sets the initial status toJob.Status.RUNNING.- Parameters:
jobId- The unique identifier of the job.worker- The worker instance assigned to execute this task.
-
-
Method Details
-
complete
Marks the task execution as completed successfully. Updates the task's status toJob.Status.COMPLETED, records the end time, and stores the provided output.- Parameters:
output- The successful output or result generated by the task.
-
fail
Marks the task execution as failed. Updates the task's status toJob.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 betweenendTimeandstartTime. If the task is still running (i.e.,endTimeis 0), it returns the duration fromstartTimeto the current time.- Returns:
- The duration of the task execution in milliseconds.
-