From 7746abbbb7700fa918450101bbc6d29ed9b4b608 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Wed, 9 Nov 2022 22:29:33 -0700 Subject: Most of the way through the stator refactor --- stator/management/__init__.py | 0 stator/management/commands/__init__.py | 0 stator/management/commands/runstator.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 stator/management/__init__.py create mode 100644 stator/management/commands/__init__.py create mode 100644 stator/management/commands/runstator.py (limited to 'stator/management') diff --git a/stator/management/__init__.py b/stator/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/stator/management/commands/__init__.py b/stator/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/stator/management/commands/runstator.py b/stator/management/commands/runstator.py new file mode 100644 index 0000000..1307fef --- /dev/null +++ b/stator/management/commands/runstator.py @@ -0,0 +1,28 @@ +from typing import List, Type, cast + +from asgiref.sync import async_to_sync +from django.apps import apps +from django.core.management.base import BaseCommand + +from stator.models import StatorModel +from stator.runner import StatorRunner + + +class Command(BaseCommand): + help = "Runs a Stator runner for a short period" + + def add_arguments(self, parser): + parser.add_argument("model_labels", nargs="*", type=str) + + def handle(self, model_labels: List[str], *args, **options): + # Resolve the models list into names + models = cast( + List[Type[StatorModel]], + [apps.get_model(label) for label in model_labels], + ) + if not models: + models = StatorModel.subclasses + print("Running for models: " + " ".join(m._meta.label_lower for m in models)) + # Run a runner + runner = StatorRunner(models) + async_to_sync(runner.run)() -- cgit v1.2.3