Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use environment variables to make Celery worker connect to a different worker?

Tags:

docker

celery

I'm starting Celery worker in the way described by the manual...

$ stoneid salimfadhley$ celery worker

 -------------- [email protected] v4.2.1 (windowlicker)
---- **** ----- 
--- * ***  * -- Darwin-18.2.0-x86_64-i386-64bit 2018-11-13 14:00:20
-- * - **** --- 
- ** ---------- [config]
- ** ---------- .> app:         default:0x10fb4ee48 (.default.Loader)
- ** ---------- .> transport:   amqp://guest:**@localhost:5672//
- ** ---------- .> results:     disabled://
- *** --- * --- .> concurrency: 8 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery


[2018-11-13 14:00:21,065: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 61] Connection refused.
Trying again in 2.00 seconds...

Can I provide some configuration (preferably via an environment variable) so that the worker connects to a different broker address?

According to the manual, I can use the -b flag to specify a broker URL via a command line, and I can wrap the worker in a script which pulls the environment variable and stuffs it into the command line argument of celery worker... but can I bypass this? Is there an environment variable I can set which the worker will pick up?

I'm actually running this inside a Docker container - the easiest way to provide this information would be as an environment variable.

like image 412
Salim Fadhley Avatar asked Sep 02 '25 13:09

Salim Fadhley


1 Answers

The majority of the settings can be set via env vars. The naming convention is prefix with CELERY_ and then uppercase the setting name.

In this case the setting is broker_url, therefore the env var is CELERY_BROKER_URL.

like image 107
Bjorn Stiel Avatar answered Sep 05 '25 15:09

Bjorn Stiel