|
| 1 | +# Launches every Azure Function in its own Windows Terminal tab. |
| 2 | +# Edit the $functions list below to add/remove/reorder functions - it's the single source of truth. |
| 3 | + |
| 4 | +$ErrorActionPreference = "Stop" |
| 5 | +$functionsRoot = Resolve-Path (Join-Path $PSScriptRoot "..\src\Functions") |
| 6 | + |
| 7 | +$functions = @( |
| 8 | + # ── CaaS Integration ──────────────────────────────────────────────────────── |
| 9 | + @{ Path = "CaasIntegration\receiveCaasFile"; Port = 7060 }, |
| 10 | + |
| 11 | + # ── Participant Management Services ────────────────────────────────────────── |
| 12 | + @{ Path = "ParticipantManagementServices\ManageParticipant"; Port = 7061 }, |
| 13 | + @{ Path = "ParticipantManagementServices\ManageServiceNowParticipant"; Port = 7064 }, |
| 14 | + @{ Path = "ParticipantManagementServices\UpdateBlockedFlag"; Port = 7027 }, |
| 15 | + |
| 16 | + # ── Audit Services ─────────────────────────────────────────────────────────── |
| 17 | + @{ Path = "AuditServices\AuditWriter"; Port = 7062 }, |
| 18 | + |
| 19 | + # ── Exception Handling ─────────────────────────────────────────────────────── |
| 20 | + @{ Path = "ExceptionHandling\CreateException"; Port = 7070 }, |
| 21 | + @{ Path = "ExceptionHandling\UpdateException"; Port = 7073 }, |
| 22 | + |
| 23 | + # ── Screening Validation Service ───────────────────────────────────────────── |
| 24 | + @{ Path = "ScreeningValidationService\StaticValidation"; Port = 7074 }, |
| 25 | + @{ Path = "ScreeningValidationService\LookupValidation"; Port = 7075 }, |
| 26 | + @{ Path = "ScreeningValidationService\RemoveValidationException"; Port = 7085 }, |
| 27 | + |
| 28 | + # ── Demographic Services ───────────────────────────────────────────────────── |
| 29 | + @{ Path = "DemographicServices\DemographicDurableFunction"; Port = 7079 }, |
| 30 | + @{ Path = "DemographicServices\RetrievePDSDemographic"; Port = 8082 }, |
| 31 | + @{ Path = "DemographicServices\ManageCaasSubscription"; Port = 9084 }, |
| 32 | + |
| 33 | + # ── Cohort Distribution Services ───────────────────────────────────────────── |
| 34 | + @{ Path = "CohortDistributionServices\DistributeParticipant"; Port = 7063 }, |
| 35 | + @{ Path = "CohortDistributionServices\TransformDataService"; Port = 7080 }, |
| 36 | + @{ Path = "CohortDistributionServices\RetrieveCohortDistribution"; Port = 7078 }, |
| 37 | + @{ Path = "CohortDistributionServices\RetrieveCohortRequestAudit"; Port = 7086 }, |
| 38 | + |
| 39 | + # ── Service Now Integration ─────────────────────────────────────────────────── |
| 40 | + @{ Path = "ServiceNowIntegration\ServiceNowMessageHandler"; Port = 9092 }, |
| 41 | + @{ Path = "ServiceNowIntegration\ServiceNowCohortLookup"; Port = 7180 }, |
| 42 | + |
| 43 | + # ── Screening Data Services ─────────────────────────────────────────────────── |
| 44 | + @{ Path = "screeningDataServices\ExceptionManagementDataService"; Port = 7911 }, |
| 45 | + @{ Path = "screeningDataServices\ScreeningLkpDataService"; Port = 8996 }, |
| 46 | + @{ Path = "screeningDataServices\ParticipantDemographicDataService"; Port = 7993 }, |
| 47 | + @{ Path = "screeningDataServices\ParticipantManagementDataService"; Port = 7994 }, |
| 48 | + @{ Path = "screeningDataServices\CohortDistributionDataService"; Port = 7992 }, |
| 49 | + @{ Path = "screeningDataServices\ReferenceDataService"; Port = 7988 }, |
| 50 | + @{ Path = "screeningDataServices\GetValidationExceptions"; Port = 7071 }, |
| 51 | + @{ Path = "screeningDataServices\BsSelectRequestAudit"; Port = 7989 }, |
| 52 | + @{ Path = "screeningDataServices\NemsSubscriptionDataService"; Port = 7990 }, |
| 53 | + @{ Path = "screeningDataServices\GeneCodeLkpDataService"; Port = 7991 }, |
| 54 | + @{ Path = "screeningDataServices\HigherRiskReferralReasonLkpDataService"; Port = 7972 }, |
| 55 | + @{ Path = "screeningDataServices\ServiceNowCasesDataService"; Port = 9996 } |
| 56 | +) |
| 57 | + |
| 58 | +Write-Host "Functions root: $functionsRoot" -ForegroundColor DarkGray |
| 59 | + |
| 60 | +# Build all functions first |
| 61 | +Write-Host "Building $($functions.Count) Azure Functions..." -ForegroundColor Cyan |
| 62 | +foreach ($fn in $functions) { |
| 63 | + $cwd = Join-Path $functionsRoot $fn.Path |
| 64 | + $name = Split-Path $fn.Path -Leaf |
| 65 | + |
| 66 | + if (-not (Test-Path $cwd)) { |
| 67 | + Write-Host " [SKIP] $name - path not found: $cwd" -ForegroundColor Yellow |
| 68 | + continue |
| 69 | + } |
| 70 | + |
| 71 | + Write-Host " [BUILD] $name" -ForegroundColor DarkCyan |
| 72 | + $result = & dotnet publish "$cwd" -o "$cwd\bin\output" --nologo -v q 2>&1 |
| 73 | + if ($LASTEXITCODE -ne 0) { |
| 74 | + Write-Host " [FAIL] $name build failed:`n$result" -ForegroundColor Red |
| 75 | + exit 1 |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +Write-Host "All functions built successfully.`n" -ForegroundColor Green |
| 80 | + |
| 81 | +# Launch all functions |
| 82 | +Write-Host "Starting $($functions.Count) Azure Functions..." -ForegroundColor Cyan |
| 83 | + |
| 84 | +$hasWT = [bool](Get-Command wt.exe -ErrorAction SilentlyContinue) |
| 85 | +if (-not $hasWT) { |
| 86 | + Write-Host "Windows Terminal (wt.exe) not found - falling back to separate pwsh windows." -ForegroundColor Yellow |
| 87 | +} |
| 88 | + |
| 89 | +foreach ($fn in $functions) { |
| 90 | + $cwd = Join-Path $functionsRoot $fn.Path |
| 91 | + $name = Split-Path $fn.Path -Leaf |
| 92 | + $title = "$name :$($fn.Port)" |
| 93 | + |
| 94 | + if (-not (Test-Path $cwd)) { |
| 95 | + Write-Host " [SKIP] $title - path not found: $cwd" -ForegroundColor Yellow |
| 96 | + continue |
| 97 | + } |
| 98 | + |
| 99 | + Write-Host " [RUN] $title" -ForegroundColor Green |
| 100 | + |
| 101 | + if ($hasWT) { |
| 102 | + $wtArgs = "-w CohortFunctions new-tab --title `"$title`" -d `"$cwd`" pwsh.exe -NoExit -Command `"func start --port $($fn.Port)`"" |
| 103 | + Start-Process wt.exe -ArgumentList $wtArgs |
| 104 | + } else { |
| 105 | + Start-Process pwsh.exe -ArgumentList @( |
| 106 | + "-NoExit", "-Command", |
| 107 | + "Set-Location '$cwd'; `$Host.UI.RawUI.WindowTitle='$title'; func start --port $($fn.Port)" |
| 108 | + ) |
| 109 | + } |
| 110 | + |
| 111 | + # Waits until the port is actually listening before starting the next function |
| 112 | + $timeout = 60 |
| 113 | + $elapsed = 0 |
| 114 | + Write-Host " Waiting for port $($fn.Port)..." -ForegroundColor DarkGray |
| 115 | + while ($elapsed -lt $timeout) { |
| 116 | + $tcp = [System.Net.Sockets.TcpClient]::new() |
| 117 | + try { |
| 118 | + $tcp.Connect("localhost", $fn.Port) |
| 119 | + $tcp.Close() |
| 120 | + Write-Host " Port $($fn.Port) is up." -ForegroundColor DarkGreen |
| 121 | + break |
| 122 | + } catch { |
| 123 | + Start-Sleep -Seconds 1 |
| 124 | + $elapsed++ |
| 125 | + } finally { |
| 126 | + $tcp.Dispose() |
| 127 | + } |
| 128 | + } |
| 129 | + if ($elapsed -ge $timeout) { |
| 130 | + Write-Host " [WARN] Timed out waiting for port $($fn.Port) - continuing anyway." -ForegroundColor Yellow |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +Write-Host "`nAll functions launched. Check the 'CohortFunctions' Windows Terminal window." -ForegroundColor Cyan |
| 135 | + |
0 commit comments