How do I deploy Django-Q (task queue) to Railway?
Are there any tutorials on how to achieve this?
After searching for a bit it looks like I need to do the following:
1. Redis DB service and connect to it from settings.py under the Q_CLUSTER/redis settings
2. set the worker in the Procfile: worker: python manage.py qcluster
I did both those things but still the tasks don't start.
Thanks!
Solution:Jump to solution
so like mentioned previously, you want two railway services, these two railway services should be near exact clones of each other, same environment variables, deploy from the same github repo, in the same project, the only difference being that you'd change the start command in the service settings of one to run the django stuff, and in the other service you'd set the start command to only run the task queue
21 Replies
Project ID:
df711288-dddd-4e3e-8f3f-62aefe4a3212
df711288-dddd-4e3e-8f3f-62aefe4a3212
you want a two railway services, one service runs the task queue, the other service runs django
don't try to run the task queue and django in a single service
Brody, thank you for the tip. But how do I set that up? Right now I have one Procfile that has this one line in it: web: python manage.py migrate && python manage.py collectstatic --no-input && gunicorn fleetdata.wsgi & python manage.py qcluster
Did you set up the Redis server yet in your project?
yes.
Q_CLUSTER = {
'name': 'fleetdata',
'workers': 8,
'recycle': 500,
'timeout': 6000,
'retry': 10000,
'compress': True,
'save_limit': 250,
'queue_limit': 500,
'cpu_affinity': 1,
'label': 'Django Q',
'redis': config('REDIS_URL'),
}
You're gonna need more than just the URL
Looks like you need a dictionary based on this: https://django-q.readthedocs.io/en/latest/configure.html
Try changing it to something like this:
'redis' : {
host=env('REDISHOST'),
port=env('REDISPORT'),
password=env('REDISPASSWORD')
}
or whatever you're using for your environment variablesfrom the docs you linked
Itβs also possible to use a Redis connection URIso nothing wrong with using the URL as it contains everything the other environment variables do
Solution
so like mentioned previously, you want two railway services, these two railway services should be near exact clones of each other, same environment variables, deploy from the same github repo, in the same project, the only difference being that you'd change the start command in the service settings of one to run the django stuff, and in the other service you'd set the start command to only run the task queue
django service start command:
python manage.py migrate && python manage.py collectstatic --no-input && gunicorn fleetdata.wsgi
task queue service start command: python manage.py qcluster
I hope this explains it well enough, but let me know if I need to clarify something
@ValeriuV π@Brody , alright, I'll try that tonight and get back to you. Thank you!
no prob π
The next question that pops to my mind is how do I do that? Should I use a different github branch?
same github repo and branch for both services, these two services will be near exact clones, the only difference being their start commands
I'm deploying through Github, so am not sure exactly how to export different versions of the Procfile to both services.
as previously mentioned you will use the start command field In the service settings, with that you can effectively delete the procfile
oh, got it. trying now
wooooooooaaaaaaaaaaaaa it worked
I'm so thankful
Brody you are the man!
I would have never figured it out that I should have another service for task queues
but I did it through two git branches
why?
one for main and another for django-q
that's what I assumed before you wrote your detailed explanation
I guess I should do it with the start command
ok, working on it
oh haha yeah definitely don't do two branches
alrighty