Using Job and Work Item Properties
Before submitting a job, the client application may add application specific properties to the Job and its work items using the property indexer. Properties are application specific information that are assigned to a job or work item by the client application. Properties can be used to
- Communicate application specific information to the application worker
- Create an association between a job or a work item and an application object
The following are the methods for retrieving properties from jobs and work items:
Method | Return type | Description |
---|---|---|
GetJobPropertiesAsync | JobProperties | Gets job properties for the specified job. |
GetWorkItemPropertiesAsync | WorkItemProperties | Gets application properties for the work items of the specified job. |
Setting job properties
The following code example show how to set job properties:
var job = new Job
{
ServiceName = "CalcWorker", // Name of the OneCompute Application
Work = work,
ClientReference = "Foo", // ClientReference is an property that can be set by the application
["MyJobName"] = "Bar" // Add an application specific named property to the job's property bag
};
job["Number"] = "42";
The Job.ClientReference is reserved for use by the application to reference application specific information, and is not used by OneCompute. Furthermore, Job has a property bag of string-valued properties that can be set and retrieved through an indexer, as shown in the example above.
Retrieving job properties
Job properties can be retrieved using OneComputePlatformClient.GetJobPropertiesAsync. It returns JobProperties that can be used to retrieved properties as shown in the following example:
var jobInfo = await oneComputePlatformClient.GetJobPropertiesAsync(jobId);
var clientReference = jobInfo.ClientReference;
var myJobName = jobInfo["MyJobName"];
var number = jobInfo["Number"];
Setting and retrieving work item properties
Setting and retrieving properties for work items is done in similar ways as for jobs, and the reasons for using them are the same. They should be used to provide application specific information to the worker or to associate a work item to an application object.
Work item properties can be retrieved using OneComputePlatformClient.GetWorkItemPropertiesAsync. It returns a collection of WorkItemProperties that can be used to retrieved properties.
The following code example shows how to assign properties to a WorkUnit, using the Tag property and the property indexer.
var wu = new WorkUnit
{
Tag = "My task",
["FirstName"] = "Foo"
};
wu["LastName"] = "Bar";
These properties can be retrieved using the OneComputePlatformClient as follows:
var jobId = job.JobId;
var workItemId = SelectWorkItem(); // Choose the work item to look for
var workItemProperties = await oneComputePlatformClient.GetWorkItemPropertiesAsync(jobId, workItemId);
var tag = workItemProperties.Tag;
var firstName = workItemProperties["FirstName"];
var lastName = workItemProperties["LastName"];
Finally, it should be mentioned that it is possible to retrieve the properties for all work items of a particular job by using the OneComputePlatformClient.GetworkItemProperties(string jobId) method.