@@ -29,23 +29,35 @@ class Command(BaseCommand):
29
29
"Cron jobs are tasks that run automatically at specified intervals."
30
30
)
31
31
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 ):
33
41
if not settings .DEJACODE_ASYNC :
34
42
self .stdout .write ("SYNC mode detected, skipping cron job setup." )
35
43
sys .exit (0 )
36
44
37
45
scheduler = django_rq .get_scheduler ("default" )
38
46
47
+ if options ["list" ]:
48
+ self .print_scheduled_jobs (scheduler )
49
+ sys .exit (0 )
50
+
39
51
# Cancel all existing cron jobs in the scheduler.
40
52
# This ensures that the cron entries are always up-to-date in case their
41
53
# configuration has changed. It also prevents any duplicate or orphaned jobs
42
54
# from remaining in the scheduler, maintaining a clean and accurate schedule.
43
55
cancel_all_scheduled_jobs (scheduler )
44
56
45
- self .stdout .write ("Schedule vulnerabilities update" )
57
+ self .stdout .write ("Schedule vulnerabilities update: " )
46
58
forever = None
47
59
scheduler .cron (
48
- cron_string = settings . DEJACODE_VULNERABILITIES_CRON , # 3am daily by default
60
+ cron_string = "*/2 * * * *" ,
49
61
func = update_vulnerabilities ,
50
62
result_ttl = 300 ,
51
63
repeat = forever ,
@@ -54,6 +66,9 @@ def handle(self, *args, **kwargs):
54
66
)
55
67
56
68
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 ):
57
72
self .stdout .write ("Scheduled jobs next execution:" )
58
73
for job , scheduled_time in scheduler .get_jobs (with_times = True ):
59
74
msg = f" > { job .description } in { naturaltime (scheduled_time )} ({ scheduled_time } )"
0 commit comments