storagecelery.py 999 Bytes
Newer Older
Guba Sándor committed
1 2 3
from celery import Celery
from kombu import Queue, Exchange
from os import getenv
4 5 6 7 8 9 10 11 12 13 14 15 16 17
from argparse import ArgumentParser


parser = ArgumentParser()
parser.add_argument("-n", "--hostname", dest="hostname",
                    help="Define the full queue name with"
                    "with priority", metavar="hostname.queue.priority")
(args, unknwon_args) = parser.parse_known_args()
HOSTNAME = vars(args).pop("hostname")
if HOSTNAME is None:
    raise Exception("You must define hostname as -n <hostname> or "
                    "--hostname=<hostname>.\n"
                    "Hostname format must be hostname.module.priority.")

Guba Sándor committed
18 19
AMQP_URI = getenv('AMQP_URI')

Guba Sándor committed
20
celery = Celery('storagedriver',
Guba Sándor committed
21 22 23 24
                broker=AMQP_URI,
                include=['storagedriver'])

celery.conf.update(
25
    CELERY_RESULT_BACKEND='amqp',
Kálmán Viktor committed
26
    CELERY_TASK_RESULT_EXPIRES=300,
Guba Sándor committed
27
    CELERY_QUEUES=(
28
        Queue(HOSTNAME, Exchange(
Guba Sándor committed
29 30 31
            'storagedriver', type='direct'), routing_key='storagedriver'),
    )
)