How to use django-rq and rq_scheduler to run recurring tasks?

If You used django-rq and rq_scheduler to run recurring tasks, give me an example of your code. I would be very grateful.
apps.py
import sys

from django.apps import AppConfig
from django_rq import get_scheduler


class PrinterAppConfig(AppConfig):
 name = 'printer_app'

 def ready(self):
 from printer_app.async_tasks import streams_tasks

 if "rqscheduler" not in sys.argv:
return

 scheduler = get_scheduler('print_check')

 for job in scheduler.get_jobs():
job.delete()

 streams_tasks(scheduler)

async_tasks.py
import django_rq
import requests
from django_rq import job

from datetime import datetime, timedelta

from checks.models import Printer, Check


def new_checks():
 url = 'http://127.0.0.1:8000/new_checks/'
 headers = {'Api-Token': '0796859f206682d5fb185bcda09f0fa5',
 'Api-Secret-Key': 'P2jg8WASSok8'}

 response = requests.get(url, headers=headers).json() # dictionary
 return response


def streams_tasks(scheduler):
scheduler.schedule(
scheduled_time=datetime.utcnow(),
func=new_checks,
 interval=1, # in seconds
 )

March 19th 20 at 09:01
2 answers
March 19th 20 at 09:03
Solution
python-rq used for background processing, but periodic job with this cron cope more than fine. Nor see any reason to bother. Write your own manage.py the team and all, nothing more is required
March 19th 20 at 09:05
Solution
I had planned to run the task every 2 seconds. This would have to indicate 2 intervals. The first interval is how often the scheduler checks for Redis and sends scheduled jobs to the correct queues. And the 2nd interval is how often the task should run. To be sure that the task runs at the right time, you need to make sure that the 1st interval is less than or equal to the 2nd and is also the divider. To start using django_rq, run the commands manage.py rqscheduler --interval 1
apps.py
import sys

from django.apps import AppConfig
from django_rq import get_scheduler


class PrinterAppConfig(AppConfig):
 name = 'printer_app'

 def ready(self):
 from printer_app.async_tasks import streams_tasks

 if "rqscheduler" not in sys.argv:
return

 scheduler = get_scheduler('print_check', interval=1)

 for job in scheduler.get_jobs():
job.delete()

 streams_tasks(scheduler)

async_tasks.py
import django_rq
import requests
from django_rq import job

from datetime import datetime, timedelta

from checks.models import Printer, Check


def new_checks():
 url = 'http://127.0.0.1:8000/new_checks/'
 headers = {'Api-Token': '0796859f206682d5fb185bcda09f0fa5',
 'Api-Secret-Key': 'P2jg8WASSok8'}

 response = requests.get(url, headers=headers).json() # dictionary
 return response


def streams_tasks(scheduler):
scheduler.schedule(
scheduled_time=datetime.utcnow(),
func=new_checks,
 interval=2, # in seconds
 )

Find more questions by tags Django