event listener for shot creation jobs
2 2

29 posts in this topic

Hi, thank you for the question.

 

Yes, there are two ways to do it (or will be when fully exposed).

 

1. Query old events from the api using ftrack.getEvents() and query every minute (Old approach)

2. Same approach as actions (http://support.ftrack.com/customer/portal/articles/1331385) using websockets where you listen to events. (This will be the preferred approach)

 

(1) is available and can be used like this:

import ftrack,timedef getLatestEventId(show):    eventNumber = show.getMeta('latestEventId')    if eventNumber == None:        eventNumber = -1    else:eventNumber = int(eventNumber)    return eventNumberdef setLatestEventId(show,number):    show.setMeta('latestEventId',str(number))def processEvent(event):    #do something    print event.getEntity()    print event.getData()show = ftrack.getShowFromPath('test')eventId = getLatestEventId(show)while(True):    events = ftrack.getEvents(projectId=show.getId(),fromEventId=eventId + 1,actions=['change.status.asset'],preloadObjects=True)    for event in events:        processEvent(event)        eventId = event.getId()    #save number    setLatestEventId(show,eventId)    time.sleep(5)

(2) Not yet supported, and will change in next release without prior information. But technically its a nicer way of doing things.

 

In the current representation the data looks like this is an entity in added, updated or removed.

entities is a list of entities that have changed. Each entity has information about what changed, who its parents are in the project hierarchy etc.

import ftrackftrack.setup()def handleCallback(topic, *args, **kwargs):    #do something with the data    print kwargs.get('entities')ftrack.TOPICS.subscribe('update',handleCallback)ftrack.TOPICS.wait()

This will be formalised in later releases to make it easier to use, and thats why it will change.

 

 

Cheers

Share this post


Link to post
Share on other sites

Will the 1st option stay available in future releases?

 

Actions are great in many situations. But sometimes we want to automate without the user explicitly launching an action.

 

Eg.

When the status of a last version changes, we may want to set the status of its parent task and set the status of all previous versions automatically.

Or the other way round, When a super sets the status of a task, change the status of the last version in this task.

 

 

Will undos work on custom event handling?  :ph34r: 

Share this post


Link to post
Share on other sites

Hi,

 

you can automate without the user interaction using both (1) and (2). Listening to the update event gives you everything that happens in the system in real time.

 

The intended use of (2) is for example, a task status changes then update something else with another status. While (1) is just a way to query old events which could be done over and over again to figure out when there are new events. 

 

Undos are only implemented in the spreadsheets in ftrack.

 

Cheers

Share this post


Link to post
Share on other sites

Hey guys, I am looking at installing a combination of actions and bg-events, much like Mitch, and have a few questions ahead of digging in.

 

Do I need program my own socket-listener or are you guys supplying one (2) which I can simply hang new handlers on? The create_folders_action provides a handleCallback which I cannot find being called anywhere else in the api. The main function in the example appears to be registering the new python command with the event server via the api, but will I need to retain the encapsulating module to run it later on?

 

In the case that the function is being registered along with the action, are there controls for managing the functions provided by the actions in the web client?

 

Thanks,

r

Share this post


Link to post
Share on other sites

Also, the link that you are pointing to contains a broken hyperlink, I assume, to point to the part of the API which describes the event server.

 

Can I ask for any additional documentation regarding this topic please? 

 

Thanks,

r

Share this post


Link to post
Share on other sites

Hi,

 

You can have as many subscribe calls as you like with different callback methods:

ftrack.TOPICS.subscribe('update', handleCallback)

You have to leave a terminal prompt open to retain the listening of the events, or detach the process to let it run in the background.

 

You can find the documentation currently available at http://api.ftrack.com/developing/events/index.html and http://support.ftrack.com/customer/portal/articles/1331385-actions-custom-callbacks-

 

Not sure if this answered your questions. Let me know if it didn't.

Share this post


Link to post
Share on other sites

By your simplest example I am doing the following:

 

import ftrack
 
 
def handleCallback(self, topic, **kw):
    print "RD DBG: handleCallback: 0: %s" % str(kw)
 
 
def main(arguments=None):
    ftrack.setup()
    ftrack.TOPICS.subscribe('*', handleCallback)
    ftrack.TOPICS.wait()
 
 
if __name__ == '__main__':
    raise SystemExit(main(sys.argv[1:]))
 
 
This reports back the following:
 
No handlers could be found for logger "socketIO_client"
 
 
If there is some step in setting up the server to receive requests, or a way to point the api to the server, I have not been able to find it in the documentation. If there is additional documentation regarding: the socket server, handling events, or describing what happens within the TOPICS namespace, please point them to me.
 
Alternatively, I am looking for ways to create directories via ftrack, or the processes it can spurn, as it is a major part in getting the server running.
 
Thanks,
r

Share this post


Link to post
Share on other sites

sorry to crash this thread... but I'm getting into actions myself and I was wondering if there was some more documentation about this. For example, from those links I know there's an action and an update topic. Is there a list of all the events that can happen?

I wanted to ask here first before I install a handler with debug prints and watch it print stuff just to see what's available :-)

Share this post


Link to post
Share on other sites

I spent some time on it this morning before realizing that I hadn't added my server path and api key to the ftrack.py file found in the ftrackAPI. I'm not sure how much I like having the key in such a central location, or associating all api tasks with a single key, but I'll help you in the meantime none the less...

 

The event listener is supplied, and you need to create a script which installs (subscribes) to the event. Events that are called using 'Actions' are generic, but include a dictionary describing which ui element (button) called them, and can make decisions from there. Handling native events could be done at the same location, and it is easy enough to determine how to catch them by subscribing to '*' and printing both the event and the keyword dict that gets handed to your callback.

 

Let me know if you need more than that. I managed to get something sufficient up and running using yapsy and a daemon wrapper called win32service.

 

r

Share this post


Link to post
Share on other sites

The API can also be set up through environment variables as described on this page.

 

We know that the current documentation is quite sparse but it will be much improved in 3.0 which also includes many improvements to the events system.

 

The "No handlers could be found for logger "socketIO_client"" error is most often caused by a firewall blocking requests on port 8002. Make sure traffic on that port is allowed before trying again.

 

Is it 'topic hub' in the first paragraph you think should be a link?

 

Thanks,

Mattias

Share this post


Link to post
Share on other sites

Do I need to create and enable a special user account for Ftrack actions? I am getting  a server error from the createJob call, and it is failing because it does not recognize the user...

 

PermissionDeniedError: Server responded with an error - Unvalid or inactive user name....

 

The userId is not my own, and I cannot find a list of keys for our user accounts (internal or otherwise).

 

r

Share this post


Link to post
Share on other sites

It looks as if it is trying to use my user login name to try and run the command, and that user does not exist in Ftrack (as it has been set to another syntax).

 

I have not been able to find any locations where that has been set, and can only assume that the Action is being called as the windows users attached to the process, rather than as the user logged into the Ftrack web interface.

 

Please advise.

r

Share this post


Link to post
Share on other sites

That was it. The login name which started the event handler process is different than 'any' existing accounts in the Ftrack server and it was breaking any sub-processes which it was trying to run.

 

I assume that this means any Action called from the web server will mask the user id in favour of the account managing the handler process, and I would request it be changed to the account which pressed the button.

 

r

Share this post


Link to post
Share on other sites

The Actions functionality is part of the API and the API has to be set up with an existing user in ftrack. However, you can get the user id of the user that ran the action in the userId argument, like in this simple example:

import ftrackftrack.setup()def handleCallback(topic, buttonId, userId, selection):	print userIdftrack.TOPICS.subscribe('action', handleCallback)ftrack.TOPICS.wait()

Share this post


Link to post
Share on other sites

That is not what is happening for me.

 

Is there a page where I can view all of the userIds or do I need to do that from the API? We are working in a system where the user logins do not match the user names in FTrack and it is causing Actions to fail with an 'Unvalid or inactive user' message.

 

r

Share this post


Link to post
Share on other sites

By the way... Did you try running this script? Have you tried selecting a Shot or a Task below a shot and running the command? I am getting errors with the following code:

 

(create_folders_action.py: line 86)

 

if selectedItem['entityType'] == 'task':
    entity = ftrack.Task(selectedItem['entityId'])
 
 
The traceback error reports the following:
 
FtrackError: Object with id: *tag* and type: task was not found
 
Have I created Shots or Tasks wrong under Ftrack? Or linked them in a strange way? I am able to instantiate Task objects using the id returned by Projects, Assets, and Asset Tasks... But that line throws errors for Shots or the Tasks listed below them, and it is a requirement of the tool that it be able to create directories from a selection of mixed entities in the web browser.
 
Please advise,
r

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
2 2