How to retrieve WorkUnit Results
As work units are completed, the application worker may return a result object. This application object will be wrapped inside a Result and stored. It can subsequently be retrieved by the client application through the OneCompute Platform API using the GetWorkItemResultAsync method.
The following code example shows how to retrieve the result in an event handler for the IJobMonitor.WorkItemStatusChanged event after the work unit is completed.
var monitor = await oneComputePlatformClient.SubmitJobAsync(job);
monitor.WorkItemStatusChanged += async (sender, workItemEvent) =>
{
if (workItemEvent.WorkStatus == WorkStatus.Completed)
{
var result = await oneComputePlatformClient.GetWorkItemResultAsync(workItemEvent.JobId, workItemEvent.WorkItemId);
var calcResult = result?.GetResult<CalcOutput>();
}
};
The GetWorkItemResultsAsync method will return the results for all work units of the given job. The following is a code example that retrieves the results of an entire job from the event handler of the IJobMonitor.JobStatusChanged event:
var monitor = await oneComputePlatformClient.SubmitJobAsync(job);
monitor.JobStatusChanged += async (sender, jobEvent) =>
{
if (jobEvent.WorkStatus == WorkStatus.Completed)
{
var results = await oneComputePlatformClient.GetWorkItemResultsAsync(jobEvent.JobId);
var calcResults = results.Select(r => r.GetResult<CalcOutput>());
}
};