Skip to content

Commit 4344352

Browse files
committed
Refactor conda environment handling in weather update status scripts; add deactivation step and improve activation warnings
1 parent d9354fc commit 4344352

File tree

2 files changed

+10
-37
lines changed

2 files changed

+10
-37
lines changed

scripts/update_weather_status.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ export LANG=C.UTF-8
1818
module load LibTIFF/4.6.0-GCCcore-13.3.0
1919
module load Miniconda3/24.7.1-0
2020

21-
# Activate conda environment
22-
conda activate mosquito-alert-monitor
21+
# Initialize conda if needed
22+
source ~/.bashrc 2>/dev/null || true
23+
24+
# Activate conda environment for dashboard operations
25+
conda activate mosquito-alert-monitor 2>/dev/null || {
26+
echo "WARNING: Failed to activate conda environment mosquito-alert-monitor"
27+
}
2328

2429

2530
# scripts/update_weather_status.sh
@@ -158,3 +163,6 @@ if [ -f "$STATUS_DIR/${JOB_NAME}.json" ]; then
158163
else
159164
echo "❌ Failed to create status file"
160165
fi
166+
167+
# Deactivate conda environment to allow R/renv to work properly
168+
conda deactivate 2>/dev/null || true

update_weather.sh

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ module load LibTIFF/4.6.0-GCCcore-13.3.0
1616
module load R/4.4.2-gfbf-2024a
1717
module load cURL/8.7.1-GCCcore-13.3.0
1818
module load OpenSSL/3
19-
module load Miniconda3/24.7.1-0
20-
21-
# Initialize and activate conda environment
22-
source ~/.bashrc # Ensure conda is initialized
23-
if ! conda activate mosquito-alert-monitor; then
24-
echo "WARNING: Failed to activate conda environment mosquito-alert-monitor"
25-
echo "Continuing with default environment..."
26-
fi
2719

2820
# Load SSH agent since this is no longer done by default on the cluster
2921
eval "$(ssh-agent -s)"
@@ -56,31 +48,6 @@ START_TIME=$(date +%s)
5648
# Report job started
5749
$STATUS_SCRIPT "$JOB_NAME" "running" 0 5
5850

59-
# Initialize renv if first run
60-
if [ ! -f "renv.lock" ]; then
61-
echo "Initializing renv..."
62-
$STATUS_SCRIPT "$JOB_NAME" "running" 0 10
63-
R --slave --no-restore --file=- <<EOF
64-
if (!requireNamespace("renv", quietly = TRUE)) {
65-
install.packages("renv", repos="https://cran.r-project.org")
66-
}
67-
renv::init()
68-
renv::install(c("tidyverse", "lubridate", "data.table", "curl", "jsonlite", "httr", "R.utils"))
69-
renv::snapshot()
70-
EOF
71-
else
72-
echo "Restoring renv packages..."
73-
$STATUS_SCRIPT "$JOB_NAME" "running" 0 15
74-
R --slave --no-restore --file=- <<EOF
75-
renv::restore(prompt = FALSE)
76-
EOF
77-
fi
78-
79-
# Activate renv
80-
R --slave --no-restore --file=- <<EOF
81-
renv::activate()
82-
EOF
83-
8451
# Pull any pending commits
8552
git pull origin main
8653

@@ -123,8 +90,6 @@ fi
12390
# Priority 4: Generate aggregated datasets
12491
echo "Generating aggregated datasets..."
12592
$STATUS_SCRIPT "weather-aggregation" "running" $(($(date +%s) - START_TIME)) 90
126-
127-
# Run dataset aggregation
12893
./generate_all_datasets.sh
12994

13095
if [ $? -eq 0 ]; then

0 commit comments

Comments
 (0)