Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a management command to run a configured periodic job immediately #8909

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions cvat/apps/engine/management/commands/runperiodicjob.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from argparse import ArgumentParser

from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.utils.module_loading import import_string


class Command(BaseCommand):
help = "Run a configured periodic job immediately"

def add_arguments(self, parser: ArgumentParser) -> None:
parser.add_argument("job_id", help="ID of the job to run")

def handle(self, *args, **options):
job_id = options["job_id"]

for job_definition in settings.PERIODIC_RQ_JOBS:
if job_definition["id"] == job_id:
job_func = import_string(job_definition["func"])
job_func()
return

raise CommandError(f"Job with ID {job_id} not found")
SpecLad marked this conversation as resolved.
Show resolved Hide resolved
SpecLad marked this conversation as resolved.
Show resolved Hide resolved
Loading