AlvaroMros commited on
Commit
8c767a0
·
1 Parent(s): 8a644b9

Automated model update: 2025-07-15 20:00:00

Browse files
logs/model_update.log ADDED
Binary file (1.04 kB). View file
 
logs/update.lock ADDED
Binary file (16 Bytes). View file
 
scripts/README.md ADDED
@@ -0,0 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # UFC Prediction Pipeline Automation Scripts
2
+
3
+ This directory contains automation scripts that run the UFC prediction pipeline and automatically push logs and model updates to your git repository.
4
+
5
+ ## Scripts Overview
6
+
7
+ ### 1. `update_models.ps1` (Windows PowerShell)
8
+ Production-ready automation script for Windows Task Scheduler with git integration.
9
+
10
+ **Features:**
11
+ - Runs model updates with resource limits and timeouts
12
+ - Commits and pushes logs to git repository automatically
13
+ - Handles missing models and new data detection
14
+ - Comprehensive error handling and logging
15
+ - Lock file mechanism to prevent concurrent runs
16
+
17
+ ### 2. `update_models.sh` (Linux/Unix Bash)
18
+ Production-ready automation script for cron jobs with git integration.
19
+
20
+ **Features:**
21
+ - Same functionality as PowerShell version but for Unix systems
22
+ - Memory and CPU resource limits
23
+ - Git integration for automatic log syncing
24
+ - Process locking and error recovery
25
+
26
+ ### 3. `startup_check.ps1` (Windows Startup)
27
+ Lightweight script that runs when you start your laptop.
28
+
29
+ **Features:**
30
+ - Quick model update check on system startup
31
+ - Desktop notification if models are updated
32
+ - Automatic git sync of startup logs
33
+ - Minimal resource usage
34
+
35
+ ## Setup Instructions
36
+
37
+ ### Prerequisites
38
+
39
+ 1. **Git Repository Setup**
40
+ ```bash
41
+ # Make sure your UFC project is a git repository
42
+ cd /path/to/ufc
43
+ git init # if not already a git repo
44
+ git remote add origin https://github.com/yourusername/ufc.git
45
+
46
+ # Configure git credentials (for automation)
47
+ git config user.name "Your Name"
48
+ git config user.email "[email protected]"
49
+
50
+ # Optional: Set up credential caching to avoid password prompts
51
+ git config credential.helper store
52
+ ```
53
+
54
+ 2. **Create logs directory**
55
+ ```bash
56
+ mkdir -p logs
57
+ ```
58
+
59
+ ### Windows Setup (PowerShell Scripts)
60
+
61
+ #### 1. Configure Script Paths
62
+ Edit the script files and update the `PROJECT_DIR` variable:
63
+ ```powershell
64
+ $PROJECT_DIR = "C:\Users\Alvaro\Desktop\ufc" # Update this path
65
+ ```
66
+
67
+ #### 2. Set Execution Policy
68
+ ```powershell
69
+ # Run as Administrator
70
+ Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
71
+ ```
72
+
73
+ #### 3. Schedule with Task Scheduler
74
+
75
+ **For Regular Updates (`update_models.ps1`):**
76
+ 1. Open Task Scheduler (`taskschd.msc`)
77
+ 2. Create Basic Task
78
+ - Name: "UFC Model Update"
79
+ - Trigger: Daily (or your preferred frequency)
80
+ - Action: Start a program
81
+ - Program: `powershell.exe`
82
+ - Arguments: `-File "C:\Users\Alvaro\Desktop\ufc\scripts\update_models.ps1"`
83
+
84
+ **For Startup Check (`startup_check.ps1`):**
85
+ 1. Create Basic Task
86
+ - Name: "UFC Startup Check"
87
+ - Trigger: At startup
88
+ - Action: Start a program
89
+ - Program: `powershell.exe`
90
+ - Arguments: `-File "C:\Users\Alvaro\Desktop\ufc\scripts\startup_check.ps1"`
91
+
92
+ ### Linux/Unix Setup (Bash Scripts)
93
+
94
+ #### 1. Configure Script Paths
95
+ Edit `update_models.sh` and update the path:
96
+ ```bash
97
+ PROJECT_DIR="/path/to/your/ufc" # Update this path
98
+ ```
99
+
100
+ #### 2. Make Scripts Executable
101
+ ```bash
102
+ chmod +x scripts/update_models.sh
103
+ ```
104
+
105
+ #### 3. Setup Cron Job
106
+ ```bash
107
+ # Edit crontab
108
+ crontab -e
109
+
110
+ # Add line for daily updates at 2 AM
111
+ 0 2 * * * /path/to/ufc/scripts/update_models.sh
112
+
113
+ # Or for updates every 6 hours
114
+ 0 */6 * * * /path/to/ufc/scripts/update_models.sh
115
+ ```
116
+
117
+ ## Git Integration Features
118
+
119
+ ### Automatic Commits
120
+ The scripts automatically commit and push:
121
+ - **Log files** (`logs/model_update.log`, `logs/startup_update.log`)
122
+ - **Model files** (if retrained)
123
+ - **Output files** (predictions, accuracy reports, etc.)
124
+ - **Data files** (if updated with new fights)
125
+
126
+ ### Commit Messages
127
+ Automated commits use descriptive messages:
128
+ - `"Automated model update: 2025-01-15 14:30:22"`
129
+ - `"Startup model check: 2025-01-15 08:15:33"`
130
+
131
+ ### Git Error Handling
132
+ - Scripts verify git repository existence
133
+ - Check for changes before committing
134
+ - Handle network errors gracefully
135
+ - Fall back to local commits if push fails
136
+ - Continue operation even if git fails
137
+
138
+ ## Monitoring and Logs
139
+
140
+ ### Log Files
141
+ - `logs/model_update.log` - Main automation logs
142
+ - `logs/startup_update.log` - Startup check logs
143
+ - `output/model_results.json` - Latest prediction results
144
+
145
+ ### What Gets Logged
146
+ - Pipeline execution start/end times
147
+ - Model retraining decisions
148
+ - Git operations (add, commit, push)
149
+ - Error messages and stack traces
150
+ - Resource usage and timeouts
151
+
152
+ ### Sample Log Output
153
+ ```
154
+ [2025-01-15 14:30:15] Starting automated model update and git sync...
155
+ [2025-01-15 14:30:16] Running model update pipeline...
156
+ [2025-01-15 14:32:45] Model update pipeline completed successfully.
157
+ [2025-01-15 14:32:46] Syncing changes to git repository...
158
+ [2025-01-15 14:32:46] Git: Adding all changes
159
+ [2025-01-15 14:32:47] Git: Adding all changes completed successfully
160
+ [2025-01-15 14:32:47] Git: Committing changes
161
+ [2025-01-15 14:32:48] Git: Committing changes completed successfully
162
+ [2025-01-15 14:32:48] Git: Pushing to remote repository
163
+ [2025-01-15 14:32:52] Git: Pushing to remote repository completed successfully
164
+ [2025-01-15 14:32:52] Successfully pushed all changes to git repository.
165
+ [2025-01-15 14:32:52] Automated update completed successfully with git sync.
166
+ ```
167
+
168
+ ## Security Considerations
169
+
170
+ ### Git Credentials
171
+ - Use SSH keys instead of passwords for git authentication
172
+ - Consider using git credential helpers for HTTPS
173
+ - Never hardcode credentials in scripts
174
+
175
+ ### File Permissions
176
+ ```bash
177
+ # Secure script files
178
+ chmod 750 scripts/*.sh
179
+ chmod 750 scripts/*.ps1
180
+
181
+ # Secure log directory
182
+ chmod 755 logs/
183
+ ```
184
+
185
+ ## Troubleshooting
186
+
187
+ ### Common Issues
188
+
189
+ 1. **Git Authentication Errors**
190
+ ```bash
191
+ # Setup SSH key authentication
192
+ ssh-keygen -t ed25519 -C "[email protected]"
193
+ # Add public key to GitHub/GitLab
194
+ ```
195
+
196
+ 2. **PowerShell Execution Policy**
197
+ ```powershell
198
+ # Check current policy
199
+ Get-ExecutionPolicy
200
+
201
+ # Set to allow scripts
202
+ Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
203
+ ```
204
+
205
+ 3. **Path Issues**
206
+ - Verify PROJECT_DIR paths in all scripts
207
+ - Use absolute paths to avoid confusion
208
+ - Check that Python is in system PATH
209
+
210
+ 4. **Resource Limits**
211
+ - Adjust memory limits in scripts if needed
212
+ - Monitor system resources during execution
213
+ - Consider running during off-peak hours
214
+
215
+ ### Debug Mode
216
+ Add debug logging by modifying scripts:
217
+ ```powershell
218
+ # PowerShell debug
219
+ $DebugPreference = "Continue"
220
+ ```
221
+
222
+ ```bash
223
+ # Bash debug
224
+ set -x # Add to top of script
225
+ ```
226
+
227
+ ## Customization
228
+
229
+ ### Frequency
230
+ - Modify cron schedule or Task Scheduler triggers
231
+ - Consider UFC event calendar for optimal timing
232
+ - Balance between freshness and resource usage
233
+
234
+ ### Resource Limits
235
+ ```powershell
236
+ # PowerShell - adjust timeout
237
+ $MAX_TIMEOUT_MINUTES = 180 # 3 hours
238
+ ```
239
+
240
+ ```bash
241
+ # Bash - adjust memory and timeout
242
+ MAX_MEMORY="8G" # Increase memory limit
243
+ NICE_LEVEL="5" # Higher priority
244
+ ```
245
+
246
+ ### Notification Settings
247
+ Modify `startup_check.ps1` to customize notifications:
248
+ ```powershell
249
+ # Custom notification
250
+ [System.Windows.Forms.MessageBox]::Show("Custom message", "Title", "OK", "Information")
251
+ ```
252
+
253
+ ## Support
254
+
255
+ For issues or questions:
256
+ 1. Check log files for error details
257
+ 2. Verify git repository status manually
258
+ 3. Test scripts manually before scheduling
259
+ 4. Review this documentation for configuration details
scripts/startup_check.ps1 CHANGED
@@ -11,22 +11,77 @@ function Write-Log {
11
  Write-Host "[$timestamp] $Message"
12
  }
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  try {
15
  Write-Log "Startup model check initiated..."
16
  Set-Location $PROJECT_DIR
17
 
18
  # Run a quick check (won't retrain unless needed)
 
19
  $result = python -m src.main --pipeline update 2>&1
20
- Write-Log "Update result: $result"
21
 
22
- if ($result -like "*retraining*") {
 
 
 
 
23
  # Show notification if models were updated
24
  Add-Type -AssemblyName System.Windows.Forms
25
- [System.Windows.Forms.MessageBox]::Show("UFC models were updated with new data!", "Model Update", "OK", "Information")
 
 
 
26
  }
27
 
28
  } catch {
29
  Write-Log "Error during startup check: $($_.Exception.Message)"
 
 
 
 
 
 
 
30
  }
31
 
32
  Write-Log "Startup check completed."
 
11
  Write-Host "[$timestamp] $Message"
12
  }
13
 
14
+ # Function to safely execute git commands
15
+ function Invoke-GitCommand {
16
+ param($Command, $Description)
17
+ try {
18
+ Write-Log "Git: $Description"
19
+ $result = Invoke-Expression "git $Command" 2>&1
20
+ if ($LASTEXITCODE -eq 0) {
21
+ Write-Log "Git: $Description completed successfully"
22
+ return $true
23
+ } else {
24
+ Write-Log "Git: $Description failed with exit code $LASTEXITCODE"
25
+ return $false
26
+ }
27
+ } catch {
28
+ Write-Log "Git: Error executing $Description - $($_.Exception.Message)"
29
+ return $false
30
+ }
31
+ }
32
+
33
+ # Function to commit and push changes
34
+ function Push-ChangesToGit {
35
+ if (!(Test-Path ".git")) {
36
+ Write-Log "Not in a git repository. Skipping git operations."
37
+ return
38
+ }
39
+
40
+ # Check git status
41
+ $gitStatus = git status --porcelain 2>&1
42
+ if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($gitStatus)) {
43
+ Write-Log "No changes to commit or git error."
44
+ return
45
+ }
46
+
47
+ # Add and commit changes
48
+ if ((Invoke-GitCommand "add ." "Adding startup changes") -and
49
+ (Invoke-GitCommand "commit -m `"Startup model check: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')`"" "Committing startup changes")) {
50
+ Invoke-GitCommand "push" "Pushing startup changes to remote"
51
+ }
52
+ }
53
+
54
  try {
55
  Write-Log "Startup model check initiated..."
56
  Set-Location $PROJECT_DIR
57
 
58
  # Run a quick check (won't retrain unless needed)
59
+ Write-Log "Running model update pipeline..."
60
  $result = python -m src.main --pipeline update 2>&1
61
+ Write-Log "Pipeline result: $result"
62
 
63
+ # Push logs and any changes to git
64
+ Write-Log "Syncing changes to git repository..."
65
+ Push-ChangesToGit
66
+
67
+ if ($result -like "*retraining*" -or $result -like "*new data*") {
68
  # Show notification if models were updated
69
  Add-Type -AssemblyName System.Windows.Forms
70
+ [System.Windows.Forms.MessageBox]::Show("UFC models were updated with new data and synced to git!", "Model Update", "OK", "Information")
71
+ Write-Log "Models were updated and synced to git."
72
+ } else {
73
+ Write-Log "No model updates needed, logs synced to git."
74
  }
75
 
76
  } catch {
77
  Write-Log "Error during startup check: $($_.Exception.Message)"
78
+
79
+ # Try to push error logs to git
80
+ try {
81
+ Push-ChangesToGit
82
+ } catch {
83
+ Write-Log "Failed to push error logs to git: $($_.Exception.Message)"
84
+ }
85
  }
86
 
87
  Write-Log "Startup check completed."
scripts/update_models.ps1 CHANGED
@@ -1,5 +1,5 @@
1
  # UFC Model Update Script for Windows Task Scheduler
2
- # This script safely updates models with resource limits
3
 
4
  # Configuration
5
  $PROJECT_DIR = "C:\Users\Alvaro\Desktop\ufc" # Change this to your actual path
@@ -21,6 +21,72 @@ function Write-Log {
21
  Write-Host "[$timestamp] $Message"
22
  }
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  # Check if another update is already running
25
  if (Test-Path $LOCK_FILE) {
26
  Write-Log "Another update process is already running. Exiting."
@@ -31,28 +97,38 @@ if (Test-Path $LOCK_FILE) {
31
  $PID | Out-File -FilePath $LOCK_FILE
32
 
33
  try {
34
- Write-Log "Starting model update check..."
35
 
36
  # Change to project directory
37
  Set-Location $PROJECT_DIR
38
 
 
 
 
 
 
 
39
  # Create a job to run the update with timeout
 
40
  $job = Start-Job -ScriptBlock {
41
  param($projectDir)
42
  Set-Location $projectDir
43
- python -m src.main --pipeline update
44
  } -ArgumentList $PROJECT_DIR
45
 
46
  # Wait for job completion with timeout
 
47
  if (Wait-Job $job -Timeout ($MAX_TIMEOUT_MINUTES * 60)) {
48
  $result = Receive-Job $job
49
  $exitCode = $job.State
50
 
51
  if ($exitCode -eq "Completed") {
52
- Write-Log "Model update completed successfully."
53
- Write-Log "Output: $result"
 
54
  } else {
55
- Write-Log "Model update failed. State: $exitCode"
 
56
  }
57
  } else {
58
  Write-Log "Model update timed out after $MAX_TIMEOUT_MINUTES minutes. Stopping job."
@@ -61,12 +137,30 @@ try {
61
 
62
  Remove-Job $job -Force
63
 
 
 
 
 
 
 
 
 
 
 
64
  } catch {
65
- Write-Log "Error during model update: $($_.Exception.Message)"
 
 
 
 
 
 
 
 
66
  } finally {
67
  # Cleanup lock file
68
  if (Test-Path $LOCK_FILE) {
69
  Remove-Item $LOCK_FILE -Force
70
  }
71
- Write-Log "Update check completed."
72
  }
 
1
  # UFC Model Update Script for Windows Task Scheduler
2
+ # This script safely updates models with resource limits and pushes logs to git
3
 
4
  # Configuration
5
  $PROJECT_DIR = "C:\Users\Alvaro\Desktop\ufc" # Change this to your actual path
 
21
  Write-Host "[$timestamp] $Message"
22
  }
23
 
24
+ # Function to safely execute git commands
25
+ function Invoke-GitCommand {
26
+ param($Command, $Description)
27
+ try {
28
+ Write-Log "Git: $Description"
29
+ $result = Invoke-Expression "git $Command" 2>&1
30
+ if ($LASTEXITCODE -eq 0) {
31
+ Write-Log "Git: $Description completed successfully"
32
+ if ($result) { Write-Log "Git output: $result" }
33
+ return $true
34
+ } else {
35
+ Write-Log "Git: $Description failed with exit code $LASTEXITCODE"
36
+ Write-Log "Git error: $result"
37
+ return $false
38
+ }
39
+ } catch {
40
+ Write-Log "Git: Error executing $Description - $($_.Exception.Message)"
41
+ return $false
42
+ }
43
+ }
44
+
45
+ # Function to commit and push changes
46
+ function Push-ChangesToGit {
47
+ Write-Log "Starting git operations..."
48
+
49
+ # Check if we're in a git repository
50
+ if (!(Test-Path ".git")) {
51
+ Write-Log "Not in a git repository. Skipping git operations."
52
+ return
53
+ }
54
+
55
+ # Check git status
56
+ $gitStatus = git status --porcelain 2>&1
57
+ if ($LASTEXITCODE -ne 0) {
58
+ Write-Log "Failed to check git status. Skipping git operations."
59
+ return
60
+ }
61
+
62
+ if ([string]::IsNullOrWhiteSpace($gitStatus)) {
63
+ Write-Log "No changes to commit."
64
+ return
65
+ }
66
+
67
+ # Add all changes
68
+ if (!(Invoke-GitCommand "add ." "Adding all changes")) {
69
+ return
70
+ }
71
+
72
+ # Create commit message with timestamp
73
+ $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
74
+ $commitMessage = "Automated model update: $timestamp"
75
+
76
+ # Commit changes
77
+ if (!(Invoke-GitCommand "commit -m `"$commitMessage`"" "Committing changes")) {
78
+ return
79
+ }
80
+
81
+ # Push to remote
82
+ if (!(Invoke-GitCommand "push" "Pushing to remote repository")) {
83
+ Write-Log "Failed to push changes. Changes are committed locally."
84
+ return
85
+ }
86
+
87
+ Write-Log "Successfully pushed all changes to git repository."
88
+ }
89
+
90
  # Check if another update is already running
91
  if (Test-Path $LOCK_FILE) {
92
  Write-Log "Another update process is already running. Exiting."
 
97
  $PID | Out-File -FilePath $LOCK_FILE
98
 
99
  try {
100
+ Write-Log "Starting automated model update and git sync..."
101
 
102
  # Change to project directory
103
  Set-Location $PROJECT_DIR
104
 
105
+ # Verify we're in the right directory
106
+ if (!(Test-Path "src\main.py")) {
107
+ Write-Log "Error: Not in UFC project directory. Expected to find src\main.py"
108
+ exit 1
109
+ }
110
+
111
  # Create a job to run the update with timeout
112
+ Write-Log "Running model update pipeline..."
113
  $job = Start-Job -ScriptBlock {
114
  param($projectDir)
115
  Set-Location $projectDir
116
+ python -m src.main --pipeline update 2>&1
117
  } -ArgumentList $PROJECT_DIR
118
 
119
  # Wait for job completion with timeout
120
+ $updateSuccess = $false
121
  if (Wait-Job $job -Timeout ($MAX_TIMEOUT_MINUTES * 60)) {
122
  $result = Receive-Job $job
123
  $exitCode = $job.State
124
 
125
  if ($exitCode -eq "Completed") {
126
+ Write-Log "Model update pipeline completed successfully."
127
+ Write-Log "Pipeline output: $result"
128
+ $updateSuccess = $true
129
  } else {
130
+ Write-Log "Model update pipeline failed. State: $exitCode"
131
+ Write-Log "Pipeline output: $result"
132
  }
133
  } else {
134
  Write-Log "Model update timed out after $MAX_TIMEOUT_MINUTES minutes. Stopping job."
 
137
 
138
  Remove-Job $job -Force
139
 
140
+ # Always attempt to push logs and any changes to git
141
+ Write-Log "Syncing changes to git repository..."
142
+ Push-ChangesToGit
143
+
144
+ if ($updateSuccess) {
145
+ Write-Log "Automated update completed successfully with git sync."
146
+ } else {
147
+ Write-Log "Automated update completed with errors, but logs have been synced to git."
148
+ }
149
+
150
  } catch {
151
+ Write-Log "Critical error during automated update: $($_.Exception.Message)"
152
+
153
+ # Try to push error logs to git
154
+ try {
155
+ Set-Location $PROJECT_DIR
156
+ Push-ChangesToGit
157
+ } catch {
158
+ Write-Log "Failed to push error logs to git: $($_.Exception.Message)"
159
+ }
160
  } finally {
161
  # Cleanup lock file
162
  if (Test-Path $LOCK_FILE) {
163
  Remove-Item $LOCK_FILE -Force
164
  }
165
+ Write-Log "Automated update process finished."
166
  }
scripts/update_models.sh CHANGED
@@ -1,7 +1,7 @@
1
  #!/bin/bash
2
 
3
  # UFC Model Update Script for Cron
4
- # This script safely updates models with resource limits
5
 
6
  # Configuration
7
  PROJECT_DIR="/path/to/your/ufc" # Change this to your actual path
@@ -16,6 +16,70 @@ mkdir -p "$PROJECT_DIR/logs"
16
  # Function to log with timestamp
17
  log() {
18
  echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$LOG_FILE"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  }
20
 
21
  # Check if another update is already running
@@ -30,21 +94,30 @@ echo $$ > "$LOCK_FILE"
30
  # Cleanup function
31
  cleanup() {
32
  rm -f "$LOCK_FILE"
33
- log "Update process finished."
34
  }
35
 
36
  # Set trap to cleanup on exit
37
  trap cleanup EXIT
38
 
39
- log "Starting model update check..."
40
 
41
  # Change to project directory
42
  cd "$PROJECT_DIR"
43
 
 
 
 
 
 
 
 
 
44
  # Run the update with resource limits
45
  # nice: lower CPU priority
46
  # timeout: kill if it takes longer than 2 hours
47
  # ulimit: limit memory usage
 
48
  nice -n "$NICE_LEVEL" timeout 7200 bash -c "
49
  ulimit -v $((4 * 1024 * 1024)) # 4GB virtual memory limit
50
  python -m src.main --pipeline update 2>&1
@@ -53,13 +126,22 @@ nice -n "$NICE_LEVEL" timeout 7200 bash -c "
53
  # Check exit code
54
  EXIT_CODE=$?
55
  if [ $EXIT_CODE -eq 0 ]; then
56
- log "Model update completed successfully."
 
57
  elif [ $EXIT_CODE -eq 124 ]; then
58
  log "Model update timed out after 2 hours."
59
  elif [ $EXIT_CODE -eq 137 ]; then
60
  log "Model update killed due to memory limit."
61
  else
62
- log "Model update failed with exit code: $EXIT_CODE"
63
  fi
64
 
65
- log "Update check completed."
 
 
 
 
 
 
 
 
 
1
  #!/bin/bash
2
 
3
  # UFC Model Update Script for Cron
4
+ # This script safely updates models with resource limits and pushes logs to git
5
 
6
  # Configuration
7
  PROJECT_DIR="/path/to/your/ufc" # Change this to your actual path
 
16
  # Function to log with timestamp
17
  log() {
18
  echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$LOG_FILE"
19
+ echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
20
+ }
21
+
22
+ # Function to safely execute git commands
23
+ git_command() {
24
+ local command="$1"
25
+ local description="$2"
26
+
27
+ log "Git: $description"
28
+ if output=$(git $command 2>&1); then
29
+ log "Git: $description completed successfully"
30
+ if [ -n "$output" ]; then
31
+ log "Git output: $output"
32
+ fi
33
+ return 0
34
+ else
35
+ log "Git: $description failed with exit code $?"
36
+ log "Git error: $output"
37
+ return 1
38
+ fi
39
+ }
40
+
41
+ # Function to commit and push changes
42
+ push_changes_to_git() {
43
+ log "Starting git operations..."
44
+
45
+ # Check if we're in a git repository
46
+ if [ ! -d ".git" ]; then
47
+ log "Not in a git repository. Skipping git operations."
48
+ return
49
+ fi
50
+
51
+ # Check git status
52
+ if ! git_status=$(git status --porcelain 2>&1); then
53
+ log "Failed to check git status. Skipping git operations."
54
+ return
55
+ fi
56
+
57
+ if [ -z "$git_status" ]; then
58
+ log "No changes to commit."
59
+ return
60
+ fi
61
+
62
+ # Add all changes
63
+ if ! git_command "add ." "Adding all changes"; then
64
+ return
65
+ fi
66
+
67
+ # Create commit message with timestamp
68
+ local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
69
+ local commit_message="Automated model update: $timestamp"
70
+
71
+ # Commit changes
72
+ if ! git_command "commit -m \"$commit_message\"" "Committing changes"; then
73
+ return
74
+ fi
75
+
76
+ # Push to remote
77
+ if ! git_command "push" "Pushing to remote repository"; then
78
+ log "Failed to push changes. Changes are committed locally."
79
+ return
80
+ fi
81
+
82
+ log "Successfully pushed all changes to git repository."
83
  }
84
 
85
  # Check if another update is already running
 
94
  # Cleanup function
95
  cleanup() {
96
  rm -f "$LOCK_FILE"
97
+ log "Automated update process finished."
98
  }
99
 
100
  # Set trap to cleanup on exit
101
  trap cleanup EXIT
102
 
103
+ log "Starting automated model update and git sync..."
104
 
105
  # Change to project directory
106
  cd "$PROJECT_DIR"
107
 
108
+ # Verify we're in the right directory
109
+ if [ ! -f "src/main.py" ]; then
110
+ log "Error: Not in UFC project directory. Expected to find src/main.py"
111
+ exit 1
112
+ fi
113
+
114
+ log "Running model update pipeline..."
115
+
116
  # Run the update with resource limits
117
  # nice: lower CPU priority
118
  # timeout: kill if it takes longer than 2 hours
119
  # ulimit: limit memory usage
120
+ UPDATE_SUCCESS=false
121
  nice -n "$NICE_LEVEL" timeout 7200 bash -c "
122
  ulimit -v $((4 * 1024 * 1024)) # 4GB virtual memory limit
123
  python -m src.main --pipeline update 2>&1
 
126
  # Check exit code
127
  EXIT_CODE=$?
128
  if [ $EXIT_CODE -eq 0 ]; then
129
+ log "Model update pipeline completed successfully."
130
+ UPDATE_SUCCESS=true
131
  elif [ $EXIT_CODE -eq 124 ]; then
132
  log "Model update timed out after 2 hours."
133
  elif [ $EXIT_CODE -eq 137 ]; then
134
  log "Model update killed due to memory limit."
135
  else
136
+ log "Model update pipeline failed with exit code: $EXIT_CODE"
137
  fi
138
 
139
+ # Always attempt to push logs and any changes to git
140
+ log "Syncing changes to git repository..."
141
+ push_changes_to_git
142
+
143
+ if [ "$UPDATE_SUCCESS" = true ]; then
144
+ log "Automated update completed successfully with git sync."
145
+ else
146
+ log "Automated update completed with errors, but logs have been synced to git."
147
+ fi