mirror of
https://github.com/computerim/impactflow-discovery.git
synced 2026-08-27 07:30:35 +00:00
Add Windows Task Scheduler runner for weekly check-ins
scripts/run-weekly-checkins.ps1: pure-Windows equivalent of the cron script — reads the admin API key from .env and POSTs /discovery/coaching/run via Invoke-RestMethod, logging to data/coaching-cron.log. README documents the Register-ScheduledTask command (weekly, StartWhenAvailable + WakeToRun) for a more robust schedule than WSL cron. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
# Weekly coaching check-in batch (Phase 3) for Windows Task Scheduler.
|
||||
# Reads the admin API key from .env and POSTs /discovery/coaching/run, which
|
||||
# generates a check-in for every eligible user whose cadence is due.
|
||||
# Override the target with $env:IMPACTFLOW_BASE_URL (default: local container).
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$dir = Split-Path -Parent $PSScriptRoot # repo root (scripts\..)
|
||||
$envFile = Join-Path $dir '.env'
|
||||
$log = Join-Path $dir 'data\coaching-cron.log'
|
||||
$base = if ($env:IMPACTFLOW_BASE_URL) { $env:IMPACTFLOW_BASE_URL } else { 'http://localhost:8011' }
|
||||
$ts = (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
|
||||
|
||||
try {
|
||||
$line = (Select-String -Path $envFile -Pattern '^IMPACTFLOW_API_KEY=' | Select-Object -First 1).Line
|
||||
$key = ($line -replace '^IMPACTFLOW_API_KEY=', '').Trim()
|
||||
if (-not $key) { throw "IMPACTFLOW_API_KEY not found in $envFile" }
|
||||
|
||||
$resp = Invoke-RestMethod -Method Post -Uri "$base/discovery/coaching/run" `
|
||||
-Headers @{ 'X-API-Key' = $key } -TimeoutSec 120
|
||||
"$ts $($resp | ConvertTo-Json -Compress)" | Add-Content -Path $log
|
||||
}
|
||||
catch {
|
||||
"$ts ERROR: $($_.Exception.Message)" | Add-Content -Path $log
|
||||
}
|
||||
Reference in New Issue
Block a user