R
Railway14mo 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
Percy14mo ago
Project ID: N/A
Malay
MalayOP14mo ago
Project ID: 286dccfe-bf85-48fe-ae80-ab24c5a80716 Project ID: 286dccfe-bf85-48fe-ae80-ab24c5a80716
Brody
Brody14mo ago
are you using the private network?
Malay
MalayOP14mo ago
I think yes
No description
Brody
Brody14mo ago
right but are you actually utilizing it
Malay
MalayOP14mo ago
How do I do that?? I have set engvironment variable like this REDIS_URL=${{Redis.REDIS_URL}}
Brody
Brody14mo ago
disable private networking, and then redeploy
Malay
MalayOP14mo ago
do I need to re-enable it??
Brody
Brody14mo ago
no
Malay
MalayOP14mo ago
I disabled it. But, It didn;t work
No description
Malay
MalayOP14mo ago
its the same as before
Brody
Brody14mo ago
can you connect to redis with redis-cli?
Malay
MalayOP14mo ago
yes I can connnect
No description
Brody
Brody14mo ago
can you show me how you have disabled private networking?
Malay
MalayOP14mo ago
No description
Malay
MalayOP14mo ago
like this
Brody
Brody14mo ago
can you show me a screenshot of your service variables
Malay
MalayOP14mo ago
sure
Malay
MalayOP14mo ago
No description
Malay
MalayOP14mo ago
I copy pasted the redis url from the redis connection section Initially I had added like this ${{Redis.REDIS_URL}}
Brody
Brody14mo ago
this is what it should be, please put it back to that
Malay
MalayOP14mo ago
but It was n;t working then I can try again
Malay
MalayOP14mo ago
similar errors
No description
Malay
MalayOP14mo 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
Brody14mo 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
MalayOP14mo ago
OK let me try that
Brody
Brody14mo 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
MalayOP14mo ago
Let me try If I fail I will ask you questions here. Is that okay?
Brody
Brody14mo 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
MalayOP14mo 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
Brody14mo ago
are you building with a dockerfile?
Malay
MalayOP14mo ago
no procfile like you had suggested
Brody
Brody14mo ago
gotcha
Malay
MalayOP14mo ago
No description
Brody
Brody14mo ago
railway does not support a worker process in the procfile do you have two railway services in your project?
Malay
MalayOP14mo ago
yes
Brody
Brody14mo ago
and do you have custom start commands set in each service?
Malay
MalayOP14mo 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
Brody14mo ago
are both of your services deploying from the same repo
Malay
MalayOP14mo ago
I dont have ustom start command in either service
Brody
Brody14mo ago
you said that already lol
Malay
MalayOP14mo ago
Yes
Brody
Brody14mo ago
do both of these services have the same service variables
Malay
MalayOP14mo ago
It wasn't same. I made them same. And redeploying.
Brody
Brody14mo ago
but its good that they are the same now
Malay
MalayOP14mo ago
They are the exact same now
Brody
Brody14mo 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
MalayOP14mo ago
remove the worker line from procfiel deploying right now
Brody
Brody14mo ago
show me your new procfile, and show me what start command you set in the celery service please
Malay
MalayOP14mo ago
I haven;t added the start command I have remove the worker command from procfiel
Malay
MalayOP14mo ago
No description
Malay
MalayOP14mo ago
What should be the start command?
Brody
Brody14mo ago
the command you use to start celery
Malay
MalayOP14mo ago
celery -A core worker --loglevel=info this??
Brody
Brody14mo ago
is that the command you use to start celery?
Malay
MalayOP14mo ago
Yes Yes
Brody
Brody14mo ago
then yes show me what start command you set in the celery service?
Malay
MalayOP14mo ago
for django app
No description
Malay
MalayOP14mo ago
for celery
No description
Brody
Brody14mo 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
MalayOP14mo ago
okay
Malay
MalayOP14mo ago
does it look okay?
No description
Brody
Brody14mo ago
yes
Malay
MalayOP14mo ago
Okay deploying
Malay
MalayOP14mo ago
the build failed
Brody
Brody14mo ago
remove the build command from the django service
Malay
MalayOP14mo ago
this is the celery service, it did not have the command but still failed
No description
Malay
MalayOP14mo ago
removed
Brody
Brody14mo ago
lets focus on one thing at a time, if the django service still fails to build, send me the logs
Malay
MalayOP14mo ago
okay
Malay
MalayOP14mo ago
Brody
Brody14mo ago
are you using pdftotext?
Malay
MalayOP14mo ago
Yes for this package I need the apt packages
Brody
Brody14mo 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
MalayOP14mo ago
Okay. doing it right away
Brody
Brody14mo ago
sorry to ask you to do all that and then just ask you to go back to what you had
Malay
MalayOP14mo ago
No thank you very much for helping out a noobie like me
Malay
MalayOP14mo ago
here is the dockefile and supervisord.conf
No description
No description
Malay
MalayOP14mo ago
SHould I deploy it??
Brody
Brody14mo ago
your cmd command should only start supervisord, supervisord will then take care of starting celery and django
Malay
MalayOP14mo ago
Yes
Brody
Brody14mo ago
so please fix that
Malay
MalayOP14mo ago
How is it now??
No description
No description
Brody
Brody14mo ago
looks good
Malay
MalayOP14mo ago
si it better that the last one??
No description
Brody
Brody14mo ago
you want to run all the gunicorn related commands in the same program what you had before this was good
Malay
MalayOP14mo ago
okay deploying
Malay
MalayOP14mo ago
deployment done but can't access the app
No description
No description
Brody
Brody14mo ago
where there any errors?
Malay
MalayOP14mo ago
No description
Malay
MalayOP14mo ago
unable to download logs from Observability using the bookmark file
Brody
Brody14mo 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
MalayOP14mo ago
here are the files I just deployed
No description
No description
Malay
MalayOP14mo ago
after asking chatgpt
Brody
Brody14mo ago
wrapping it in a shell string should certainly work
Malay
MalayOP14mo ago
Yes it worked I can see the admin page
Brody
Brody14mo ago
any errors?
Malay
MalayOP14mo ago
but I dont see the css applied to admin site
No description
Brody
Brody14mo ago
why you deploy to railway do you have debug set to false?
Malay
MalayOP14mo ago
debug is false in the production in railway
No description
Malay
MalayOP14mo ago
I haven;t set any env variables in the railway for debug
Brody
Brody14mo ago
then other than that there would be a config issue somewhere
Malay
MalayOP14mo 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
Brody14mo ago
that's more so looking like a code issue I do have a thought though, how big are these audio files?
Malay
MalayOP14mo ago
100kb or less
Brody
Brody14mo ago
okay then yeah this is a code issue
Malay
MalayOP14mo ago
gpt suggested this
No description
Brody
Brody14mo ago
I don't know what that would do but it might be worth a try
Malay
MalayOP14mo ago
now it works as expected. I can't thank you enough for your help and patience
Brody
Brody14mo ago
did you figure out the missing css issue?
Malay
MalayOP14mo ago
no
Brody
Brody14mo ago
it's a common issue, maybe gpt can suggest a fix for that too?
Malay
MalayOP14mo ago
I guess so I will try it Thanks a lot
Brody
Brody14mo ago
let me know how that goes
Malay
MalayOP14mo ago
sure
Want results from more Discord servers?
Add your server