mancelery.py 1.82 KB
Newer Older
1
from celery import Celery
2
from datetime import timedelta
3
from kombu import Queue, Exchange
Guba Sándor committed
4
from os import getenv
5

Guba Sándor committed
6
HOSTNAME = "localhost"
7
CACHE_URI = getenv("CACHE_URI", "pylibmc://127.0.0.1:11211/")
8

9
celery = Celery('manager',
Guba Sándor committed
10
                broker=getenv("AMQP_URI"),
11 12
                include=['vm.tasks.local_tasks',
                         'vm.tasks.local_periodic_tasks',
Bach Dániel committed
13
                         'vm.tasks.local_agent_tasks',
14
                         'storage.tasks.local_tasks',
15 16
                         'storage.tasks.periodic_tasks',
                         'firewall.tasks.local_tasks', ])
17 18

celery.conf.update(
19 20
    CELERY_RESULT_BACKEND='cache',
    CELERY_CACHE_BACKEND=CACHE_URI,
Őry Máté committed
21
    CELERY_TASK_RESULT_EXPIRES=300,
22
    CELERY_QUEUES=(
23 24
        Queue(HOSTNAME + '.man', Exchange('manager', type='direct'),
              routing_key="manager"),
25 26 27 28 29 30 31 32 33
        Queue(HOSTNAME + '.monitor', Exchange('monitor', type='direct'),
              routing_key="monitor"),
    ),
    CELERYBEAT_SCHEDULE={
        'firewall.periodic_task': {
            'task': 'firewall.tasks.local_tasks.periodic_task',
            'schedule': timedelta(seconds=5),
            'options': {'queue': 'localhost.man'}
        },
34
        'vm.update_domain_states': {
35 36 37 38
            'task': 'vm.tasks.local_periodic_tasks.update_domain_states',
            'schedule': timedelta(seconds=10),
            'options': {'queue': 'localhost.man'}
        },
39 40 41 42 43
        'vm.garbage_collector': {
            'task': 'vm.tasks.local_periodic_tasks.garbage_collector',
            'schedule': timedelta(minutes=10),
            'options': {'queue': 'localhost.man'}
        },
44 45 46 47 48
        'storage.periodic_tasks': {
            'task': 'storage.tasks.periodic_tasks.garbage_collector',
            'schedule': timedelta(hours=1),
            'options': {'queue': 'localhost.man'}
        },
49 50
    }

51
)