How do I start redis (for celery background tasks) for django app?

space-we3
TRIAL

2 years ago

Hi,

I have successfully developed a Django application that is functioning properly and has been successfully connected to Redis using the appropriate database name and password. However, I am unsure of the procedure for initiating a Celery instance to execute scheduled tasks. In localhost, It had to run two separate terminals for running both Celery by entering specific two commands

celery -A APP_NAME beat --scheduler django_celery_beat.schedulers:DatabaseScheduler
and
celery -A APP_NAME.celery worker --pool=solo -l INFO

but How do I run it in railway to perform scheduled tasks?

Solved

24 Replies

2 years ago

on railway, you would use two services for this usecase, each service would deploy from the same repo as the django app does, but you would set the applicable command as the start command.


Status changed to Solved Railway over 1 year ago


space-we3
TRIAL

2 years ago

Could you please provide clarification on which two services are being referenced?


2 years ago

two new services, and those commands would be their start commands.


space-we3
TRIAL

2 years ago

I understand, could you please clarify what you are referring to as "services"? Terminals? Would it be appropriate for me to define these commands in the Procfile with the main app commands? If not, then where do I run these commands?


2 years ago

railway services, nothing to do with a Procfile.


space-we3
TRIAL

2 years ago

Okay, then where do I run these commands?


2 years ago

as mentioned previously, the commands you provided would be used as the services start command.


space-we3
TRIAL

2 years ago

As asked previously, Where do I define these two commands? In build.sh? If not then where? I have asked it several times, What are referring to as "services"? I am not understanding it


2 years ago

the start command field is found in the service settings.


space-we3
TRIAL

2 years ago

And Where do I find the "service settings"? Can you please provide a link of documentation or some page where I can completely understand?


2 years ago

click on the service and then click on the settings tab


space-we3
TRIAL

2 years ago

Do you mean I need to create a "empty service" in redis?


space-we3
TRIAL

2 years ago

Which settings, Django app's or redis's?


2 years ago

I'm not sure what redis has to do with this, I had assumed you already had redis deployed.

but no, these two new services would need to be deployed from your repo


space-we3
TRIAL

2 years ago

There are multiple settings like

Custom Build Command,
Custom Start Command,
Cron Schedule ,
Railway Config File,
Replicas,

But Cron schedule is not accepting celery -A APP_NAME.celery worker --pool=solo -l INFO as command and showing error "Sorry but that's not a valid cron expression"


2 years ago

cron has nothing to do with this.

as mentioned previously, you would set those commands as the start command in each of your two new services.


space-we3
TRIAL

2 years ago

But "Start command" can only take one command at a time.

I think I need to tell to "run build.sh" file where I can define both the commands. What do you think?


2 years ago

But "Start command" can only take one command at a time.

you're correct, that's why, as mentioned previously, you need two new services.

I don't know why you mention this build.sh file, or where this file is coming from or what you think it does, but I know its not needed.


space-we3
TRIAL

2 years ago

You're saying no need of build.sh but Only one command at a time can be defined in "Start command"


2 years ago

again, you need two services, TWO.

you have two start commands, so you need two railway services.

one service for each command you need to run.


space-we3
TRIAL

2 years ago

Okay, Thanks I will try and let you know.


space-we3
TRIAL

2 years ago

One more thing, Do I create Empty service inside my project? (I can also define Start command in empty service)


2 years ago

as mentioned previously, the two new services would be deployed from your repo, the same repo that you use for django.

going forward, please carefully read my comments so that I can avoid continuous repetition.


space-we3
TRIAL

2 years ago

Hi, Celery worked after creating two services. Thanks for the suggestions.


How do I start redis (for celery background tasks) for django app? - Railway Help Station