48 lines
2.9 KiB
PowerShell
48 lines
2.9 KiB
PowerShell
$ErrorActionPreference = 'Stop'
|
|
$taskRoot = 'C:\laragon\www\portal-investidor'
|
|
$privateDirectory = Join-Path $taskRoot 'storage\app\private\investmoz-v2\portal-audit'
|
|
$plan = Get-Content -LiteralPath (Join-Path $privateDirectory 'service-followup-latest.json') -Raw -Encoding UTF8 | ConvertFrom-Json
|
|
if ($plan.target.port -ne 55441 -or $plan.target.database -notmatch '^workflow_upgrade_\d{8}_\d{6}_test$' -or $plan.base -ne 'https://portal-investidor.test:18448') { throw 'Isolated QA required' }
|
|
$taskStamp = $plan.target.database.Replace('workflow_upgrade_','').Replace('_test','')
|
|
$name = 'InvestMoz QA watchdog ' + $taskStamp
|
|
$service = New-Object -ComObject 'Schedule.Service'
|
|
$service.Connect()
|
|
$folder = $service.GetFolder('\')
|
|
$definition = $service.NewTask(0)
|
|
$definition.RegistrationInfo.Description = 'QA ONLY: services-followup-qa on PostgreSQL 55441; no active queue or services.'
|
|
$definition.Principal.Id = 'QAUser'
|
|
$definition.Principal.UserId = [Security.Principal.WindowsIdentity]::GetCurrent().Name
|
|
$definition.Principal.LogonType = 3
|
|
$definition.Principal.RunLevel = 0
|
|
$definition.Actions.Context = 'QAUser'
|
|
$definition.Settings.Enabled = $false
|
|
$definition.Settings.MultipleInstances = 2
|
|
$definition.Settings.AllowHardTerminate = $true
|
|
$definition.Settings.DisallowStartIfOnBatteries = $false
|
|
$definition.Settings.StopIfGoingOnBatteries = $false
|
|
$definition.Settings.StartWhenAvailable = $true
|
|
$definition.Settings.ExecutionTimeLimit = 'PT3M'
|
|
$timer = $definition.Triggers.Create(1)
|
|
$timer.StartBoundary = (Get-Date).AddMinutes(1).ToString('yyyy-MM-ddTHH:mm:ss')
|
|
$timer.Repetition.Interval = 'PT1M'
|
|
$action = $definition.Actions.Create(0)
|
|
$action.Path = 'C:\laragon\bin\php\php-8.5.11-Win32-vs17-x64\php.exe'
|
|
$action.Arguments = '-c "C:\laragon\bin\php\php-8.5.11-Win32-vs17-x64\php.ini" -d memory_limit=256M "' + (Join-Path $taskRoot 'tools\portal-service-followup-worker-qa.php') + '"'
|
|
$action.WorkingDirectory = $taskRoot
|
|
$proof = @{at=[DateTime]::UtcNow.ToString('o');name=$name;target=$plan.target;base=$plan.base;execution_limit_seconds=180;interval_seconds=60;php_process_memory_limit='256M';identity='current QA interactive user; not a LocalService permission test';active_queue_consumed=0;active_tasks_changed=0}
|
|
try {
|
|
$existing = $null
|
|
try { $existing = $folder.GetTask($name) } catch {}
|
|
if ($existing) { throw 'Own QA task already exists; inspect before repeating' }
|
|
$registered = $folder.RegisterTaskDefinition($name,$definition,2,$null,$null,3,$null)
|
|
$proof.result = 'registered_disabled'
|
|
$proof.task_enabled = $registered.Enabled
|
|
} catch {
|
|
$proof.result = 'registration_failed'
|
|
$proof.error_type = $_.Exception.GetType().FullName
|
|
$proof.hresult = $_.Exception.HResult
|
|
}
|
|
$utf8 = New-Object System.Text.UTF8Encoding($false)
|
|
[IO.File]::WriteAllText((Join-Path $privateDirectory 'service-followup-scheduler-registration-qa.json'),($proof | ConvertTo-Json -Depth 5),$utf8)
|
|
$proof | ConvertTo-Json -Compress -Depth 4
|