From bc273f17cd8e08c6944660b8633ba41763f292b2 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Sun, 6 Jun 2021 14:33:41 +0300 Subject: Migrate Celery to RQ --- servo/management/commands/scheduler.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 servo/management/commands/scheduler.py (limited to 'servo/management/commands/scheduler.py') diff --git a/servo/management/commands/scheduler.py b/servo/management/commands/scheduler.py new file mode 100644 index 0000000..18018e5 --- /dev/null +++ b/servo/management/commands/scheduler.py @@ -0,0 +1,28 @@ +from datetime import datetime + +import django_rq +from django.core.management.base import BaseCommand +from django_rq.management.commands import rqscheduler + + +from servo.tasks import check_mail + + +scheduler = django_rq.get_scheduler('default') + + +class Command(rqscheduler.Command): + + help = "Start task scheduler" + + def handle(self, *args, **kwargs): + for job in scheduler.get_jobs(): + job.delete() + + scheduler.schedule( + scheduled_time=datetime.utcnow(), # Time for first execution, in UTC timezone + func=check_mail, # Function to be queued + interval=300, # Time before the function is called again, in seconds + ) + + super(Command, self).handle(*args, **kwargs) -- cgit v1.2.3