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

space-we3TRIAL

a year 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

a year 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[bot] about 1 year ago


space-we3TRIAL

a year ago

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


a year ago

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


space-we3TRIAL

a year 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?


a year ago

railway services, nothing to do with a Procfile.


space-we3TRIAL

a year ago

Okay, then where do I run these commands?


a year ago

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


space-we3TRIAL

a year 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


a year ago

the start command field is found in the service settings.


space-we3TRIAL

a year 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?


a year ago

click on the service and then click on the settings tab


space-we3TRIAL

a year ago

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


space-we3TRIAL

a year ago

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


a year 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-we3TRIAL

a year 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"


a year 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-we3TRIAL

a year 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?


a year 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-we3TRIAL

a year ago

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


a year 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-we3TRIAL

a year ago

Okay, Thanks I will try and let you know.


space-we3TRIAL

a year ago

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


a year 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-we3TRIAL

a year ago

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