Running python scripts in cron?

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.
14 Replies
Percy
Percy9mo ago
Project ID: f939f8da-1921-4926-b703-976d253eafb2
croissant
croissant9mo ago
f939f8da-1921-4926-b703-976d253eafb2
Brody
Brody9mo 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 https://railway.app/template/fwH-l3 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.
Adam
Adam9mo 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) but that can be worked around
croissant
croissant9mo ago
What is the lowest frequency? 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"]
# 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"]
Brody
Brody9mo ago
yeah that looks fine to me ill check 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
croissant
croissant9mo ago
croissant
croissant9mo ago
The UI does let me set every minute though
Brody
Brody9mo ago
No description
croissant
croissant9mo ago
Doesn't seem like it runs at all
Brody
Brody9mo ago
fair enough
croissant
croissant9mo ago
Bug report? I'll go away to the cron template
Brody
Brody9mo ago
its just a ui bug, nothing of major concern the min frequency is indeed 15 minutes for hobby users
croissant
croissant9mo ago
Noted
Want results from more Discord servers?
Add your server