Monitor Job Status and Progress
- Definition of Terminal Work States
- The Job Monitor
- Awaiting job termination
- Event-based job monitoring
- Polling job status and progress through the API
The OneComputePlatformClient.SubmitJobAsync method submits the specified Job and returns a job monitor that allows the client to monitor the status and progress of the job. Likewise, OneComputePlatformClient.BeginMonitorJobAsync returns an IJobMonitor that supports event-based monitoring. The latter method can be used to reconnect to a job that has previously been submitted.
Definition of Terminal Work States
Three work states are defined as terminal:
- WorkStatus.Completed: The job or work item completed successfully.
- WorkStatus.Faulted: The job or work item failed. A job fails if one or more work items fails.
- WorkStatus.Aborted: The job was canceled by the user.
The Job Monitor
The IJobMonitor returned from the SubmitJobAsync method or the BeginMonitorJobAsync method enables event-based monitoring of job and work item status and progress.
Awaiting job termination
The IJobMonitor.AwaitTerminationAsync is an extension method that allows the client application to wait for the job to terminate.
Event-based job monitoring
The IJobMonitor interface exposes the follwing events:
Event | Description |
---|---|
JobStatusChanged | Event triggered when the job status has changed |
JobProgressChanged | Event triggered when the overall job progress has changed. |
WorkItemStatusChanged | Event triggered when a work item has changed status |
WorkItemProgressChanged | Event triggered when the progress of a work item has changed. |
The following is a code example on how to do event-based job monitoring:
var monitor = await oneComputePlatformClient.SubmitJobAsync(job);
monitor.JobStatusChanged += async (sender, jobEvent) =>
{
if (jobEvent.WorkStatus.IsTerminal())
{
Console.WriteLine($"Job {jobEvent.JobId} terminated with status {jobEvent.WorkStatus}.")
}
};
monitor.WorkItemStatusChanged += async (sender, workItemEvent) =>
{
if (workItemEvent.WorkStatus.IsTerminal())
{
Console.WriteLine($"Work item {workItemEvent.WorkItemId} terminated with status {workItemEvent.WorkStatus}.")
}
};
var jobStatus = await monitor.AwaitTerminationAsync(job.JobId);
Polling job status and progress through the API
The alternative to use event-based monitoring is for the client to use the OneComputePlatformClient to request status information for a job or its work items. The OneCompute Platform API offers methods for requesting status information for jobs, status information for all work items in a job and status information for a particular work item:
Method | Return type | Description |
---|---|---|
GetJobStatusAsync | JobInfo | Gets the status info for the specified job. |
GetWorkItemInfoAsync | IEnumerable<WorkItemInfo> |
Gets status info for the work items for the specified job. |
GetWorkItemInfoAsync | WorkItemInfo | Gets status info for the specified work item. |