ftrack_api.event.hub
- class ftrack_api.event.hub.SocketIoSession(id, heartbeatTimeout, supportedTransports)
- __init__()
- count(value, /)
Return number of occurrences of value.
- heartbeatTimeout
Alias for field number 1
- id
Alias for field number 0
- index(value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
- supportedTransports
Alias for field number 2
- class ftrack_api.event.hub.ServerDetails(scheme, hostname, port)
- __init__()
- count(value, /)
Return number of occurrences of value.
- hostname
Alias for field number 1
- index(value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
- port
Alias for field number 2
- scheme
Alias for field number 0
- class ftrack_api.event.hub.EventHub(server_url, api_user, api_key, headers=None, cookies=None)[source]
Manage routing of events.
- __init__(server_url, api_user, api_key, headers=None, cookies=None)[source]
Initialise hub, connecting to ftrack server_url.
api_user is the user to authenticate as and api_key is the API key to authenticate with.
cookies should be an optional mapping (dict) of key-value pairs specifying custom cookies that we need to pass in alongside the requests to the server.
headers should be an optional mapping (dict) of key-value pairs specifying custom headers that we need to pass in alongside the requests to the server.
- property secure
Return whether secure connection used.
- init_connection()[source]
If the connection is not handled synchronously the connection may be marked as initialized to allow for published events to be queued.
- connect()[source]
Initialise connection to server.
Raise
ftrack_api.exception.EventHubConnectionError
if already connected or connection fails.
- property connected
Return if connected.
- disconnect(unsubscribe=True, reconnect=False)[source]
Disconnect from server.
Raise
ftrack_api.exception.EventHubConnectionError
if not currently connected.If unsubscribe is True then unsubscribe all current subscribers automatically before disconnecting.
If reconnect is True we do not set connection_initialized to False so that we may queue up messages that are published while disconnected.
- reconnect(attempts=10, delay=5)[source]
Reconnect to server.
Make attempts number of attempts with delay in seconds between each attempt.
Note
All current subscribers will be automatically resubscribed after successful reconnection.
Raise
ftrack_api.exception.EventHubConnectionError
if fail to reconnect.
- wait(duration=None)[source]
Wait for events and handle as they arrive.
If duration is specified, then only process events until duration is reached. duration is in seconds though float values can be used for smaller values.
- get_subscriber_by_identifier(identifier)[source]
Return subscriber with matching identifier.
Return None if no subscriber with identifier found.
- subscribe(subscription, callback, subscriber=None, priority=100)[source]
Register callback for subscription.
A subscription is a string that can specify in detail which events the callback should receive. The filtering is applied against each event object. Nested references are supported using ‘.’ separators. For example, ‘topic=foo and data.eventType=Shot’ would match the following event:
<Event {'topic': 'foo', 'data': {'eventType': 'Shot'}}>
The callback should accept an instance of
ftrack_api.event.base.Event
as its sole argument.Callbacks are called in order of priority. The lower the priority number the sooner it will be called, with 0 being the first. The default priority is 100. Note that priority only applies against other callbacks registered with this hub and not as a global priority.
An earlier callback can prevent processing of subsequent callbacks by calling
Event.stop()
on the passed event before returning.Warning
Handlers block processing of other received events. For long running callbacks it is advisable to delegate the main work to another process or thread.
A callback can be attached to subscriber information that details the subscriber context. A subscriber context will be generated automatically if not supplied.
Note
The subscription will be stored locally, but until the server receives notification of the subscription it is possible the callback will not be called.
Return subscriber identifier.
Raise
ftrack_api.exception.NotUniqueError
if a subscriber with the same identifier already exists.
- unsubscribe(subscriber_identifier)[source]
Unsubscribe subscriber with subscriber_identifier.
Note
If the server is not reachable then it won’t be notified of the unsubscription. However, the subscriber will be removed locally regardless.
- publish(event, synchronous=False, on_reply=None, on_error='raise')[source]
Publish event.
If synchronous is specified as True then this method will wait and return a list of results from any called callbacks.
Note
Currently, if synchronous is True then only locally registered callbacks will be called and no event will be sent to the server. This may change in future.
on_reply is an optional callable to call with any reply event that is received in response to the published event.
Note
Will not be called when synchronous is True.
If on_error is set to ‘ignore’ then errors raised during publish of event will be caught by this method and ignored.