File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed
Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -15,3 +15,4 @@ nuget.config
1515global.json
1616* .g.json
1717* .g.ps1
18+ scripts /build-agents /last-execution.txt
Original file line number Diff line number Diff line change 11$ErrorActionPreference = ' Stop'
22
3- # Remove all Docker images that have not been used for 7 days.
4- docker image prune - a -- filter " until=168h" -- force
3+ # Get the script's directory
4+ $scriptDir = $PSScriptRoot
5+ $lastExecutionFile = Join-Path $scriptDir " last-execution.txt"
56
6- # Pull this repo.
7- git pull
7+ # Check if the script has been executed in the last 24 hours
8+ $shouldExecute = $true
9+ if (Test-Path $lastExecutionFile ) {
10+ $lastExecutionTime = (Get-Item $lastExecutionFile ).LastWriteTime
11+ $timeSinceLastExecution = (Get-Date ) - $lastExecutionTime
12+
13+ if ($timeSinceLastExecution.TotalHours -lt 24 ) {
14+ Write-Host " Daily maintenance was already executed $ ( [math ]::Round($timeSinceLastExecution.TotalHours , 2 )) hours ago. Skipping execution."
15+ $shouldExecute = $false
16+ }
17+ }
18+
19+ if ($shouldExecute ) {
20+ Write-Host " Executing daily maintenance..."
21+
22+ # Update the last execution timestamp by touching the file
23+ " Last maintenance executed at $ ( Get-Date ) " | Out-File $lastExecutionFile - Encoding UTF8
24+
25+ # Remove all Docker images that have not been used for 7 days.
26+ docker image prune - a -- filter " until=168h" -- force
27+
28+ # Pull this repo.
29+ git pull
30+
31+ Write-Host " Daily maintenance completed successfully."
32+ }
You can’t perform that action at this time.
0 commit comments