-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a new view CLI command for managing views
- Loading branch information
Showing
3 changed files
with
85 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import click | ||
|
||
from dataimporter.cli.utils import with_config, console | ||
from dataimporter.importer import DataImporter | ||
from dataimporter.lib.config import Config | ||
|
||
|
||
@click.group("view") | ||
def view_group(): | ||
pass | ||
|
||
|
||
@view_group.command("list") | ||
@with_config() | ||
def list_views(config: Config): | ||
""" | ||
List the name of all the views in current use. | ||
""" | ||
with DataImporter(config) as importer: | ||
console.log(", ".join(view.name for view in importer.views)) | ||
|
||
|
||
@view_group.command("flush") | ||
@click.argument("view", type=str) | ||
@with_config() | ||
def flush(view: str, config: Config): | ||
""" | ||
Flushes the given view's queue. | ||
For non-published views this should always be safe to do (but maybe think about it | ||
first, just to make sure) but for published views you should make sure you know what | ||
you're doing. | ||
""" | ||
with DataImporter(config) as importer: | ||
view = importer.get_view(view) | ||
console.log( | ||
f"Flushing {view.name} view queue, currently has", view.count(), "IDs in it" | ||
) | ||
view.flush() | ||
console.log(f"{view.name} flushed") | ||
|
||
|
||
@view_group.command("ingest") | ||
@click.argument("view", type=str) | ||
@click.option( | ||
"--everything", | ||
is_flag=True, | ||
show_default=True, | ||
default=False, | ||
help="Add all records to MongoDB regardless of whether they have changed. This is " | ||
"primarily useful when a change has been made to a view's filters or " | ||
"representation", | ||
) | ||
@with_config() | ||
def ingest(view: str, config: Config, everything: bool = False): | ||
""" | ||
On the given view, updates MongoDB with any queued EMu changes and flushes its | ||
queue. | ||
""" | ||
with DataImporter(config) as importer: | ||
console.log(f"Adding changes from {view} view to mongo") | ||
importer.add_to_mongo(view, everything=everything) | ||
console.log(f"Added changes from {view} view to mongo") | ||
|
||
|
||
@view_group.command("sync") | ||
@click.argument("view", type=str) | ||
@click.option( | ||
"--resync", | ||
is_flag=True, | ||
show_default=True, | ||
default=False, | ||
help="Resynchronise all data in Elasticsearch with MongoDB for this view, not just " | ||
"the records that have changed.", | ||
) | ||
@with_config() | ||
def sync(view: str, config: Config, resync: bool = False): | ||
""" | ||
Updates Elasticsearch with the changes in MongoDB for the given view. | ||
""" | ||
with DataImporter(config) as importer: | ||
console.log(f"Syncing changes from {view} view to elasticsearch") | ||
importer.sync_to_elasticsearch(view, resync=resync) | ||
console.log(f"Finished with {view}") |