Skip to content

Commit ec2c7ed

Browse files
committed
Migrate from rq-scheduler to new built-in CronScheduler
Signed-off-by: tdruez <[email protected]>
1 parent a3435be commit ec2c7ed

11 files changed

+73
-277
lines changed

dejacode/settings.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,6 @@ def get_fake_redis_connection(config, use_strict_redis):
566566
"propagate": False,
567567
"level": DEJACODE_LOG_LEVEL,
568568
},
569-
"rq_scheduler.scheduler": {
570-
"handlers": ["null"] if IS_TESTS else ["console"],
571-
"propagate": False,
572-
"level": "DEBUG" if DEBUG else DEJACODE_LOG_LEVEL,
573-
},
574569
},
575570
}
576571

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# DejaCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: AGPL-3.0-only
5+
# See https://github.com/aboutcode-org/dejacode for support or download.
6+
# See https://aboutcode.org for more information about AboutCode FOSS projects.
7+
#
8+
9+
"""
10+
Management command to manage RQ CronScheduler instances.
11+
12+
Usage:
13+
./manage.py cronjobs # Start the cron scheduler
14+
"""
15+
16+
import sys
17+
18+
from django.conf import settings
19+
from django.core.management.base import BaseCommand
20+
21+
import django_rq
22+
from rq.cron import CronScheduler
23+
24+
25+
class Command(BaseCommand):
26+
help = (
27+
"Manage RQ CronScheduler instances. "
28+
"The CronScheduler enqueues jobs at regular intervals based on cron configuration."
29+
)
30+
31+
def handle(self, *args, **options):
32+
if not settings.DEJACODE_ASYNC:
33+
self.stdout.write("SYNC mode detected, cron scheduler is not needed.")
34+
sys.exit(0)
35+
36+
connection = django_rq.get_connection("default")
37+
self.start_scheduler(connection)
38+
39+
def start_scheduler(self, connection):
40+
"""Start the cron scheduler."""
41+
self.stdout.write(self.style.SUCCESS("Starting cron scheduler..."))
42+
self.stdout.write("(Press Ctrl+C to stop)")
43+
44+
cron = CronScheduler(connection=connection, logging_level="INFO")
45+
46+
# Register jobs
47+
cron.register(print, queue_name="default", cron="* * * * *")
48+
49+
# Start the scheduler (this will block until interrupted)
50+
try:
51+
cron.start()
52+
except KeyboardInterrupt:
53+
self.stdout.write(self.style.SUCCESS("\nShutting down cron scheduler..."))
54+
sys.exit(0)
55+
except Exception as e:
56+
self.stdout.write(self.style.ERROR(f"Error starting cron scheduler: {e}"))
57+
sys.exit(1)
58+
59+
60+
# self.stdout.write("Schedule vulnerabilities update:")
61+
# forever = None
62+
# scheduler.cron(
63+
# cron_string=settings.DEJACODE_VULNERABILITIES_CRON, # 3am daily by default
64+
# func=update_vulnerabilities,
65+
# result_ttl=300,
66+
# repeat=forever,
67+
# timeout="3h",
68+
# use_local_timezone=True,
69+
# )
70+
#
71+
# self.stdout.write(self.style.SUCCESS("Successfully set up cron jobs."))
72+
# self.print_scheduled_jobs(scheduler)

dje/management/commands/setupcron.py

Lines changed: 0 additions & 86 deletions
This file was deleted.

docker-compose.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ services:
6666

6767
scheduler:
6868
build: .
69-
command: wait-for-it web:8000 -- sh -c "
70-
./manage.py setupcron &&
71-
./manage.py rqscheduler --interval=600"
69+
command: wait-for-it web:8000 -- sh -c "./manage.py cronjobs"
7270
env_file:
7371
- docker.env
7472
volumes:

pyproject.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ dependencies = [
8484
"croniter==6.0.0",
8585
"django-rq==3.1.0",
8686
"fakeredis==2.32.1",
87-
# Scheduler
88-
"rq-scheduler==0.14.0",
89-
"crontab==1.0.5",
90-
"freezegun==1.5.2",
9187
# Libs
9288
"certifi==2025.11.12",
9389
"urllib3==2.5.0",
-21.4 KB
Binary file not shown.

thirdparty/dist/crontab-1.0.5.tar.gz.ABOUT

Lines changed: 0 additions & 150 deletions
This file was deleted.
-18.3 KB
Binary file not shown.

thirdparty/dist/freezegun-1.5.2-py3-none-any.whl.ABOUT

Lines changed: 0 additions & 15 deletions
This file was deleted.
-13.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)