@@ -29,20 +29,32 @@ class Command(BaseCommand):
2929 "Cron jobs are tasks that run automatically at specified intervals."
3030 )
3131
32- def handle (self , * args , ** kwargs ):
32+ def add_arguments (self , parser ):
33+ super ().add_arguments (parser )
34+ parser .add_argument (
35+ "--list" ,
36+ action = "store_true" ,
37+ help = "List the current scheduled cron jobs." ,
38+ )
39+
40+ def handle (self , * args , ** options ):
3341 if not settings .DEJACODE_ASYNC :
3442 self .stdout .write ("SYNC mode detected, skipping cron job setup." )
3543 sys .exit (0 )
3644
3745 scheduler = django_rq .get_scheduler ("default" )
3846
47+ if options ["list" ]:
48+ self .print_scheduled_jobs (scheduler )
49+ sys .exit (0 )
50+
3951 # Cancel all existing cron jobs in the scheduler.
4052 # This ensures that the cron entries are always up-to-date in case their
4153 # configuration has changed. It also prevents any duplicate or orphaned jobs
4254 # from remaining in the scheduler, maintaining a clean and accurate schedule.
4355 cancel_all_scheduled_jobs (scheduler )
4456
45- self .stdout .write ("Schedule vulnerabilities update" )
57+ self .stdout .write ("Schedule vulnerabilities update: " )
4658 forever = None
4759 scheduler .cron (
4860 cron_string = settings .DEJACODE_VULNERABILITIES_CRON , # 3am daily by default
@@ -54,6 +66,9 @@ def handle(self, *args, **kwargs):
5466 )
5567
5668 self .stdout .write (self .style .SUCCESS ("Successfully set up cron jobs." ))
69+ self .print_scheduled_jobs (scheduler )
70+
71+ def print_scheduled_jobs (self , scheduler ):
5772 self .stdout .write ("Scheduled jobs next execution:" )
5873 for job , scheduled_time in scheduler .get_jobs (with_times = True ):
5974 msg = f" > { job .description } in { naturaltime (scheduled_time )} ({ scheduled_time } )"
0 commit comments