| # OpenCode Space Keep-Alive Script | |
| # Pings the HuggingFace Space every 5 minutes to keep it active | |
| $SpaceUrl = "https://abbasyk60-opencode.static.hf.space" | |
| $LogFile = "$PSScriptRoot\keep-alive.log" | |
| Write-Host "=========================================" | |
| Write-Host " OpenCode Space Keep-Alive" | |
| Write-Host "=========================================" | |
| Write-Host "" | |
| Write-Host "Space URL: $SpaceUrl" | |
| Write-Host "Press Ctrl+C to stop" | |
| Write-Host "" | |
| while ($true) { | |
| try { | |
| $response = Invoke-WebRequest -Uri $SpaceUrl -Method Head -TimeoutSec 10 -UseBasicParsing | |
| $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" | |
| $logEntry = "[$timestamp] OK - Status: $($response.StatusCode)" | |
| Write-Host $logEntry | |
| Add-Content -Path $LogFile -Value $logEntry | |
| } catch { | |
| $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" | |
| $logEntry = "[$timestamp] ERROR - $($_.Exception.Message)" | |
| Write-Host $logEntry -ForegroundColor Red | |
| Add-Content -Path $LogFile -Value $logEntry | |
| } | |
| # Wait 5 minutes before next ping | |
| Start-Sleep -Seconds 300 | |
| } | |