Don't break if a backend is missing

This commit is contained in:
Adrian Moennich 2014-11-13 12:22:45 +01:00
parent 03cdb34c0e
commit 5ec5e419e2
2 changed files with 14 additions and 1 deletions

View File

@ -54,7 +54,11 @@ def agents():
for agent in agent_list:
initial = (cformat('%{green!}done%{reset}') if agent.initial_data_exported else
cformat('%{yellow!}pending%{reset}'))
table_data.append([unicode(agent.id), agent.name, agent.backend.title, initial, unicode(agent.queue.count())])
if agent.backend is None:
backend_title = cformat('%{red!}invalid backend ({})%{reset}').format(agent.backend_name)
else:
backend_title = agent.backend.title
table_data.append([unicode(agent.id), agent.name, backend_title, initial, unicode(agent.queue.count())])
table = AsciiTable(table_data)
table.justify_columns[4] = 'right'
print table.table
@ -74,6 +78,9 @@ def initial_export(agent_id, force=False):
if agent is None:
print 'No such agent'
return
if agent.backend is None:
print cformat('Cannot run agent %{red!}{}%{reset} (backend not found)').format(agent.name)
return
print cformat('Selected agent: %{white!}{}%{reset} ({})').format(agent.name, agent.backend.title)
if agent.initial_data_exported and not force:
print 'The initial export has already been performed for this agent.'
@ -127,6 +134,9 @@ def run(agent_id=None):
agent_list = [agent]
for agent in agent_list:
if agent.backend is None:
print cformat('Skipping agent: %{red!}{}%{reset} (backend not found)').format(agent.name)
continue
if not agent.initial_data_exported:
print cformat('Skipping agent: %{red!}{}%{reset} (initial export not performed)').format(agent.name)
continue

View File

@ -41,6 +41,9 @@ class LiveSyncTask(PeriodicUniqueTask):
plugin = LiveSyncPlugin.instance # RuntimeError if not active
with plugin.plugin_context():
for agent in LiveSyncAgent.find_all():
if agent.backend is None:
self.logger.warning('Skipping agent {}; backend not found'.format(agent.name))
continue
if not agent.initial_data_exported:
self.logger.warning('Skipping agent {}; initial export not performed yet'.format(agent.name))
continue