forked from cvat-ai/cvat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a management command to run a configured periodic job immediately (…
…cvat-ai#8909) This can be useful for testing.
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 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
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") |