Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure django-celery in heroku server

In my local environment i used celery for schedule task it works in local system i used redis as a worker now i want to configure django celery in heroku server i tried to use heroku-redis add-ons in heroku app

added this stuff in my settings.py:

r = redis.from_url(os.environ.get("REDIS_URL"))
BROKER_URL = redis.from_url(os.environ.get("REDIS_URL"))
CELERY_RESULT_BACKEND = os.environ.get('REDIS_URL')
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Canada/Eastern'

redis_url = urlparse.urlparse(os.environ.get('REDIS_URL'))
CACHES = {
"default": {
"BACKEND": "redis_cache.RedisCache",
"LOCATION": "{0}:{1}".format(redis_url.hostname, redis_url.port),
"OPTIONS": {
"PASSWORD": redis_url.password,
"DB": 0,
}
}
}

after in my procfile I added:

web: gunicorn bizbii.wsgi --log-file -
worker : celery workder -A tasks.app -l INFO
python manage.py celeryd -v 2 -B -s celery -E -l INFO

but still task does not run

After that I run command for log so it return:

2016-07-30T08:53:19+00:00 app[heroku-redis]: source=REDIS sample#active-connections=1 sample#load-avg-1m=0.07 sample#load-avg-5m=0.075 sample#load-avg-15m=0.07 sample#read-iops=0 sample#write-iops=0 sample#memory-total=15664876.0kB sample#memory-free=13426732.0kB sample#memory-cached=460140kB sample#memory-redis=299616bytes sample#hit-rate=1 sample#evicted-keys=0

after that create dyno with this command:

heroku run bash -a bizbii2

and run following command:

python manage.py celeryd -v 2 -B -s celery -E -l INFO

so it return error like:

[2016-08-03 08:23:26,506: ERROR/Beat] beat: Connection error: [Errno 111] Connection refused. Trying again in 8.0 seconds...
[2016-08-03 08:23:26,843: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.
Trying again in 8.00 seconds...

Please give me suggestion how we deploy celery on heroku server

like image 416
kartik Avatar asked Aug 02 '16 05:08

kartik


1 Answers

I had this exact problem. I updated my procfile with the following line and the error is gone:

worker: celery -A TASKFILE worker -B --loglevel=info

Replace TASKFILE with for example: proj.celery or proj.tasks. This depends on where you put the tasks.

like image 122
1GDST Avatar answered Nov 18 '22 00:11

1GDST