Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit the Event Daemon to specific projects #36

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.idea/
src/logs
docs/_build/doctrees
shotgunEventDaemon.conf
plugins
*.pyc
9 changes: 9 additions & 0 deletions src/shotgunEventDaemon.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ name: shotgunEventDaemon
# this random useless key with the one corresponding to the script you've setup.
key: 841c9a51bf45e1872c3e5f2435dade67458bc858

# Limits the events receiving by this event daemon to the comma delimited list
# defined in limit_to_projects. Should not used together with 'ignore_projects'.
limit_to_projects:

# Ignores events for projects defined in the comma delimited list ignore_projects.
# Should not be used together with 'limit_to_projects'.
ignore_projects:


# Sets the session_uuid from every event in the Shotgun instance to propagate in
# any events generated by plugins. This will allow the Shotgun UI to display
# updates that occur as a result of a plugin.
Expand Down
32 changes: 29 additions & 3 deletions src/shotgunEventDaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ def getEngineScriptName(self):
def getEngineScriptKey(self):
return self.get('shotgun', 'key')

def getEngineLimitToProjects(self):
project_list = [s.strip() for s in self.get('shotgun', 'limit_to_projects').split(',')]
return project_list if project_list[0] != '' else []

def getEngineIgnoreProjects(self):
project_list = [s.strip() for s in self.get('shotgun', 'ignore_projects').split(',')]
return project_list if project_list[0] != '' else []

def getEventIdFile(self):
return self.get('daemon', 'eventIdFile')

Expand Down Expand Up @@ -360,6 +368,8 @@ def _loadEventIdData(self):
self.log.debug('Read last event id (%d) from file.', lastEventId)
for collection in self._pluginCollections:
collection.setState(lastEventId)
except EOFError:
print "EOFERROR in pickle.load occured", fh.read()
fh.close()
except OSError, err:
raise EventDaemonError('Could not load event id from file.\n\n%s' % traceback.format_exc(err))
Expand Down Expand Up @@ -446,13 +456,14 @@ def _getNewEvents(self):
filters = [['id', 'greater_than', nextEventId - 1]]
fields = ['id', 'event_type', 'attribute_name', 'meta', 'entity', 'user', 'project', 'session_uuid']
order = [{'column':'id', 'direction':'asc'}]

conn_attempts = 0
while True:
try:
return self._sg.find("EventLogEntry", filters, fields, order, limit=self.config.getMaxEventBatchSize())
if events:
self.log.debug('Got %d events: %d to %d.', len(events), events[0]['id'], events[-1]['id'])
# This gets never fired as the function returns previously
# if events:
# self.log.debug('Got %d events: %d to %d.', len(events), events[0]['id'], events[-1]['id'])
except (sg.ProtocolError, sg.ResponseError, socket.error), err:
conn_attempts = self._checkConnectionAttempts(conn_attempts, str(err))
except Exception, err:
Expand Down Expand Up @@ -850,6 +861,21 @@ def __init__(self, callback, plugin, engine, shotgun, matchEvents=None, args=Non
self._logger.config = self._engine.config

def canProcess(self, event):

limit_to_projects = self._engine.config.getEngineLimitToProjects()
ignore_projects = self._engine.config.getEngineIgnoreProjects()

if 'project' in event and event['project'] is not None:
project_name = event['project'].get('name')
if limit_to_projects and project_name not in limit_to_projects:
msg = "Skipping event {0}. Ignored by engine configuration 'limit_to_projects' for project: {1}"
self._logger.debug(msg.format(event['id'], project_name))
return False
if project_name in ignore_projects:
msg = "Skipping event {0}. Ignored by engine configuration 'ignore_projects' for project: {1}"
self._logger.debug(msg.format(event['id'], project_name))
return False

if not self._matchEvents:
return True

Expand Down