R
Railway13mo ago
Malay

Celery worker is not getting connected with Redis broker.

code in settings.py CELERY_BACKEND_URL = getenv('REDIS_URL') CELERY_BROKER_URL = getenv('REDIS_URL') CELERY_ACCEPT_CONTENT = ['json'] CELERY_TASK_SERIALIZER = 'json' CELERY_RESULT_SERIALIZER = 'json' celery.py (as sibling as settings.py) import os from celery import Celery from django.conf import settings os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') app = Celery('core') app.config_from_object('django.conf:settings', namespace='CELERY') app.autodiscover_tasks() @app.task(bind=True, ignore_result=True) def debug_task(self): print(f'Request: {self.request!r}') init.py (as sibling as settings.py) from .celery import app as celery_app __all__ = ('celery_app',)
No description
No description
115 Replies
Percy
Percy13mo ago
Project ID: N/A
Malay
Malay13mo ago
Project ID: 286dccfe-bf85-48fe-ae80-ab24c5a80716 Project ID: 286dccfe-bf85-48fe-ae80-ab24c5a80716
Brody
Brody13mo ago
are you using the private network?
Malay
Malay13mo ago
I think yes
No description
Brody
Brody13mo ago
right but are you actually utilizing it
Malay
Malay13mo ago
How do I do that?? I have set engvironment variable like this REDIS_URL=${{Redis.REDIS_URL}}
Brody
Brody13mo ago
disable private networking, and then redeploy
Malay
Malay13mo ago
do I need to re-enable it??
Brody
Brody13mo ago
no
Malay
Malay13mo ago
I disabled it. But, It didn;t work
No description
Malay
Malay13mo ago
its the same as before
Brody
Brody13mo ago
can you connect to redis with redis-cli?
Malay
Malay13mo ago
yes I can connnect
No description
Brody
Brody13mo ago
can you show me how you have disabled private networking?
Malay
Malay13mo ago
No description
Malay
Malay13mo ago
like this
Brody
Brody13mo ago
can you show me a screenshot of your service variables
Malay
Malay13mo ago
sure
Malay
Malay13mo ago
No description
Malay
Malay13mo ago
I copy pasted the redis url from the redis connection section Initially I had added like this ${{Redis.REDIS_URL}}
Brody
Brody13mo ago
this is what it should be, please put it back to that
Malay
Malay13mo ago
but It was n;t working then I can try again
Malay
Malay13mo ago
similar errors
No description
Malay
Malay13mo ago
Here is my docker file FROM python:3.10 ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 WORKDIR /app COPY . /app/ RUN apt-get update && apt-get install -y \ build-essential \ libpoppler-cpp-dev \ pkg-config \ python3-dev \ supervisor \ && apt-get clean RUN pip install --no-cache-dir -r requirements.txt RUN useradd -ms /bin/bash myuser RUN chown -R myuser:myuser /app/ COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf USER myuser CMD python manage.py collectstatic --noinput && python manage.py migrate && supervisord -c /etc/supervisor/conf.d/supervisord.conf here is the supervisord.conf [supervisord] nodaemon=true [program:celery] command=celery -A core worker --loglevel=info stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 [program:gunicorn] command=gunicorn core.wsgi:application stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 do you think I have made any mistake in these files??
Brody
Brody13mo ago
okay my recommendation going forward would be to use nixpacks and use two railway services, one for gunicorn and one for celery so get rid of the dockerfile, add another railway service to your project, In the service settings set the start command to the start command needed for celery, and in the current service have a Procfile with the gunicorn start command so much simpler without a dependency on supervisord
Malay
Malay13mo ago
OK let me try that
Brody
Brody13mo ago
I could break it down into discrete steps at a high level if that would be slightly more helpful? but keep in mind I haven't done this exact thing, so I only have a high level understanding on the general steps you need to take, like the ones I've previously given
Malay
Malay13mo ago
Let me try If I fail I will ask you questions here. Is that okay?
Brody
Brody13mo ago
for sure! might be worth mentioning that both of these services should be setup to deploy from the same repo and same branch
Malay
Malay13mo ago
I need to run apt-get update && apt-get install -y \ build-essential \ libpoppler-cpp-dev \ pkg-config \ python3-dev \ && apt-get clean before I install packages from run requirements.txt. How can I achie3ve that here is proc file: web: python manage.py collectstatic --noinput && python manage.py migrate && gunicorn core.wsgi:application worker: celery -A core worker --loglevel=info
Brody
Brody13mo ago
are you building with a dockerfile?
Malay
Malay13mo ago
no procfile like you had suggested
Brody
Brody13mo ago
gotcha
Malay
Malay13mo ago
No description
Brody
Brody13mo ago
railway does not support a worker process in the procfile do you have two railway services in your project?
Malay
Malay13mo ago
yes
Brody
Brody13mo ago
and do you have custom start commands set in each service?
Malay
Malay13mo ago
no deployment failed in both as some of my packages are dependent on apt-get update && apt-get install -y \ build-essential \ libpoppler-cpp-dev \ pkg-config \ python3-dev \ && apt-get clean this
Brody
Brody13mo ago
are both of your services deploying from the same repo
Malay
Malay13mo ago
I dont have ustom start command in either service
Brody
Brody13mo ago
you said that already lol
Malay
Malay13mo ago
Yes
Brody
Brody13mo ago
do both of these services have the same service variables
Malay
Malay13mo ago
It wasn't same. I made them same. And redeploying.
Brody
Brody13mo ago
but its good that they are the same now
Malay
Malay13mo ago
They are the exact same now
Brody
Brody13mo ago
remove the worker line in your procfile in the service that you want to have run celery set a custom start command in the service settings in the service that you want to run django, dont set a start command, the web command from the procfile will be used as the start command
Malay
Malay13mo ago
remove the worker line from procfiel deploying right now
Brody
Brody13mo ago
show me your new procfile, and show me what start command you set in the celery service please
Malay
Malay13mo ago
I haven;t added the start command I have remove the worker command from procfiel
Malay
Malay13mo ago
No description
Malay
Malay13mo ago
What should be the start command?
Brody
Brody13mo ago
the command you use to start celery
Malay
Malay13mo ago
celery -A core worker --loglevel=info this??
Brody
Brody13mo ago
is that the command you use to start celery?
Malay
Malay13mo ago
Yes Yes
Brody
Brody13mo ago
then yes show me what start command you set in the celery service?
Malay
Malay13mo ago
for django app
No description
Malay
Malay13mo ago
for celery
No description
Brody
Brody13mo ago
looks good to me so far now to install those apt packages add a nixpacks.toml file to your project with this in it
[phases.setup]
aptPkgs = ['...', 'build-essential', 'libpoppler-cpp-dev', 'pkg-config', 'python3-dev']
[phases.setup]
aptPkgs = ['...', 'build-essential', 'libpoppler-cpp-dev', 'pkg-config', 'python3-dev']
Malay
Malay13mo ago
okay
Malay
Malay13mo ago
does it look okay?
No description
Brody
Brody13mo ago
yes
Malay
Malay13mo ago
Okay deploying
Malay
Malay13mo ago
the build failed
Brody
Brody13mo ago
remove the build command from the django service
Malay
Malay13mo ago
this is the celery service, it did not have the command but still failed
No description
Malay
Malay13mo ago
removed
Brody
Brody13mo ago
lets focus on one thing at a time, if the django service still fails to build, send me the logs
Malay
Malay13mo ago
okay
Malay
Malay13mo ago
Brody
Brody13mo ago
are you using pdftotext?
Malay
Malay13mo ago
Yes for this package I need the apt packages
Brody
Brody13mo ago
well as silly as it may sound, i think we should go back to your single service and dockerfile, nixpacks isnt properly installing those apt packages
Malay
Malay13mo ago
Okay. doing it right away
Brody
Brody13mo ago
sorry to ask you to do all that and then just ask you to go back to what you had
Malay
Malay13mo ago
No thank you very much for helping out a noobie like me
Malay
Malay13mo ago
here is the dockefile and supervisord.conf
No description
No description
Malay
Malay13mo ago
SHould I deploy it??
Brody
Brody13mo ago
your cmd command should only start supervisord, supervisord will then take care of starting celery and django
Malay
Malay13mo ago
Yes
Brody
Brody13mo ago
so please fix that
Malay
Malay13mo ago
How is it now??
No description
No description
Brody
Brody13mo ago
looks good
Malay
Malay13mo ago
si it better that the last one??
No description
Brody
Brody13mo ago
you want to run all the gunicorn related commands in the same program what you had before this was good
Malay
Malay13mo ago
okay deploying
Malay
Malay13mo ago
deployment done but can't access the app
No description
No description
Brody
Brody13mo ago
where there any errors?
Malay
Malay13mo ago
No description
Malay
Malay13mo ago
unable to download logs from Observability using the bookmark file
Brody
Brody13mo ago
download the logs from the service it also doesnt look like supervisord supports && in the command, so.. use the same supervisord.conf and dockerfile you showed here if i dont sound like i know what im doing, its because i dont
Malay
Malay13mo ago
here are the files I just deployed
No description
No description
Malay
Malay13mo ago
after asking chatgpt
Brody
Brody13mo ago
wrapping it in a shell string should certainly work
Malay
Malay13mo ago
Yes it worked I can see the admin page
Brody
Brody13mo ago
any errors?
Malay
Malay13mo ago
but I dont see the css applied to admin site
No description
Brody
Brody13mo ago
why you deploy to railway do you have debug set to false?
Malay
Malay13mo ago
debug is false in the production in railway
No description
Malay
Malay13mo ago
I haven;t set any env variables in the railway for debug
Brody
Brody13mo ago
then other than that there would be a config issue somewhere
Malay
Malay13mo ago
OKay, that's not the main issue. When I call the api end point I get a 202 response as expected. But I'm getting this error when the background task is run.
No description
No description
Brody
Brody13mo ago
that's more so looking like a code issue I do have a thought though, how big are these audio files?
Malay
Malay13mo ago
100kb or less
Brody
Brody13mo ago
okay then yeah this is a code issue
Malay
Malay13mo ago
gpt suggested this
No description
Brody
Brody13mo ago
I don't know what that would do but it might be worth a try
Malay
Malay13mo ago
now it works as expected. I can't thank you enough for your help and patience
Brody
Brody13mo ago
did you figure out the missing css issue?
Malay
Malay13mo ago
no
Brody
Brody13mo ago
it's a common issue, maybe gpt can suggest a fix for that too?
Malay
Malay13mo ago
I guess so I will try it Thanks a lot
Brody
Brody13mo ago
let me know how that goes
Malay
Malay13mo ago
sure
Want results from more Discord servers?
Add your server