Skip to content

Example: Task Dependencies

kporangehat edited this page Dec 21, 2010 · 6 revisions

Task dependencies work very simply in the API and there are only a couple of things to keep in mind when interacting with them.

Create Tasks

Let's create a couple of Tasks and create dependencies between them. First we'll create a 'Layout' Task for our Shot:

    data = {
        'project': {'type':'Project', 'id':65},
        'content': 'Layout',
        'start_date': '2010-04-28',
        'due_date': '2010-05-05',
        'entity': {'type':'Shot', 'id':860}
        }    
    result = sg.create(Task, data)

Returns:

{'content': 'Layout',
 'due_date': '2010-05-05',
 'entity': {'id': 860, 'name': 'bunny_010_0010', 'type': 'Shot'},
 'id': 556,
 'project': {'id': 65, 'name': 'Demo Animation Project', 'type': 'Project'},
 'start_date': '2010-04-28',
 'type': 'Task'}

Now let's create an 'Anm' Task for our Shot:

    data = {
        'project': {'type':'Project', 'id':65},
        'content': 'Anm',
        'start_date': '2010-05-06',
        'due_date': '2010-05-12',
        'entity': {'type':'Shot', 'id':860}
        }    
    result = sg.create(Task, data)

Returns:

{'content': 'Anm',
 'due_date': '2010-05-12',
 'entity': {'id': 860, 'name': 'bunny_010_0010', 'type': 'Shot'},
 'id': 557,
 'project': {'id': 65, 'name': 'Demo Animation Project', 'type': 'Project'},
 'start_date': '2010-05-06,
 'type': 'Task'}

Create A Dependency

Tasks each have an upstream_tasks field and a downstream_tasks field. Each field is a list [] type and can contain zero, one, or multiple Task entity hashes representing the dependent Tasks. Here is how to create a dependency between our 'Layout' and 'Anim' Tasks:

    # make 'Layout' and upstream Task to 'Anm'. (aka, make 'Anm' dependent on 'Layout')
    result = sg.update('Task', 557, {'upstream_tasks':[{'type':'Task','id':556}])

Returns:

[{'id': 557,
  'type': 'Task',
  'upstream_tasks': [{'id': 556, 'name': 'Layout', 'type': 'Task'}]}]

This will also automatically update the downstream_tasks field on 'Layout' to include the 'Anm' Task.

Clone this wiki locally