test/mfssogr/celery.py
2025-06-09 12:11:53 +07:00

64 lines
2.0 KiB
Python

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(ignore_result=True)
def test_task():
print(f"Request")
return None
app.conf.enable_utc = True
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
},
"apps.schedulers.tasks.ping_plagroups": { # Проверка доступности вышек
"task": "apps.schedulers.tasks.ping_plagroups",
"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 = {}