import os # from celery.schedules import crontab from datetime import timedelta from celery import Celery from django.conf import settings # set the default Django settings module for the 'celery' program. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mfssogr.settings") app = Celery("mfssogr") # Using a string here means the worker doesn't have to serialize # the configuration object to child processes. # - namespace='CELERY' means all celery-related configuration keys # should have a `CELERY_` prefix. app.config_from_object("django.conf:settings", namespace="CELERY") # Load task modules from all registered Django app configs. app.autodiscover_tasks() @app.task(bind=True, ignore_result=True) def debug_task(self): print(f"Request: {self.request!r}") app.conf.enable_utc = False schedule_dict = { "apps.schedulers.tasks.load_earthquake": { # Получение данных по землятресениям "task": "apps.schedulers.tasks.load_earthquake", "schedule": timedelta( minutes=30 ), # change to `crontab(minute=0, hour=0)` if you want it to run daily at midnight }, "apps.schedulers.tasks.load_navigation": { # Получение данных по навигации "task": "apps.schedulers.tasks.load_navigation", "schedule": timedelta( seconds=60 ), # change to `crontab(minute=0, hour=0)` if you want it to run daily at midnight }, } if settings.TEST_CIRCUIT: schedule_dict["apps.schedulers.tasks.test_circuit"] = { "task": "apps.schedulers.tasks.test_circuit", "schedule": timedelta( seconds=30 ), } app.conf.beat_schedule = schedule_dict