How to run a cron job.
rootmateo
PROOP

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

brody
EMPLOYEE

a year ago

yeah docs around this topic are lacking


rootmateo
PROOP

a year ago

My man brody! Thx for the help


brody
EMPLOYEE

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

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


brody
EMPLOYEE

a year ago

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


rootmateo
PROOP

a year ago

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


rootmateo
PROOP

a year ago

pull_data.sh runs a python script.


brody
EMPLOYEE

a year ago

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


brody
EMPLOYEE

a year ago

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


rootmateo
PROOP

a year ago

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


rootmateo
PROOP

a year ago

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


brody
EMPLOYEE

a year ago

nixpacks handles that


rootmateo
PROOP

a year ago

Okay let me give it a proper shot


rootmateo
PROOP

a year ago

Thank you


rootmateo
PROOP

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


brody
EMPLOYEE

a year ago

yes, but that doesnt look like it worked lol


brody
EMPLOYEE

a year ago

send a link to it please?


rootmateo
PROOP

a year ago

Sure what would you like me to link?


brody
EMPLOYEE

a year ago

the url



rootmateo
PROOP

a year ago

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


brody
EMPLOYEE

a year ago

correct


rootmateo
PROOP

a year ago

You can just see it with your magic powers


rootmateo
PROOP

a year ago

gotcha


brody
EMPLOYEE

a year ago

only you and team


rootmateo
PROOP

a year ago

Perfect


rootmateo
PROOP

a year ago

Quick FYI, the cron job just hit again, successfully


rootmateo
PROOP

a year ago

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


brody
EMPLOYEE

a year ago

its running a deploy from 14 mins ago


brody
EMPLOYEE

a year ago

what about the deploy from 3 mins ago?


brody
EMPLOYEE

a year ago

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


rootmateo
PROOP

a year ago

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



brody
EMPLOYEE

a year ago

^


rootmateo
PROOP

a year ago

Just added / as the root


rootmateo
PROOP

a year ago

Lets see if that does it


brody
EMPLOYEE

a year ago

/ is already the default


brody
EMPLOYEE

a year ago

have you read the deploy logs?


rootmateo
PROOP

a year ago

Deploy logs appear empty


brody
EMPLOYEE

a year ago

sorry, i meant build logs


rootmateo
PROOP

a year ago

Ah yes I did. But no errors in there.


rootmateo
PROOP

a year ago

Can you see them?


brody
EMPLOYEE

a year ago

yes there is


brody
EMPLOYEE

a year ago

yes i can


rootmateo
PROOP

a year ago

1313986132484292600


rootmateo
PROOP

a year ago

It ends here. only info level on my ui


brody
EMPLOYEE

a year ago

have you read the logs though?


rootmateo
PROOP

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

a year ago

Only info level


brody
EMPLOYEE

a year ago

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


rootmateo
PROOP

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


brody
EMPLOYEE

a year ago

^


rootmateo
PROOP

a year ago

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


brody
EMPLOYEE

a year ago

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


rootmateo
PROOP

a year ago

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


brody
EMPLOYEE

a year ago

where is it located


rootmateo
PROOP

a year ago

Are you seeing something I'm not in this?


rootmateo
PROOP

a year ago

the cron jobs are located in services/cron/


brody
EMPLOYEE

a year ago

Nixpacks build failed

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

rootmateo
PROOP

a year ago

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


brody
EMPLOYEE

a year ago

does the script need files from outside of the services folder


rootmateo
PROOP

a year ago

Yes


rootmateo
PROOP

a year ago

it needs files from /lib/ and /jasper/


brody
EMPLOYEE

a year ago

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


rootmateo
PROOP

a year ago

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


rootmateo
PROOP

a year ago

Sorry for wasting your time


rootmateo
PROOP

a year ago

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


brody
EMPLOYEE

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

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

a year ago

1314011634565517300


brody
EMPLOYEE

a year ago

Dockerfile is perfectly fine


rootmateo
PROOP

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

a year ago

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



brody
EMPLOYEE

a year ago

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


rootmateo
PROOP

a year ago

That's what I was thinking


rootmateo
PROOP

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


brody
EMPLOYEE

a year ago

that's fine


rootmateo
PROOP

a year ago

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


brody
EMPLOYEE

a year ago

correct


rootmateo
PROOP

a year ago

Amazing. Thanks Brody


rootmateo
PROOP

a year ago

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


rootmateo
PROOP

a year ago

I barely got Docker down haha


brody
EMPLOYEE

a year ago

no problem!


rootmateo
PROOP

a year ago

Tip jar? 👀


brody
EMPLOYEE

a year ago

wdym?


rootmateo
PROOP

a year ago

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


rootmateo
PROOP

a year ago

Hoping you've changed your mind


rootmateo
PROOP

a year ago

I feel bad getting your assistance for free


brody
EMPLOYEE

a year ago

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


rootmateo
PROOP

a year ago

Fair


rootmateo
PROOP

a year ago

Thanks boss


brody
EMPLOYEE

a year ago

happy to help


brody
EMPLOYEE

a year ago

!s


Status changed to Solved brody about 1 year ago


Loading...