start the django
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from rota.models import RotaSchedule
|
||||
from rota.services import run_rota_async
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Create a RotaRun for the given RotaSchedule id and start it in background."
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument("rota_id", type=int)
|
||||
parser.add_argument("--external", action="store_true", help="Use external generator hook if available")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
rota_id = options["rota_id"]
|
||||
use_external = options.get("external", False)
|
||||
try:
|
||||
rota = RotaSchedule.objects.get(pk=rota_id)
|
||||
except RotaSchedule.DoesNotExist:
|
||||
raise CommandError(f"RotaSchedule with id={rota_id} not found")
|
||||
|
||||
run = run_rota_async(rota.id, use_external_generator=use_external)
|
||||
self.stdout.write(self.style.SUCCESS(f"Started RotaRun id={run.id} for rota={rota.name}"))
|
||||
Reference in New Issue
Block a user