We use cookies (just for analytics) on this website. If you continue we will assume you are happy with it. ok

BeBanjo

Back to index

Task

Tasks are each of the steps that need to be completed in order for a job to be processed. A task belongs to a job. It has no child resources.

Here is what its XML looks like:

<?xml version='1.0' encoding='utf-8' ?>
<task>
  <name>Encoding</name>
  <status>pending</status>
  <requires-duration type='boolean'>true</requires-duration>
  <duration>12:15:00</duration>
  <position type='integer'>1</position>
  <link href="http://sequence.example.com/api/work_areas/10/jobs/12875/tasks/55999" rel="self"></link>
  <link href="http://sequence.example.com/api/work_areas/10/jobs/12875" rel="job"></link>
</task>

Valid attributes

  • name (string, read/write): This is the name of the task. It can be any string. Normally, the name of the tasks for a given job will be derived on the job creation from those defined in a workflow template

  • status (string, read/write): This is the status of a specific task. It can be in one of these two states:

    • pending: This is the initial state of a task, when it has not been completed yet.

    • completed: When a task has been deemed complete

  • requires-duration (boolean, read/write on creation, read only later): This inmutable flag indicates whether a certain task requires a duration. Being true a duration attribute will be present in the task information. Otherwise the duration attribute will be ommited. If not provided on creation, requires-duration will default to false, and the task will not require duration.

  • duration (string, read/write): For tasks that require duration (requires-duration is true), represents the time the task took to complete. Values for this field should be provided in the format hh:mm:ss, otherwise a validation error will be raised. Duration is blank by default, and a task that requires duration will not be able to be completed until this attribute is properly updated.

  • position (integer, read/write): Optional. The position of this task within the list of tasks for this job. The value, if provided, must be an integer value greater than zero. And if not provided, it will be automatically assigned to the next available position starting on 1. Trying to set a value greater than the next available position is not possible.

Creating a task

In order to add a task to a specific Job, it is necessary to issue a POST request to the tasks list of a Job. The URL for the request would look something like this:

https://sequence.example.com/api/work_areas/10/jobs/27188/tasks

The attributes that can be used to create a task are:

  • name (required)

  • status (optional)

  • requires-duration (optional, defaults to false)

  • duration (optional, only valid if require-duration is true)

  • position (optional)

Here is an example using curl:

$ curl --digest -u robot_user -H "Content-Type: application/xml" -d @task.xml https://sequence.example.com/api/work_areas/10/jobs/27188/tasks

This line would issue a POST request to the URL specified at the end using digest authentication. It is also setting the HTTP header “Content-Type: application/xml” (required) and is sending the contents of the file task.xml as the body of the request.

This is what the body of the POST request should look like:

<task>
  <name>Encoding</name>
</task>

If successfully created, the response will be the complete XML of the new job with an HTTP status code of 200:

<task>
  <name>Encoding</name>
  <status>pending</status>
  <requires-duration type='boolean'>false</requires-duration>
  <position type='integer'>1</position>
  <link href="https://sequence.example.com/api/work_areas/10/jobs/27188/tasks/123941" rel="self"></link>
  <link href="https://sequence.example.com/api/work_areas/10/jobs/27188" rel="job"></link>
</task>

If duration would be required, the post data would look like:

<task>
  <name>Encoding</name>
  <require-duration>true</require-duration>
</task>

And if successfully created, the body of the response will differ from the above, being in this case:

<task>
  <name>Encoding</name>
  <status>pending</status>
  <requires-duration type='boolean'>true</requires-duration>
  <duration/>
  <position type='integer'>1</position>
  <link href="https://sequence.example.com/api/work_areas/10/jobs/27188/tasks/123941" rel="self"></link>
  <link href="https://sequence.example.com/api/work_areas/10/jobs/27188" rel="job"></link>
</task>

Updating a task

To update a task, it is necessary to issue a PUT request to the URL of a given task. The body of the request should contain the XML of the task with the changed attributes. Note that not all attributes must be included, it would be enough to include the attributes that we wish to update.

The following example updates the status of the previous task. Note how the URL used now is the one that uniquely identifies the task:

$ curl --digest -u robot_user -H "Content-Type: application/xml" -X PUT -d @task_update.xml https://sequence.example.com/api/work_areas/10/jobs/27188/tasks/123941

This is what the body of the request would contain:

<task>
  <status>completed</status>
</task>

If the request is successful, it should return the updated task XML and a status code of 200:

<task>
  <name>Encoding</name>
  <requires-duration type='boolean'>true</requires-duration>
  <duration>12:15:00</duration>
  <status>completed</status>
  <position type='integer'>1</position>
  <link href="https://sequence.example.com/api/work_areas/10/jobs/27188/tasks/123941" rel="self"></link>
  <link href="https://sequence.example.com/api/work_areas/10/jobs/27188" rel="job"></link>
</task>

Deleting a task

In order to Delete a task, it is only necessary to issue a DELETE request to the task URL, like so:

$ curl --digest -u robot_user -H "Content-Type: application/xml" -X DELETE https://sequence.example.com/api/work_areas/10/jobs/27188/tasks/123941

The response should be a 204 (no content) HTTP status code, with no body.

Last updated May 05th, 2017.