Jump to content

Multiple instance of Ftrack-Connect


Luigi

Recommended Posts

On 10/12/2017 at 10:36 AM, Mattias Lagergren said:

It is not possible to restrict it at the moment.

Way not?

On 10/12/2017 at 10:36 AM, Mattias Lagergren said:

Do you run them on the same machine

Yes, on the same machine with the same user.

 

This looks more like a bug. ftrack-connect should not start if it is already running on the same machine by the same user with the same ftrack URL.

Way would a user like to start the application 2 times?

Link to comment
Share on other sites

If there was a way for the event to return the hostname or ip of the browser from which an action is called you could at least verify on which machine the action is called. This doesn't solve the multiple instances on one machine issue, but for users logged in on multiple workstations you could at least filter out your custom hooks so only those available on that machine are discovered.

Link to comment
Share on other sites

Unfortunately there is no reliable way of detecting the machine from the browser, not in a way that can be re-created from python.

I've made a small plugin (see code below) that detects if there are multiple instances of Connect running for a user and pops up a message. If this functionality makes sense and you like it, we may bundle the plugin in Connect.

import logging
import socket
import functools

from QtExt import QtWidgets, QtCore

import ftrack_api
import ftrack_connect.util
import ftrack_connect.ui.application


logger = logging.getLogger(
    'multiple-instances-plugin'
)


def open_warning_dialog(message):
    '''Open warning window.'''
    parent = None
    for item in QtCore.QCoreApplication.instance().topLevelWidgets():
        if isinstance(item, ftrack_connect.ui.application.Application):
            parent = item

    dialog = QtWidgets.QMessageBox(parent=parent)
    dialog.setText(message)
    dialog.setIcon(QtWidgets.QMessageBox.Critical)
    dialog.exec_()


def handle_reply(event):
    '''Handle reply event if someone else is already running Connect.'''
    logger.warning('Someone else is already running connect: {0}'.format(event))
    ftrack_connect.util.invoke_in_main_thread(
        open_warning_dialog,
        u'ftrack Connect is already running on machine: {0}'.format(
            event['data']['machine']
        )
    )


def callback(event):
    '''Handle start of another connect.'''
    logger.warning('Someone just started ftrack Connect: {0}'.format(event))
    ftrack_connect.util.invoke_in_main_thread(
        functools.partial(
            open_warning_dialog,
            u'Connect just opened on machine: {0}'.format(
                event['data']['machine']
            )
        )
    )
    return {'machine': socket.gethostname()}


def register(session, **kw):
    '''Register hooks.'''
    logger.info(
        'Register detection of multiple Connect instances'
    )

    # Validate that session is an instance of ftrack_api.session.Session. If
    # not, assume that register is being called from an old or incompatible API
    # and return without doing anything.
    if not isinstance(session, ftrack_api.Session):
        logger.debug(
            'Not subscribing plugin as passed argument {0!r} is not an '
            'Session instance.'.format(session)
        )
        return

    session.event_hub.subscribe(
        'topic=studio.ftrack-connect.start and source.id != "{0}" and '
        'data.username = "{1}"'.format(
            session.event_hub.id, session._api_user
        ),
        callback
    )
    session.event_hub.publish(
        ftrack_api.event.base.Event(
            topic='studio.ftrack-connect.start',
            data={
                'username': session._api_user,
                'machine': socket.gethostname()
            }
        ),
        on_reply=handle_reply
    )

To use it create a folder detect-multi-instance/hook/ inside the ftrack connectp plugins folder, and add the code in a plugin.py (don't forget the hook/ folder). Restart Connect for the plugin to source.

This simple example could be extended with the ability to "quit" other instances of ftrack Connect.

Link to comment
Share on other sites

10 minutes ago, Mattias Lagergren said:

This simple example could be extended with the ability to "quit" other instances of ftrack Connect.

+1

Would this work for remote instances of Ftrack Connect as well?
Say you are logged into Ftrack Connect on two machines in different locations. Use case that was happened for me :)

Link to comment
Share on other sites

3 hours ago, tokejepsen said:

Would this work for remote instances of Ftrack Connect as well?
Say you are logged into Ftrack Connect on two machines in different locations. Use case that was happened for me :)

Yes, it is using the ftrack event hub service to do this. So it will work in different sites / locations.

Link to comment
Share on other sites

For reference, we have implemented the concept of a 'huddle' for event plugins that groups published events and listeners around unique discoverable huddle identifiers. 

So you can have multiple instances of an application such as Maya running for one user and be able to scope events to one particular instance. You can also discover all the available huddles dynamically and allow the user to interactively select between them. Seems to work well so far and greatly simplifies the scoping logic.

Link to comment
Share on other sites

  • 2 years later...

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
×
×
  • Create New...