def run(agent_id, force=False): """Runs the livesync agent""" if agent_id is None: agent_list = LiveSyncAgent.query.all() else: agent = LiveSyncAgent.get(agent_id) if agent is None: print('No such agent') return 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 and not force: print(cformat('Skipping agent: %{red!}{}%{reset} (initial export not performed)').format(agent.name)) continue print(cformat('Running agent: %{white!}{}%{reset}').format(agent.name)) try: agent.create_backend().run() db.session.commit() except Exception: db.session.rollback() raise
def initial_export(agent_id, force): """Performs the initial data export for an agent""" agent = LiveSyncAgent.get(agent_id) 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.') print(cformat('To re-run it, use %{yellow!}--force%{reset}')) return agent.create_backend().run_initial_export(Event.query.filter_by(is_deleted=False)) agent.initial_data_exported = True db.session.commit()
def reset(agent_id): """Resets all livesync data for an agent.""" agent = LiveSyncAgent.get(agent_id) 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 backend = agent.create_backend() reset_allowed, message = backend.check_reset_status() if not reset_allowed: print(f'Resetting is not possible: {message}') return print(cformat('Selected agent: %{white!}{}%{reset} ({})').format(agent.name, backend.title)) print(cformat('%{yellow!}!!! %{red!}DANGER %{yellow!}!!!%{reset}')) if backend.reset_deletes_indexed_data: print(cformat('%{yellow!}This command will delete all indexed data on this backend.%{reset}') .format(backend.title)) else: print(cformat('%{yellow!}This command should only be used if the data on this backend ' 'has been deleted.%{reset}') .format(backend.title)) print(cformat('%{yellow!}After resetting you need to perform a new initial export.%{reset}')) click.confirm(click.style('Do you really want to perform the reset?', fg='red', bold=True), default=False, abort=True) if not config.DEBUG: click.confirm(click.style('Are you absolutely sure?', fg='red', bold=True), default=False, abort=True) for i in range(5): print(cformat('\rResetting in %{white!}{}%{reset}s (CTRL+C to abort)').format(5 - i), end='') time.sleep(1) print('') backend.reset() db.session.commit() print(cformat('Reset complete; run %{green!}indico livesync initial-export {}%{reset} for a new export') .format(agent.id))
def initial_export(agent_id, batch, force, verbose, retry): """Performs the initial data export for an agent.""" agent = LiveSyncAgent.get(agent_id) 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)) backend = agent.create_backend() if not backend.is_configured(): print(cformat('Agent %{red!}{}%{reset} is not properly configured').format(agent.name)) return if agent.initial_data_exported and not force: print('The initial export has already been performed for this agent.') print(cformat('To re-run it, use %{yellow!}--force%{reset}')) return try: if not backend.run_initial_export(batch, force, verbose): print('The initial export failed; not marking it as done') return except Exception: if not retry: raise traceback.print_exc() print('Restarting in 2 seconds') time.sleep(2) os.execl(sys.argv[0], *sys.argv) return # exec doesn't return but just in case... agent.initial_data_exported = True db.session.commit()
def run(agent_id, force, verbose, allowed_categories): """Runs the livesync agent.""" from indico_livesync.plugin import LiveSyncPlugin if LiveSyncPlugin.settings.get('disable_queue_runs'): print(cformat('%{yellow!}Queue runs are disabled%{reset}')) if LiveSyncPlugin.settings.get('skip_category_changes'): print(cformat('%{yellow!}Category changes are currently being skipped%{reset}')) if allowed_categories: print(cformat('Whitelisted categories: %{green}{}%{reset}') .format(', '.join(map(str, sorted(allowed_categories))))) if agent_id is None: agent_list = LiveSyncAgent.query.all() else: agent = LiveSyncAgent.get(agent_id) if agent is None: print('No such agent') return 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 backend = agent.create_backend() queue_allowed, reason = backend.check_queue_status() if not queue_allowed and not force: print(cformat('Skipping agent: %{red!}{}%{reset} ({})').format(agent.name, reason)) continue print(cformat('Running agent: %{white!}{}%{reset}').format(agent.name)) try: backend.run(verbose, from_cli=True, allowed_categories=allowed_categories) db.session.commit() except Exception: db.session.rollback() raise