Using summary as event trigger

Hi all,

I want to update my Episode Task status based on the related Tasks for Shots in the Episode, i. e. when all Episode Shot Tasks at a given step (say, Layout) are approved, set the Episode Layout Task status to apr.
I did that once based on Task status updates, checking all Shot Task statuses every time one of them was set to apr… needless to say it wasn’t my best idea, as the event handler had to face huge queries.
Now I wonder if it would be possible to use the summaries as triggers, so I would only use their value to update my Episode (and if so, how?).


Best Regards,


Hi François,

Status summaries can’t trigger the event daemon as they are not an actual data change on a record.

The best you can do is trigger on anything that in turn affects the summary which is what I think you did previously. I’ll rehash the process here for everyone’s benefit.

  • Register an event daemon plugin that triggers on Task status change
  • When your plugin is called make sure your task is connected to an episode before continuing
  • If you are connected to an episode, load the original Task’s siblings. You can do this by loading all tasks linked to your episode or loading all sibling_tasks of your original task.
  • Compute your tasks’ summary
  • Set the status on your episode

Essentially, once you get the event you’ll have one find call and one update call to the server.

Your find will look something like this:

task = sg.find('Task', [['id', 'is', event['entity']['id']]], ['sibling_tasks', 'entity'])

If task && task['entity'] && task['entity']['type'] == 'Episode' then you can continue and process the summary of the statuses of tasks contained in task['sibling_tasks'].

Once you have that computed you can do an update of your Episode like so:

sg.update('Episode', task['entity']['id'], {'sg_status_list': computed_status})

Hi Patrick, thanks for your insights!

I did not know about the sibling_tasks stuff, that’s pretty nice. Unfortunately this does not do the trick for me as what I need to review is the Episode.Shot.Task.Layout status, not Episode.Task status.
Hence I need to first get all Layout Tasks from Shots in my Episode, and check all statuses are apr. If so, I update my Episode Layout Task to apr like you showed us.



Hmmm… I missed that linkage from your original message. So if I understand you correctly, tasks are linked to shots and shots to episodes.

So you’d first need to load the one episode linked to the task change (via any Shot) that just triggered the event. Then you’d need to load all tasks linked to that episode (via all Shots). Finally, you’d compute and update. There’s indeed a 3rd necessary call that I don’t think can be worked around.

episode = sg.find_one('Episode', [['', 'is', event['entity']['id']]])
tasks = sg.find(
    [['', 'is', episode['id']], ['step', 'is', layout_step]],
# Compute episode's status based on tasks' statuses
sg.update('Episode', episode['id'], {'sg_status_list': computed_status})

This assumes there is a single entity field from Shot to Episode called sg_episode which automatically generated the reverse multi-entity field from Episode to Shot called sg_shots.

1 Like

Hi Patrick,

I wanted to finish my tests before sharing my solution with you, it seems you were faster than me :wink:
I did the way you show, but had to query the Task first because I had to handle several different Steps and not layout alone. Another point is that it is the Episode Task status that I want to update, not the Episode status itself.
Here is the process I use:

# Get task details
task = sg.find_one('Task', [['id', 'is', event['entity']['id']]], ['step', 'entity.Shot.sg_episode', 'content'])

# Filter out other Entities than Shots
if task.get('entity.Shot.sg_episode'):
    episode = task['entity.Shot.sg_episode']

    # Get all Tasks of the same Shot and Step
    tasks = sg.find('Task',
                    [['step', 'is', task['step']], ['entity.Shot.sg_episode', 'is', episode]],
                    ['content', 'sg_status_list'])

    # loop if ever we need to test several values
    for stat_val in ['apr',]:
        ep_update = all(elmt['sg_status_list'] == stat_val for elmt in tasks)

        # All Shots status are the same -> update Episode Task status
        if ep_update:
            ep_task = sg.find_one('Task', [['content', 'is', task['content']], ['entity', 'is', episode]])
            if ep_task:
                sg.update('Task', ep_task['id'], {'sg_status_list': stat_val})

I get it! Looks great!

Thanks for sharing your solution with the community.

1 Like