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)
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() # словарь
return response
def streams_tasks(scheduler):
scheduler.schedule(
scheduled_time=datetime.utcnow(),
func=new_checks,
interval=2, # в секундах
)