Running python scripts in cron?

arhammusheerHOBBY

a year 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](simulate.py) which i wanna run on a cron schedule. How do I set this up as my nixpack build fails.

0 Replies

arhammusheerHOBBY

a year ago

f939f8da-1921-4926-b703-976d253eafb2


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


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


a year ago

but that can be worked around


arhammusheerHOBBY

a year ago

What is the lowest frequency?


arhammusheerHOBBY

a year ago

Figured out I could just use a dockerfile

Dropping it here if anyone references this in future
```py

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"]```


a year ago

yeah that looks fine to me


a year ago

ill check


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


arhammusheerHOBBY

a year ago

Just found docs saying 15 mins


arhammusheerHOBBY

a year ago

The UI does let me set every minute though


a year ago


arhammusheerHOBBY

a year ago

Doesn't seem like it runs at all


a year ago

fair enough


arhammusheerHOBBY

a year ago

Bug report?


arhammusheerHOBBY

a year ago

I'll go away to the cron template


a year ago

its just a ui bug, nothing of major concern


a year ago

the min frequency is indeed 15 minutes for hobby users


arhammusheerHOBBY

a year ago

Noted


Running python scripts in cron? - Railway Help Station