Skip to content

Commit

Permalink
Merge pull request #325 from JaerongA/datajoint_pipeline
Browse files Browse the repository at this point in the history
chore: 🔊 Create a logger for a cron job
  • Loading branch information
Thinh Nguyen authored Feb 5, 2024
2 parents 51b33a9 + b54597a commit fcd7e41
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions docker/cron_script.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
# 0 */4 * * * /path/to/cron_script.bash
# For debugging, run ./cron_script.bash -v

# Create a log file whenever the job gets run.
ROOT_LOG_DIR="/ceph/aeon/aeon/dj_store/logs"
mkdir -p "${ROOT_LOG_DIR}"
LOG_FILE="${ROOT_LOG_DIR}/cron_script_$(date '+%Y%m%d_%H%M%S').log"

verbose=0

while [[ "$#" -gt 0 ]]; do
Expand All @@ -17,15 +22,15 @@ done
# Verbose option for debugging
print_verbose() {
if [ "$verbose" -eq 1 ]; then
printf "[DEBUG] %s - %s\n\n" "$1" "$(date '+%Y-%m-%d %H:%M:%S')"
echo "[DEBUG] $1 - $(date '+%Y-%m-%d %H:%M:%S')" >>"$LOG_FILE"
fi
}

print_verbose "Starting Ingestion..."
cd /nfs/nhome/live/aeon_db/aeon_mecha/docker/

print_verbose "Terminate running workers..."
docker-compose down
docker-compose down >>"$LOG_FILE" 2>&1
if [ $? -eq 0 ]; then
print_verbose "Workers terminated successfully."
else
Expand All @@ -34,13 +39,13 @@ fi

if docker image inspect ghcr.io/sainsburywellcomecentre/aeon_mecha >/dev/null 2>&1; then
print_verbose "Removing existing aeon_mecha image..."
docker image rm ghcr.io/sainsburywellcomecentre/aeon_mecha
docker image rm ghcr.io/sainsburywellcomecentre/aeon_mecha >>"$LOG_FILE" 2>&1
fi

print_verbose "Restart workers..."
docker-compose up --detach
docker-compose up --detach >>"$LOG_FILE" 2>&1
if [ $? -eq 0 ]; then
print_verbose "workers restarted successfully."
print_verbose "Workers restarted successfully."
else
print_verbose "Failed to restart workers."
fi

0 comments on commit fcd7e41

Please sign in to comment.