Anthony Kramer Posted October 17, 2013 Report Share Posted October 17, 2013 Is there a way to create an event listener that will launch a job when a new episode/sequence/shot/task is created? I'd like to create folder structures on my local disk when I add shots or tasks. Link to comment Share on other sites More sharing options...
Björn Rydahl Posted October 18, 2013 Report Share Posted October 18, 2013 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 Link to comment Share on other sites More sharing options...
Anthony Kramer Posted October 18, 2013 Author Report Share Posted October 18, 2013 Awesome, I look forward to the next release. In the meantime I will give this a try. Thanks Link to comment Share on other sites More sharing options...
mitch.s Posted October 21, 2013 Report Share Posted October 21, 2013 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? Link to comment Share on other sites More sharing options...
Björn Rydahl Posted October 22, 2013 Report Share Posted October 22, 2013 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 Link to comment Share on other sites More sharing options...
Björn Rydahl Posted October 22, 2013 Report Share Posted October 22, 2013 And to answer your first question. Yes, (1) will stay available. Cheers Link to comment Share on other sites More sharing options...
bnrayner Posted July 1, 2014 Report Share Posted July 1, 2014 Any new on this? Link to comment Share on other sites More sharing options...
Mattias Seebergs Posted July 2, 2014 Report Share Posted July 2, 2014 Hi Brenton, The preferred approach is (2) above and (1) is not recommended. You can read more about event listening here: http://api.ftrack.com/developing/events/index.html Let us know if you have any questions. Link to comment Share on other sites More sharing options...
rdurnin Posted September 16, 2014 Report Share Posted September 16, 2014 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 Link to comment Share on other sites More sharing options...
rdurnin Posted September 17, 2014 Report Share Posted September 17, 2014 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 Link to comment Share on other sites More sharing options...
Mattias Seebergs Posted September 17, 2014 Report Share Posted September 17, 2014 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. Link to comment Share on other sites More sharing options...
rdurnin Posted September 18, 2014 Report Share Posted September 18, 2014 Yes, enough to start building, although that page is the one with the missing hyperlink (topic hub). Thanks,r Link to comment Share on other sites More sharing options...
rdurnin Posted September 18, 2014 Report Share Posted September 18, 2014 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 Link to comment Share on other sites More sharing options...
rdurnin Posted September 18, 2014 Report Share Posted September 18, 2014 I would assume this has something to do with the api keys that I have, or need to, setup, although I am not sure where in this code example the server key needs to be added. r Link to comment Share on other sites More sharing options...
Tilt Posted September 18, 2014 Report Share Posted September 18, 2014 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 :-) Link to comment Share on other sites More sharing options...
rdurnin Posted September 18, 2014 Report Share Posted September 18, 2014 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 Link to comment Share on other sites More sharing options...
Mattias Seebergs Posted September 22, 2014 Report Share Posted September 22, 2014 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 Link to comment Share on other sites More sharing options...
rdurnin Posted September 23, 2014 Report Share Posted September 23, 2014 That was where I was expecting to find a link to a description, yes. Env vars are next, and thanks. r Link to comment Share on other sites More sharing options...
rdurnin Posted September 23, 2014 Report Share Posted September 23, 2014 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 Link to comment Share on other sites More sharing options...
rdurnin Posted September 23, 2014 Report Share Posted September 23, 2014 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 Link to comment Share on other sites More sharing options...
rdurnin Posted September 23, 2014 Report Share Posted September 23, 2014 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 Link to comment Share on other sites More sharing options...
Mattias Seebergs Posted September 24, 2014 Report Share Posted September 24, 2014 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() Link to comment Share on other sites More sharing options...
rdurnin Posted September 25, 2014 Report Share Posted September 25, 2014 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 Link to comment Share on other sites More sharing options...
rdurnin Posted September 25, 2014 Report Share Posted September 25, 2014 By ensuring the login account matches the ftrack login I am able to run actions. Thanks,r Link to comment Share on other sites More sharing options...
rdurnin Posted September 25, 2014 Report Share Posted September 25, 2014 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.