0

I have a Celery task that I run locally using celery -A tasks worker --loglevel=info or sometimes it runs on a live server.

@app.task
def example_task_calling_api():
      url = "http://127.0.0.1:8000/" 
      #  url = "http://www.example.com/api/"
      content = requests.get(url)
      #Do something with content etc

At the moment I uncomment the url depending on what environment I'm running.

My question is, how can I pass into celery settings or extra args that I can use to setup the correct URL?

PS... I DON'T mean passing args to a task i.e. Task(123) but somesort of system wide variable set upon starting celery.

i.e. celery -A tasks worker --loglevel=info -LOCALDEV

1 Answer 1

1

One way would be to set the url as an environmental variable, and use python os.environ to see if it is set and or set a default.

If you have multiple variables you'd like to config based on your env's: ie. demo, develop, production ect, you could use a python file and store all your varialbes in it. Then when your application starts up you could select the correct settings file based on a command line argument or from an env variable.

The above suggestion is how django framework handles your issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.