import os

from celery import Celery
from celery.schedules import crontab

from postamates.settings import CELERY_BROKER_URL
from postamates.settings import CELERY_NAMESPACE
from postamates.settings import PROJECT_NAME

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'postamates.settings')
app = Celery(
    PROJECT_NAME, broker=CELERY_BROKER_URL,
    include=['service.tasks'], )

app.config_from_object('django.conf:settings', namespace=CELERY_NAMESPACE)
app.conf.beat_schedule = {
    'age_day_every_24h': {
        'task': 'service.tasks.add_age_day',
        'schedule': crontab(minute=0, hour=0),
    },
    'ml_func_every_24h': {
        'task': 'service.tasks.raschet',
        'schedule': crontab(minute=0, hour=0),
    },
}

app.autodiscover_tasks()
