From dfe8f2c60bcf5e54edf8215c26f76f65704f26d6 Mon Sep 17 00:00:00 2001 From: Adrian Moennich Date: Wed, 28 Jul 2021 11:18:10 +0200 Subject: [PATCH] LiveSync: Add enqueue cli --- livesync/README.md | 4 +++ livesync/indico_livesync/cli.py | 45 +++++++++++++++++++++++++++++++++ livesync/setup.cfg | 2 +- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/livesync/README.md b/livesync/README.md index 3f41c81..3199e53 100644 --- a/livesync/README.md +++ b/livesync/README.md @@ -5,6 +5,10 @@ external services, typically to provide advanced search functionality. ## Changelog +### 3.0.1 + +- Add `indico livesync enqueue` CLI to manually add queue entries + ### 3.0 - Initial release for Indico 3.0 diff --git a/livesync/indico_livesync/cli.py b/livesync/indico_livesync/cli.py index 81472ee..01f170d 100644 --- a/livesync/indico_livesync/cli.py +++ b/livesync/indico_livesync/cli.py @@ -20,6 +20,8 @@ from indico.core.db import db from indico.util.console import cformat from indico_livesync.models.agents import LiveSyncAgent +from indico_livesync.models.queue import ChangeType, EntryType, LiveSyncQueueEntry +from indico_livesync.util import get_excluded_categories, obj_ref @cli_group(name='livesync') @@ -201,3 +203,46 @@ def reset(agent_id): db.session.commit() print(cformat('Reset complete; run %{green!}indico livesync initial-export {}%{reset} for a new export') .format(agent.id)) + + +@cli.command() +@click.option('--type', '-t', + type=click.Choice(EntryType.__members__), + callback=lambda c, p, v: getattr(EntryType, v) if v else None, + default='event', + help='The object type (default: event)') +@click.option('--change', '-c', + type=click.Choice(ChangeType.__members__), + callback=lambda c, p, v: getattr(ChangeType, v) if v else None, + default='protection_changed', + help='The change type (default: protection_changed)') +@click.argument('ids', nargs=-1, type=int, metavar='ID...') +def enqueue(type, change, ids): + """Adds the given objects to the LiveSync queues. + + This is intended to be used if a change was not recorded by LiveSync + for some reason and you want to manually force an update. Note that + enqueuing a deletion for something that is not deleted may be + dangerous and can cause agent runs to fail. + + By default this util uses the `protection_changed` change type since + that way it cascades to all child objects when used on anything except + categories. + """ + + model = { + EntryType.category: db.m.Category, + EntryType.event: db.m.Event, + EntryType.contribution: db.m.Contribution, + EntryType.subcontribution: db.m.SubContribution, + EntryType.session: db.m.Session, + EntryType.note: db.m.EventNote, + EntryType.attachment: db.m.Attachment, + }[type] + + objs = model.query.filter(model.id.in_(ids)).all() + excluded_categories = get_excluded_categories() + for obj in objs: + click.echo(f'Enqueuing {obj}') + LiveSyncQueueEntry.create({change}, obj_ref(obj), excluded_categories=excluded_categories) + db.session.commit() diff --git a/livesync/setup.cfg b/livesync/setup.cfg index fdbdb8a..8001de9 100644 --- a/livesync/setup.cfg +++ b/livesync/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = indico-plugin-livesync -version = 3.0 +version = 3.0.1 description = Framework for pushing Indico event data to external services long_description = file: README.md long_description_content_type = text/markdown; charset=UTF-8; variant=GFM