How to run a cron job.

rootmateo
PRO

7 months 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

0 Replies

7 months ago

yeah docs around this topic are lacking


rootmateo
PRO

7 months ago

My man brody! Thx for the help


7 months 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
PRO

7 months 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/.


7 months ago

in your case it would be sh /cron/pull_[data.sh](data.sh)


rootmateo
PRO

7 months ago

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


rootmateo
PRO

7 months ago

pull_data.sh runs a python script.


7 months ago

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


7 months ago

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


rootmateo
PRO

7 months ago

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


rootmateo
PRO

7 months ago

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


7 months ago

nixpacks handles that


rootmateo
PRO

7 months ago

Okay let me give it a proper shot


rootmateo
PRO

7 months ago

Thank you


rootmateo
PRO

7 months 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?

1313983877135733000


7 months ago

yes, but that doesnt look like it worked lol


7 months ago

send a link to it please?


rootmateo
PRO

7 months ago

Sure what would you like me to link?


7 months ago

the url



rootmateo
PRO

7 months ago

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


7 months ago

correct


rootmateo
PRO

7 months ago

You can just see it with your magic powers


rootmateo
PRO

7 months ago

gotcha


7 months ago

only you and team


rootmateo
PRO

7 months ago

Perfect


rootmateo
PRO

7 months ago

Quick FYI, the cron job just hit again, successfully


rootmateo
PRO

7 months ago

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


7 months ago

its running a deploy from 14 mins ago


7 months ago

what about the deploy from 3 mins ago?


7 months ago

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


rootmateo
PRO

7 months ago

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



7 months ago

^


rootmateo
PRO

7 months ago

Just added / as the root


rootmateo
PRO

7 months ago

Lets see if that does it


7 months ago

/ is already the default


7 months ago

have you read the deploy logs?


rootmateo
PRO

7 months ago

Deploy logs appear empty


7 months ago

sorry, i meant build logs


rootmateo
PRO

7 months ago

Ah yes I did. But no errors in there.


rootmateo
PRO

7 months ago

Can you see them?


7 months ago

yes there is


7 months ago

yes i can


rootmateo
PRO

7 months ago

1313986132484292600


rootmateo
PRO

7 months ago

It ends here. only info level on my ui


7 months ago

have you read the logs though?


rootmateo
PRO

7 months 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
PRO

7 months ago

Only info level


7 months ago

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


rootmateo
PRO

7 months 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/
v3alts/ setup.py mt5/ shared/ jasper/ admin/ tests/ lib/ .gitignore init.py datasci/
"


7 months ago

^


rootmateo
PRO

7 months ago

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


7 months ago

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


rootmateo
PRO

7 months ago

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


7 months ago

where is it located


rootmateo
PRO

7 months ago

Are you seeing something I'm not in this?


rootmateo
PRO

7 months ago

the cron jobs are located in services/cron/


7 months ago

Nixpacks build failed

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

rootmateo
PRO

7 months ago

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


7 months ago

does the script need files from outside of the services folder


rootmateo
PRO

7 months ago

Yes


rootmateo
PRO

7 months ago

it needs files from /lib/ and /jasper/


7 months ago

thenn your start command should be sh /services/cron/test/run_[test.sh](test.sh)


rootmateo
PRO

7 months ago

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


rootmateo
PRO

7 months ago

Sorry for wasting your time


rootmateo
PRO

7 months ago

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


7 months 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
PRO

7 months 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
PRO

7 months ago

1314011634565517300


7 months ago

Dockerfile is perfectly fine


rootmateo
PRO

7 months 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
PRO

7 months ago

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



7 months ago

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


rootmateo
PRO

7 months ago

That's what I was thinking


rootmateo
PRO

7 months 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.

1314012609028161500


7 months ago

that's fine


rootmateo
PRO

7 months ago

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


7 months ago

correct


rootmateo
PRO

7 months ago

Amazing. Thanks Brody


rootmateo
PRO

7 months ago

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


rootmateo
PRO

7 months ago

I barely got Docker down haha


7 months ago

no problem!


rootmateo
PRO

7 months ago

Tip jar? 👀


7 months ago

wdym?


rootmateo
PRO

7 months ago

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


rootmateo
PRO

7 months ago

Hoping you've changed your mind


rootmateo
PRO

7 months ago

I feel bad getting your assistance for free


7 months ago

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


rootmateo
PRO

7 months ago

Fair


rootmateo
PRO

7 months ago

Thanks boss


7 months ago

happy to help


7 months ago

!s


Status changed to Solved brody 7 months ago