from os import environ

from celery import Celery
from celery.schedules import crontab
from celery.utils.log import get_task_logger
from redis import Redis

logger = get_task_logger(__name__)

redis_host = environ.get('OMNOMNOM_REDIS_HOST') or 'localhost'
redis_port = environ.get('OMNOMNOM_REDIS_PORT') or 6379

cache_interval = environ.get('OMNOMNOM_CACHE_INTERVAL') or 60 * 60
cache_database = environ.get('OMNOMNOM_CACHE_DATABASE') or 0

celery_database = environ.get('OMNOMNOM_CELERY_DATABASE') or 1

cache = Redis(host=redis_host, port=redis_port, db=cache_database)
cache_date_format = '%Y-%m-%d'

app = Celery('backend',
             broker='redis://%s:%s/%s' % (redis_host, redis_port, celery_database),
             include=[
                 'canteens.cafenero',
                 'canteens.personalkantine',
                 'canteens.singh',
                 'canteens.studierendenwerk',
                 'omnomgram.tasks',
                 'stats.tasks'
             ]
             )
app.conf.timezone = 'Europe/Berlin'
app.conf.beat_schedule = {
    'update cafenero': {
        'task': 'canteens.cafenero.update_cafenero',
        'schedule': crontab(minute=3)
    },
    'update singh': {
        'task': 'canteens.singh.update_singh',
        'schedule': crontab(minute=3)
    },
    'update personalkantine': {
        'task': 'canteens.personalkantine.update_personalkantine',
        'schedule': crontab(minute=3)
    },
    'update en canteen': {
        'task': 'canteens.personalkantine.update_en_canteen',
        'schedule': crontab(minute=3)
    },
    'update studierendenwerk': {
        'task': 'canteens.studierendenwerk.update_all_studierendenwerk_canteens',
        'schedule': crontab(minute=3)
    }
}

if __name__ == '__main__':
    app.start()

from os import environ

from celery import Celery
from celery.schedules import crontab
from celery.utils.log import get_task_logger
from redis import Redis

logger = get_task_logger(__name__)

redis_host = environ.get('OMNOMNOM_REDIS_HOST') or 'localhost'
redis_port = environ.get('OMNOMNOM_REDIS_PORT') or 6379

cache_interval = environ.get('OMNOMNOM_CACHE_INTERVAL') or 60 * 60
cache_database = environ.get('OMNOMNOM_CACHE_DATABASE') or 0

celery_database = environ.get('OMNOMNOM_CELERY_DATABASE') or 1

refresh_minute = environ.get('OMNOMNOM_REFRESH_MINUTE') or 3
refresh_hour = environ.get('OMNOMNOM_REFRESH_HOUR') or '*/2'

cache = Redis(host=redis_host, port=redis_port, db=cache_database)
cache_date_format = '%Y-%m-%d'

app = Celery('backend',
             broker='redis://%s:%s/%s' % (redis_host, redis_port, celery_database),
             include=[
                 'canteens.cafenero',
                 'canteens.personalkantine',
                 'canteens.singh',
                 'canteens.studierendenwerk',
                 'omnomgram.tasks',
                 'stats.tasks'
             ]
             )
app.conf.timezone = 'Europe/Berlin'
app.conf.beat_schedule = {
    'update cafenero': {
        'task': 'canteens.cafenero.update_cafenero',
        'schedule': crontab(hour=refresh_hour, minute=refresh_minute)
    },
    'update singh': {
        'task': 'canteens.singh.update_singh',
        'schedule': crontab(hour=refresh_hour, minute=refresh_minute)
    },
    'update personalkantine': {
        'task': 'canteens.personalkantine.update_personalkantine',
        'schedule': crontab(hour=refresh_hour, minute=refresh_minute)
    },
    'update en canteen': {
        'task': 'canteens.personalkantine.update_en_canteen',
        'schedule': crontab(hour=refresh_hour, minute=refresh_minute)
    },
    'update studierendenwerk': {
        'task': 'canteens.studierendenwerk.update_all_studierendenwerk_canteens',
        'schedule': crontab(hour=refresh_hour, minute=refresh_minute)
    }
}

if __name__ == '__main__':
    app.start()

allow custom refresh times