Running python scripts in cron?
arhammusheer
HOBBYOP

2 years ago

how can i run a cron python script on railway? like just run once every minute. No active container?

I have a script called simulate.py which i wanna run on a cron schedule. How do I set this up as my nixpack build fails.

19 Replies

arhammusheer
HOBBYOP

2 years ago

f939f8da-1921-4926-b703-976d253eafb2


2 years ago

railway's cron schedular does not let you run at a frequency of 1 minute, if you need the script to be ran at one minute intervals you would need to either use an in code schedular (active container as you call it) or use in restart mode.

but before we worry about cron at all, we would need to get your script to at least launch, and for that, please provide your repo and any error messages you are getting.


2 years ago

the error is very likely that nixpacks is unable to generate a build plan, since your script isn’t following the usual naming conventions (eg. main.py)


2 years ago

but that can be worked around


arhammusheer
HOBBYOP

2 years ago

What is the lowest frequency?


arhammusheer
HOBBYOP

2 years ago

Figured out I could just use a dockerfile

Dropping it here if anyone references this in future

# Use an official Python runtime as a parent image
FROM python:3.9-slim

# Set the working directory in the container
WORKDIR /usr/src/app

# Copy the current directory contents into the container at /usr/src/app
COPY . /usr/src/app

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Run simulate.py when the container launches
CMD ["python", "./simulate.py"]```

2 years ago

yeah that looks fine to me


2 years ago

ill check


2 years ago

it appears you can now do 1 minute intervals natively, i distinctly remember them disallowing that, at least the ui tells me that it will run every minute


arhammusheer
HOBBYOP

2 years ago

Just found docs saying 15 mins


arhammusheer
HOBBYOP

2 years ago

The UI does let me set every minute though


2 years ago

(no markdown available for this content)


arhammusheer
HOBBYOP

2 years ago

Doesn't seem like it runs at all


2 years ago

fair enough


arhammusheer
HOBBYOP

2 years ago

Bug report?


arhammusheer
HOBBYOP

2 years ago

I'll go away to the cron template


2 years ago

its just a ui bug, nothing of major concern


2 years ago

the min frequency is indeed 15 minutes for hobby users


arhammusheer
HOBBYOP

2 years ago

Noted


Welcome!

Sign in to your Railway account to join the conversation.

Loading...