<# .SYNOPSIS Der naechtliche Lauf: uebernimmt faellig gewordene, zukunftsdatierte Aenderungen (Versetzung, Befoerderung, Karenz, Reorganisation). .DESCRIPTION Ruft /api/cron/apply-pending-changes mit CRON_SECRET auf. Laeuft als geplante Aufgabe "AlpenwerkHR Nachtlauf" taeglich um 03:00; von Hand: Start-ScheduledTask 'AlpenwerkHR Nachtlauf' Ergebnis in logs\nachtlauf.log. Eine Weiterleitung gilt als Fehler, nicht als Erfolg: genau so ist der Lauf im Docker-Betrieb lange unbemerkt ins Leere gegangen -- er bekam die Anmeldeseite mit 200 und meldete nichts. #> param([string]$Ziel = (Split-Path $PSScriptRoot -Parent)) . (Join-Path $PSScriptRoot 'gemeinsam.ps1') $protokoll = "$Ziel\logs\nachtlauf.log" function Write-Protokoll([string]$text) { Add-Content -LiteralPath $protokoll -Value ("{0} {1}" -f (Get-Date -Format 'yyyy-MM-dd HH:mm:ss'), $text) -Encoding UTF8 } try { $app = Read-EnvDatei "$Ziel\app.env" $port = $app['PORT'] if (-not $port) { $port = '3000' } if (-not $app['CRON_SECRET']) { throw "CRON_SECRET fehlt in $Ziel\app.env" } $antwort = Invoke-WebRequest -Uri "http://127.0.0.1:$port/api/cron/apply-pending-changes" ` -Headers @{ Authorization = "Bearer $($app['CRON_SECRET'])" } ` -UseBasicParsing -TimeoutSec 300 -MaximumRedirection 0 if ($antwort.StatusCode -ne 200) { throw "Antwort $($antwort.StatusCode) statt 200" } Write-Protokoll "ok $($antwort.Content)" } catch { Write-Protokoll "FEHLER $($_.Exception.Message)" exit 1 }