Cron jobs

icarocreativa
HOBBY

a year ago

Hi,

I have delpoyed my app in nextjs. I need to run a cron job to delete old users in my app. How to do this in railway?. Where I put the script for delete old users? (in the nextjs's folder?). How to configure the cron job to execute my script.

Thanks a lot!!

2 Replies

a year ago

Hello!

Cron services can not also be regular services, meaning you need to have one service to run your nextjs app and another service to run your script on a Cron schedule.

It looks like you already have your nextjs app deployed fine so no need to touch that service.

You would want to write up a script like task.js that does your desired task when ran and exits when done.

Deploy a new service into your project that deploys from the repo you have the task.js file in, add any needed environment variables that task may need, and set the service's start command to run that task.js file, set your cron schedule and you are set, Railway will now run that script on a Cron schedule!


icarocreativa
HOBBY

a year ago

Thanks a lot. I will try and i tell you if it works fine.


Cron jobs - Railway Help Station