mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 13:52:15 +01:00
moved auto sync all projects directly to storer subprocess
This commit is contained in:
parent
b5b8b527d1
commit
45d4f4401b
2 changed files with 71 additions and 58 deletions
|
|
@ -1,58 +0,0 @@
|
|||
from pype.ftrack import BaseEvent
|
||||
|
||||
|
||||
class SyncAllAutoSyncProjects(BaseEvent):
|
||||
"""Trigger sychronization of each project where auto sync is set."""
|
||||
|
||||
def register(self):
|
||||
"""Registers the event, subscribing the discover and launch topics."""
|
||||
self.session.event_hub.subscribe(
|
||||
"topic=pype.storer.started",
|
||||
self.launch
|
||||
)
|
||||
|
||||
def launch(self, event):
|
||||
session = self.session
|
||||
projects = session.query("Project").all()
|
||||
if not projects:
|
||||
return False
|
||||
|
||||
selections = []
|
||||
for project in projects:
|
||||
if project["status"] != "active":
|
||||
continue
|
||||
|
||||
auto_sync = project["custom_attributes"].get("avalon_auto_sync")
|
||||
if not auto_sync:
|
||||
continue
|
||||
|
||||
selections.append({
|
||||
"entityId": project["id"],
|
||||
"entityType": "show"
|
||||
})
|
||||
|
||||
if not selections:
|
||||
return
|
||||
|
||||
user = session.query(
|
||||
"User where username is \"{}\"".format(session.api_user)
|
||||
).one()
|
||||
user_data = {
|
||||
"username": user["username"],
|
||||
"id": user["id"]
|
||||
}
|
||||
action_name = "sync.to.avalon.server"
|
||||
|
||||
for selection in selections:
|
||||
self.trigger_action(
|
||||
action_name,
|
||||
selection=[selection],
|
||||
user_data=user_data
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def register(session, plugins_presets={}):
|
||||
"""Register plugin. Called when used as an plugin."""
|
||||
SyncAllAutoSyncProjects(session, plugins_presets).register()
|
||||
|
|
@ -5,6 +5,7 @@ import signal
|
|||
import socket
|
||||
import pymongo
|
||||
|
||||
import ftrack_api
|
||||
from ftrack_server import FtrackServer
|
||||
from pype.ftrack.ftrack_server.lib import get_ftrack_event_mongo_info
|
||||
from pype.ftrack.lib.custom_db_connector import DbConnector
|
||||
|
|
@ -15,6 +16,13 @@ log = Logger().get_logger("Event storer")
|
|||
|
||||
url, database, table_name = get_ftrack_event_mongo_info()
|
||||
|
||||
|
||||
class SessionClass:
|
||||
def __init__(self):
|
||||
self.session = None
|
||||
|
||||
|
||||
session_obj = SessionClass()
|
||||
dbcon = DbConnector(
|
||||
mongo_url=url,
|
||||
database_name=database,
|
||||
|
|
@ -24,6 +32,7 @@ dbcon = DbConnector(
|
|||
# ignore_topics = ["ftrack.meta.connected"]
|
||||
ignore_topics = []
|
||||
|
||||
|
||||
def install_db():
|
||||
try:
|
||||
dbcon.install()
|
||||
|
|
@ -65,10 +74,71 @@ def launch(event):
|
|||
)
|
||||
|
||||
|
||||
def trigger_sync(event):
|
||||
session = session_obj.session
|
||||
if session is None:
|
||||
log.warning("Session is not set. Can't trigger Sync to avalon action.")
|
||||
return True
|
||||
|
||||
projects = session.query("Project").all()
|
||||
if not projects:
|
||||
return True
|
||||
|
||||
query = {
|
||||
"pype_data.is_processed": False,
|
||||
"topic": "ftrack.action.launch",
|
||||
"data.actionIdentifier": "sync.to.avalon.server"
|
||||
}
|
||||
set_dict = {
|
||||
"$set": {"pype_data.is_processed": True}
|
||||
}
|
||||
dbcon.update_many(query, set_dict)
|
||||
|
||||
selections = []
|
||||
for project in projects:
|
||||
if project["status"] != "active":
|
||||
continue
|
||||
|
||||
auto_sync = project["custom_attributes"].get("avalon_auto_sync")
|
||||
if not auto_sync:
|
||||
continue
|
||||
|
||||
selections.append({
|
||||
"entityId": project["id"],
|
||||
"entityType": "show"
|
||||
})
|
||||
|
||||
if not selections:
|
||||
return
|
||||
|
||||
user = session.query(
|
||||
"User where username is \"{}\"".format(session.api_user)
|
||||
).one()
|
||||
user_data = {
|
||||
"username": user["username"],
|
||||
"id": user["id"]
|
||||
}
|
||||
|
||||
for selection in selections:
|
||||
event_data = {
|
||||
"actionIdentifier": "sync.to.avalon.server",
|
||||
"selection": [selection]
|
||||
}
|
||||
session.event_hub.publish(
|
||||
ftrack_api.event.base.Event(
|
||||
topic="ftrack.action.launch",
|
||||
data=event_data,
|
||||
source=dict(user=user_data)
|
||||
),
|
||||
on_error="ignore"
|
||||
)
|
||||
|
||||
|
||||
def register(session):
|
||||
'''Registers the event, subscribing the discover and launch topics.'''
|
||||
install_db()
|
||||
session.event_hub.subscribe("topic=*", launch)
|
||||
session.event_hub.subscribe("topic=pype.storer.started", trigger_sync)
|
||||
|
||||
|
||||
def main(args):
|
||||
|
|
@ -85,6 +155,7 @@ def main(args):
|
|||
|
||||
try:
|
||||
session = StorerSession(auto_connect_event_hub=True, sock=sock)
|
||||
session_obj.session = session
|
||||
register(session)
|
||||
server = FtrackServer("event")
|
||||
log.debug("Launched Ftrack Event storer")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue