You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have checked the commit log
to find out if the bug was already fixed in the main branch.
I have included all related issues and possible duplicate issues
in this issue (If there are none, check this box anyway).
Mandatory Debugging Information
I have included the output of celery -A proj report in the issue.
(if you are not able to do this, then at least specify the Celery
version affected).
I have verified that the issue exists against the main branch of Celery.
I have included the contents of pip freeze in the issue.
I have included all the versions of all the external dependencies required
to reproduce this bug.
Issue
While trying to connect my redis instance in Azure to my django celery instance, even after setting the correct backend and broker URL, they are not being used and is set to the default url of redis://redis:6379/0. The given below is the celery code i used in the django:
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
from django.conf import settings
from dotenv import load_dotenv
load_dotenv()
REDIS_ACCESS_KEY = os.getenv('REDIS_ACCESS_KEY')
REDIS_HOST = os.getenv('REDIS_HOST')
REDIS_PORT = os.getenv('REDIS_PORT')
REDIS_DB = os.getenv('REDIS_DB')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TestProject.settings')
broker_url = f'rediss://:{REDIS_ACCESS_KEY}@{REDIS_HOST}:{REDIS_PORT}/{REDIS_DB}?ssl_cert_reqs=required'
result_backend = f'rediss://:{REDIS_ACCESS_KEY}@{REDIS_HOST}:{REDIS_PORT}/{REDIS_DB}?ssl_cert_reqs=required'
print(f"broker_url: {broker_url}")
print(f"result_backend: {result_backend}")
settings.CELERY_BROKER_URL = broker_url
settings.CELERY_RESULT_BACKEND = result_backend
app = Celery('TestProject',
broker=broker_url,
backend=result_backend,
include=['ReservationManager.tasks'],
queue='central',
timezone='Asia/Kolkata',
broker_heartbeat=10,
backend_heartbeat=10,
broker_connection_max_retries=100,
broker_connection_timeout=30,
broker_connection_retry=True
)
# app.config_from_object("django.conf:settings")
print(f"CELERY_BROKER_URL: {app.conf.broker_url}")
print(f"CELERY_RESULT_BACKEND: {app.conf.result_backend}")
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(name='ping_central')
def ping_central_server():
"""
This function is used to test the celery task in the main server.
"""
return {'status': 'pong'}
i have commented the app.config_from_object("django.conf:settings") as im using all the neccessary configs in this file itself. But my debug results is showing that the URLs i have provided are not being used and instead the default one is being used:
celery -A TestProject worker -l info broker_connection_retry_on_startup=True
broker_url: rediss://:<access_key>@<host>/0?ssl_cert_reqs=required
result_backend: rediss://:<access_key>@<host>/0?ssl_cert_reqs=required
CELERY_BROKER_URL: redis://redis:6379/0
CELERY_RESULT_BACKEND: redis://redis:6379/0
-------------- celery@s-suryan-82FG v5.3.6 (emerald-rush)
--- ***** -----
-- ******* ---- Linux-6.5.0-26-generic-x86_64-with-glibc2.38 2024-04-01 22:19:24
- *** --- * ---
- ** ---------- [config]
- ** ---------- .> app: TestProject:0x7d281bc1d550
- ** ---------- .> transport: redis://redis:6379/0
- ** ---------- .> results: redis://redis:6379/0
- *** --- * --- .> concurrency: 8 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
-------------- [queues]
.> celery exchange=celery(direct) key=celery
[tasks]
. ping_central
[2024-04-01 22:19:26,933: ERROR/MainProcess] consumer: Cannot connect to redis://redis:6379/0: Error -3 connecting to redis:6379. Temporary failure in name resolution..
Trying again in 2.00 seconds... (1/100)
I tried many ways to assign the values of the broker and backend URL. eventually i created another python file outside of the django project with this code:
from celery import Celery
broker_url = rediss://:<access_key>@<host>/0?ssl_cert_reqs=required
result_backend = rediss://:<access_key>@<host>/0?ssl_cert_reqs=required
app = Celery(
broker_url=broker_url,
backend=result_backend,
queue='micro1',
timezone='Asia/Kolkata',
broker_heartbeat=10,
backend_heartbeat=10,
broker_connection_max_retries=100,
broker_connection_timeout=30,
broker_connection_retry=True,
broker_pool_limit=10000,
broker_connection_retry_on_startup=True
)
@app.task(name='test')
def test(x, y):
print('The sum received is {}'.format(x + y))
return x + y
surprisingly this worked perfectly fine. And this is the debug info:
I have tried avoiding naming the env variables as CELERY_BROKER_URL CELERY_RESULT_BACKEND
or any such variables which are present in Setting configuration. This worked
I have tried avoiding naming the env variables as CELERY_BROKER_URLCELERY_RESULT_BACKEND or any such variables which are present in Setting configuration. This worked
Thank you @aayushostwal , the error I was getting was similar except I had a similar variable in my .env file. Since both the .env and settings had the same variable, the one from the env was used. Took a long time until I realised the issue. .so that solved the issue.
Checklist
main
branch of Celery.contribution guide
on reporting bugs.
for similar or identical bug reports.
for existing proposed fixes.
to find out if the bug was already fixed in the main branch.
in this issue (If there are none, check this box anyway).
Mandatory Debugging Information
celery -A proj report
in the issue.(if you are not able to do this, then at least specify the Celery
version affected).
main
branch of Celery.pip freeze
in the issue.to reproduce this bug.
Issue
While trying to connect my redis instance in Azure to my django celery instance, even after setting the correct backend and broker URL, they are not being used and is set to the default url of
redis://redis:6379/0
. The given below is the celery code i used in the django:i have commented the
app.config_from_object("django.conf:settings")
as im using all the neccessary configs in this file itself. But my debug results is showing that the URLs i have provided are not being used and instead the default one is being used:I tried many ways to assign the values of the broker and backend URL. eventually i created another python file outside of the django project with this code:
surprisingly this worked perfectly fine. And this is the debug info:
i tried printing the env values in the django side program and everything is working fine. But dont know why its going back to using the default URL.
this is the dependecy details:
The text was updated successfully, but these errors were encountered: