8000 Add the ability to list the current scheduled cron jobs #199 by tdruez · Pull Request #328 · aboutcode-org/dejacode · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add the ability to list the current scheduled cron jobs #199 #328

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

Merged
merged 2 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions dejacode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,11 @@ def get_fake_redis_connection(config, use_strict_redis):
"propagate": False,
"level": DEJACODE_LOG_LEVEL,
},
"rq_scheduler.scheduler": {
"handlers": ["null"] if IS_TESTS else ["console"],
"propagate": False,
"level": "DEBUG" if DEBUG else DEJACODE_LOG_LEVEL,
},
},
}

Expand Down
19 changes: 17 additions & 2 deletions dje/management/commands/setupcron.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,32 @@ class Command(BaseCommand):
"Cron jobs are tasks that run automatically at specified intervals."
)

def handle(self, *args, **kwargs):
def add_arguments(self, parser):
super().add_arguments(parser)
parser.add_argument(
"--list",
action="store_true",
help="List the current scheduled cron jobs.",
)

def handle(self, *args, **options):
if not settings.DEJACODE_ASYNC:
self.stdout.write("SYNC mode detected, skipping cron job setup.")
sys.exit(0)

scheduler = django_rq.get_scheduler("default")

if options["list"]:
self.print_scheduled_jobs(scheduler)
sys.exit(0)

# Cancel all existing cron jobs in the scheduler.
# This ensures that the cron entries are always up-to-date in case their
# configuration has changed. It also prevents any duplicate or orphaned jobs
# from remaining in the scheduler, maintaining a clean and accurate schedule.
cancel_all_scheduled_jobs(scheduler)

self.stdout.write("Schedule vulnerabilities update")
self.stdout.write("Schedule vulnerabilities update:")
forever = None
scheduler.cron(
cron_string=settings.DEJACODE_VULNERABILITIES_CRON, # 3am daily by default
Expand All @@ -54,6 +66,9 @@ def handle(self, *args, **kwargs):
)

self.stdout.write(self.style.SUCCESS("Successfully set up cron jobs."))
self.print_scheduled_jobs(scheduler)

def print_scheduled_jobs(self, scheduler):
self.stdout.write("Scheduled jobs next execution:")
for job, scheduled_time in scheduler.get_jobs(with_times=True):
msg = f" > {job.description} in {naturaltime(scheduled_time)} ({scheduled_time})"
Expand Down
0