CadHubManage/scripts/auto_revit_callback.ps1
sladro 08623bf4d6 feat: Enhance SerialBatchExecutor with pre-batch cleanup and task execution improvements
- Added pre-batch cleanup functionality to SerialBatchExecutor, allowing for cleanup tasks before processing items.
- Introduced new task execution phases and improved error handling for task submissions.
- Implemented inter-step delays and between-items delays for better task management.
- Updated logging to capture detailed events during batch processing.
- Enhanced configuration options for plugins in software_config.yaml to support new features.
- Added tests for pre-batch cleanup and auto-close scenarios to ensure robust handling of edge cases.
- Created a PowerShell script for automated callback handling from Revit.
2026-03-03 16:13:19 +08:00

62 lines
1.9 KiB
PowerShell

param(
[string]$BackendBaseUrl = "http://127.0.0.1:8000",
[string]$LogFile = "",
[string]$Token = "revit-callback-token",
[int]$LookbackLines = 400
)
$ErrorActionPreference = "Stop"
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
if (-not $LogFile) {
$today = Get-Date -Format "yyyy-MM-dd"
$LogFile = ".\logs\operation_logs\operation_$today.jsonl"
}
if (-not (Test-Path $LogFile)) {
throw "Log file not found: $LogFile"
}
$callbackUrl = ($BackendBaseUrl.TrimEnd("/")) + "/api/v1/plugin-callbacks/task-result"
Write-Host "Watching: $LogFile"
Write-Host "Callback: $callbackUrl"
$sent = @{}
while ($true) {
$lines = Get-Content -Path $LogFile -Tail $LookbackLines
foreach ($line in $lines) {
if ($line -notmatch '"operation":"batch_step_waiting_callback"') { continue }
$obj = $null
try {
$obj = $line | ConvertFrom-Json
} catch {
continue
}
$executionId = $obj.extra_data.execution_id
if (-not $executionId) { continue }
if ($sent.ContainsKey($executionId)) { continue }
$payload = @{
execution_id = $executionId
software_id = "revit"
status = "success"
error_message = $null
result = @{ source = "auto_revit_callback_ps1" }
finished_at = (Get-Date).ToUniversalTime().ToString("o")
token = $Token
} | ConvertTo-Json -Depth 5
try {
$resp = Invoke-RestMethod -Method Post -Uri $callbackUrl -ContentType "application/json" -Body $payload
$sent[$executionId] = $true
Write-Host ("[{0}] callback sent execution_id={1} accepted={2}" -f (Get-Date -Format "HH:mm:ss"), $executionId, $resp.accepted)
} catch {
Write-Host ("[{0}] callback failed execution_id={1} error={2}" -f (Get-Date -Format "HH:mm:ss"), $executionId, $_.Exception.Message)
}
}
Start-Sleep -Milliseconds 700
}