How to run a cron job.
rootmateo
PROOP

2 years ago

Disclaimer: Bit of a noob.

I'm super familiar with running services via docker files.

Am a bit unsure how to run a cron job.

If I have a file in my repo called pull_data.sh in /cron/ dir, how would I have a cron service execute that?

Note: I took a look at documentation on this and am a bit stuck.

Solved

94 Replies

2 years ago

yeah docs around this topic are lacking


rootmateo
PROOP

2 years ago

My man brody! Thx for the help


2 years ago

  1. Create a new service in your existing project
  2. Add any needed variables
  3. Set it up to deploy from the repo that contains the file / script / etc that you want to run
  4. In the service settings, set the start command the start command will be what's ran on the set schedule
  5. Set the schedule in the service settings

rootmateo
PROOP

2 years ago

Step 1 and 2 are done. Service created and variables added.

For step 3, I have the repo connected. I take it thats all here.

For step 4, what would the start command be? saying I have the sh file in /cron/.


2 years ago

in your case it would be sh /cron/pull_data.sh


rootmateo
PROOP

2 years ago

Also would you recommend it be done via a docker container or is that not necessary here


rootmateo
PROOP

2 years ago

pull_data.sh runs a python script.


2 years ago

not necessary as runs of the cron job don't rebuild anything


2 years ago

nixpacks should detect that its a python app so you should have python


rootmateo
PROOP

2 years ago

Gotcha. Quick Q: Without a docker container how would I handle passing in all the dependencies (requirements.txt)


rootmateo
PROOP

2 years ago

And passing in the required files (Docker's COPY /logic/pull_data/ .)


2 years ago

nixpacks handles that


rootmateo
PROOP

2 years ago

Okay let me give it a proper shot


rootmateo
PROOP

2 years ago

Thank you


rootmateo
PROOP

2 years ago

Okay so the cron job worked (so really all is good).

I'm just wondering, should there be things here in the deployments tab?

1313983877135732927


2 years ago

yes, but that doesnt look like it worked lol


2 years ago

send a link to it please?


rootmateo
PROOP

2 years ago

Sure what would you like me to link?


2 years ago

the url



rootmateo
PROOP

2 years ago

Quick Q: No one else who can see this chat can click into this?


2 years ago

correct


rootmateo
PROOP

2 years ago

You can just see it with your magic powers


rootmateo
PROOP

2 years ago

gotcha


2 years ago

only you and team


rootmateo
PROOP

2 years ago

Perfect


rootmateo
PROOP

2 years ago

Quick FYI, the cron job just hit again, successfully


rootmateo
PROOP

2 years ago

Seems like the cron part is working. Not sure about the deployment tab though


2 years ago

its running a deploy from 14 mins ago


2 years ago

what about the deploy from 3 mins ago?


2 years ago

from the deploy logs, it looks like you might need to set a root dir


rootmateo
PROOP

2 years ago

Okay. I start that service trying it with docker file so I just created a new one



2 years ago

^


rootmateo
PROOP

2 years ago

Just added / as the root


rootmateo
PROOP

2 years ago

Lets see if that does it


2 years ago

/ is already the default


2 years ago

have you read the deploy logs?


rootmateo
PROOP

2 years ago

Deploy logs appear empty


2 years ago

sorry, i meant build logs


rootmateo
PROOP

2 years ago

Ah yes I did. But no errors in there.


rootmateo
PROOP

2 years ago

Can you see them?


2 years ago

yes there is


2 years ago

yes i can


rootmateo
PROOP

2 years ago

1313986132484292698


rootmateo
PROOP

2 years ago

It ends here. only info level on my ui


2 years ago

have you read the logs though?


rootmateo
PROOP

2 years ago

Sorry I don't want to be missing something but when I look through the build logs, all I see is that screenshot


rootmateo
PROOP

2 years ago

Only info level


2 years ago

please read the actual content of the logs, dont worry if they are red or not


rootmateo
PROOP

2 years ago

I read them. All I see is "

[Region: us-west1]

Using Nixpacks

context: 2b843b44d67edc7bfb5e5c611eba9555

Nixpacks build failed

Nixpacks was unable to generate a build plan for this app.

Please check the documentation for supported languages: https://nixpacks.com

The contents of the app directory are:

.cursorignore

.dockerignore

deploy/

services/

contracts/

v3_alts/

setup.py

mt5/

shared/

jasper/

admin/

tests/

lib/

.gitignore

init.py

data_sci/

"


2 years ago

^


rootmateo
PROOP

2 years ago

I thought I did with "/". Wouldn't that work?


2 years ago

i feel like you aren't reading the build logs?


rootmateo
PROOP

2 years ago

my cron job pulls files from other dir's in the root directory.


2 years ago

where is it located


rootmateo
PROOP

2 years ago

Are you seeing something I'm not in this?


rootmateo
PROOP

2 years ago

the cron jobs are located in services/cron/


2 years ago

Nixpacks build failed

Nixpacks was unable to generate a build plan for this app.

rootmateo
PROOP

2 years ago

I'm just trying to test services/cron/test/run_test.sh


2 years ago

does the script need files from outside of the services folder


rootmateo
PROOP

2 years ago

Yes


rootmateo
PROOP

2 years ago

it needs files from /lib/ and /jasper/


2 years ago

thenn your start command should be sh /services/cron/test/run_test.sh


rootmateo
PROOP

2 years ago

Gotcha. I went ahead and did this but still get build failed 😦


rootmateo
PROOP

2 years ago

Sorry for wasting your time


rootmateo
PROOP

2 years ago

Let me mess around with this and see if I can fix it. I'm probably just messing up something stupid.


2 years ago

add a nixpacks.toml to the cron folder with this in it -

[phases.setup]
    nixPkgs = ['python3']

the set a service variable NIXPACKS_CONFIG_FILE=/services/cron


rootmateo
PROOP

2 years ago

Hey boss. I tried this nix approach with your nixpacks.toml but was getting a file doesn't exist error.

Out of curiousity, is it not recommended to do it via docker file? I was able to get it work this way but wanted to get your thoughts.


rootmateo
PROOP

2 years ago

1314011634565517332


2 years ago

Dockerfile is perfectly fine


rootmateo
PROOP

2 years ago

Okay great. Does this screenshot look okay? I just wanted to make sure that the deployments are properly closing down after they finish.


rootmateo
PROOP

2 years ago

I'm scared that they're staying open and every 5 minutes another container is opening up (and charging)



2 years ago

looks like they are exiting after around 10s according to the time on the right side


rootmateo
PROOP

2 years ago

That's what I was thinking


rootmateo
PROOP

2 years ago

But when I open up the log (of one that already completed) it still says active and doesn't say it stopped container or anything like that.

1314012609028161630


2 years ago

that's fine


rootmateo
PROOP

2 years ago

Okay. Hmm. So it is closing and not charging for these containers?


2 years ago

correct


rootmateo
PROOP

2 years ago

Amazing. Thanks Brody


rootmateo
PROOP

2 years ago

Sorry for being a bit of a dud when it came to the Nix stuff


rootmateo
PROOP

2 years ago

I barely got Docker down haha


2 years ago

no problem!


rootmateo
PROOP

2 years ago

Tip jar? 👀


2 years ago

wdym?


rootmateo
PROOP

2 years ago

Last time I asked if I could tip you when you helped me out, you said no


rootmateo
PROOP

2 years ago

Hoping you've changed your mind


rootmateo
PROOP

2 years ago

I feel bad getting your assistance for free


2 years ago

I'm still gonna say no, railway pays me lol


rootmateo
PROOP

2 years ago

Fair


rootmateo
PROOP

2 years ago

Thanks boss


2 years ago

happy to help


2 years ago

!s


Status changed to Solved brody over 1 year ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...