Task 6 – Submit a WorkItem
When you post a WorkItem to the Automation Service, you are instructing the service to execute an Activity.
The relationship between an Activity and a WorkItem can be thought of as the relationship between a “function definition” and “function call”. Named parameters of the Activity have corresponding named arguments of the WorkItem. Like in function calls, optional parameters of the Activity can be skipped and left unspecified while posting a WorkItem.
By the end of this task, you will be able to:
- Create a WorkItem to execute an Activity.
- Check if execution succeeded or failed.
- Get the URL to the execution log file.
You will use the following operations to work with WorkItems in this task:
| HTTP Request | Description |
|---|---|
| POST /workitems | Creates a new WorkItem and queues it for processing. |
| GET /workitems/{id} | Gets the status of a specific WorkItem. |
Step 1 - Send a WorkItem
To create a WorkItem to execute the Activity ListLayersActivity:
Request
curl -X POST \ 'https://developer.api.autodesk.com/da/us-east/v3/workitems' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer <YOUR_ACCESS_TOKEN>' \ -d '{ "activityId": "<YOUR_APP_NICKNAME>.ListLayersActivity+my_current_version", "arguments": { "InputDwg": { "url": "urn:adsk.objects:os.object:<YOUR_BUCKET_KEY>/<OBJECT_KEY_4_INPUT_FILE>", "verb": "get", "headers": { "Authorization": "Bearer <YOUR_ACCESS_TOKEN>" } }, "result": { "url": "urn:adsk.objects:os.object:<YOUR_BUCKET_KEY>/<OBJECT_KEY_4_OUTPUT_FILE>", "verb": "put", "headers": { "Authorization": "Bearer <YOUR_ACCESS_TOKEN>" } } } }'Show MoreNote
Attribute Description activityIdThe target Activity defined by “owner.activity+alias” this WorkItem will execute. arguments The argument list that is required by the Activity (ListLayersActivity):-InputDwg- Details of the input file that must be downloaded from OSS and then processed by the WorkItem.-result- Details of the output that must be “put” (uploaded) to OSS.priority(Beta)Coming soon. Optional. The priority tier of this WorkItem.- Supported values areP1andP3, case-insensitive.-P3, the standard queue, is equivalent to leaving it out.- Any other value is rejected with an error.- See beta limits and terms.- Send feedback and questions about the beta at feedback.autodesk.com/flexiblecompute.The response contains the
idof the posted WorkItem:
Response
{
"status": "pending",
"stats": {
"timeQueued": "2019-10-17T11:21:50.5619735Z"
},
"id": "<YOUR_WORKITEM_ID>"
}
Step 2 - Check status of a WorkItem
WorkItems are queued before they are processed. A WorkItem’s processing time will vary depending on the size and complexity of the input files, the type of processing done by the AppBundle, and the size of the output files.
In this walkthrough, you will be checking the WorkItem status to see if it has completed.
However, the best practice is to use the onComplete argument when submitting a WorkItem.
The onComplete argument enables you to specify a callback URL, which will be called once the WorkItem is completed.
For more information see the documentation on callbacks here.
You can check the status of a WorkItem by calling `GET /v3/workitems/{id}`_ :
Request
curl -X GET \
https://developer.api.autodesk.com/da/us-east/v3/workitems/<YOUR_WORKITEM_ID> \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <YOUR_ACCESS_TOKEN>'
Response
{
"status": "success",
"reportUrl": "https://dasprod-store.s3.amazonaws.com/workItem/<YOUR_APP_NICKNAME>/2ea96495c..{Truncated}",
"stats": {
"timeQueued": "2019-10-17T11:21:50.5619735Z",
"timeDownloadStarted": "2019-10-17T11:21:42.5827646Z",
"timeInstructionsStarted": "2019-10-17T11:21:43.3796462Z",
"timeInstructionsEnded": "2019-10-17T11:21:45.3952874Z",
"timeUploadEnded": "2019-10-17T11:21:45.5515369Z",
"timeFinished": "2019-10-17T11:21:54.1463701Z",
"bytesDownloaded": 88612,
"bytesUploaded": 1115
},
"id": "2ea96495c30d432b84797d7e71262772"
}
| Attribute | Description |
|---|---|
status |
Indicates if execution is pending, successful, failed or cancelled. |
reportUrl |
The URL to get the report log for this WorkItem’s execution. |
Additional notes
(Beta) Priority Pass is coming soon for AutoCAD during the public beta. Until then, a P1 request for AutoCAD is rejected with an error. To check whether it is available, call GET engines/:id and look for "priorityPass": true.
The optional WorkItem attribute priority places a WorkItem in a priority queue. Priority affects the position of the WorkItem in the queue; it is not a commitment on queue time, processing time or completion time. During the beta, each client ID can have one P1 WorkItem. A second P1 request is rejected with an error that includes the reason.
Process a priority WorkItem
To use a priority queue, add "priority": "P1" to the WorkItem payload.
{
"activityId": "<YOUR_APP_NICKNAME>.ListLayersActivity+my_current_version",
"arguments": { ... },
"priority": "P1"
}
For when to use Priority Pass, the beta limits and the beta terms, see High Memory, GPU and Priority Pass (Beta). Send feedback and questions about the beta at feedback.autodesk.com/flexiblecompute.