Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding schedule to run.sh #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
#!/bin/sh
#!/bin/bash

# Define cron-style schedule (e.g., "32 18 17,21,29 11 mon,wed")
# Refer to https://crontab.guru/#*_*_*_*_*
SCHEDULE="* * * * *"

# Function to check if the current time matches the schedule
function check_schedule() {
# Split schedule into components
IFS=' ' read -r S_MIN S_HOUR S_DOM S_MONTH S_DOW <<< "$SCHEDULE"

# Get current time components
CUR_MIN=$(date +'%M')
CUR_HOUR=$(date +'%H')
CUR_DOM=$(date +'%d')
CUR_MONTH=$(date +'%m')
CUR_DOW=$(date +'%a' | tr '[:upper:]' '[:lower:]') # Convert to lowercase (e.g., "mon")

# Helper function to match a component (e.g., "18" or "mon,wed")
function match_component() {
local component=$1
local value=$2
if [[ "$component" == "*" ]] || [[ "$component" == *",$value,"* ]] || [[ "$component" == "$value" ]]; then
return 0
else
return 1
fi
}

# Match each component of the schedule against the current time
match_component ",$S_MIN," "$CUR_MIN" &&
match_component ",$S_HOUR," "$CUR_HOUR" &&
match_component ",$S_DOM," "$CUR_DOM" &&
match_component ",$S_MONTH," "$CUR_MONTH" &&
match_component ",$S_DOW," "$CUR_DOW"
}

# Only run if the schedule matches
if ! check_schedule; then
echo "Not the scheduled time to run. Exiting."
exit 0
fi

# this will create venv from python version defined in .python-version
uv venv
Expand Down