Repository navigation
update replay parked to work against the catchup service #684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fff1dc4
update replay parked to work against the catchup service
StuartFerguson 168e621
Merge branch 'main' into task/#676_support_catchup_service
StuartFerguson 8011699
Update parked queue replay endpoints and tests
StuartFerguson e92249e
Merge branch 'task/#676_support_catchup_service' of https://github.co…
StuartFerguson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
ScheduledTasks/ReplayParkedQueue/ReplayParkedQueue_EventStore.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| param ( | ||
| [Parameter(Mandatory = $true)] | ||
| [string]$BaseUrl, | ||
|
|
||
| [Parameter()] | ||
| [System.Management.Automation.PSCredential]$Credential, | ||
|
|
||
| [string]$LogDirectory = "C:\home\txnproc\trace", | ||
| [int]$LogRetentionDays = 7 | ||
| ) | ||
|
|
||
| # ========================= | ||
| # Logging setup | ||
| # ========================= | ||
| if (-not (Test-Path $LogDirectory)) { | ||
| New-Item -ItemType Directory -Path $LogDirectory -Force | Out-Null | ||
| } | ||
|
|
||
| function Get-LogFilePath { | ||
| $date = (Get-Date).ToString("yyyy-MM-dd") | ||
| Join-Path $LogDirectory "ReplayParkedSubscriptions-$date.log" | ||
| } | ||
|
|
||
| function Write-Trace { | ||
| param ( | ||
| [string]$Level, | ||
| [string]$Message | ||
| ) | ||
|
|
||
| $timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss.fff") | ||
| $entry = "$timestamp [$Level] $Message" | ||
| Add-Content -Path (Get-LogFilePath) -Value $entry | ||
| } | ||
|
|
||
| # ========================= | ||
| # Log retention cleanup | ||
| # ========================= | ||
| $cutoffDate = (Get-Date).Date.AddDays(-$LogRetentionDays) | ||
|
|
||
| Get-ChildItem -Path $LogDirectory -Filter "ReplayParkedSubscriptions-*.log" -File | | ||
| Where-Object { | ||
| if ($_.Name -match 'ReplayParkedSubscriptions-(\d{4}-\d{2}-\d{2})\.log') { | ||
| [DateTime]::ParseExact($matches[1], 'yyyy-MM-dd', $null) -lt $cutoffDate | ||
| } | ||
| else { | ||
| $false | ||
| } | ||
| } | | ||
| ForEach-Object { | ||
| try { | ||
| Remove-Item $_.FullName -Force | ||
| } | ||
| catch { | ||
| Write-Trace "WARN" "Failed to remove stale log file $($_.FullName): $($_.Exception.Message)" | ||
| } | ||
| } | ||
|
|
||
| Write-Trace "INFO" "Script started. BaseUrl=$BaseUrl" | ||
|
|
||
| # ========================= | ||
| # Auth header | ||
| # ========================= | ||
| $AuthHeader = @{} | ||
| if ($null -ne $Credential) { | ||
| $networkCredential = $Credential.GetNetworkCredential() | ||
| $username = $networkCredential.UserName | ||
| $password = $networkCredential.Password | ||
|
|
||
| $AuthHeader.Authorization = "Basic " + | ||
| [Convert]::ToBase64String( | ||
| [Text.Encoding]::ASCII.GetBytes("$username`:$password") | ||
| ) | ||
| } | ||
|
|
||
| # ========================= | ||
| # Query subscriptions | ||
| # ========================= | ||
| try { | ||
| Write-Trace "INFO" "Querying persistent subscriptions" | ||
| $subscriptions = Invoke-RestMethod ` | ||
| -Method GET ` | ||
| -Uri "$BaseUrl/subscriptions" ` | ||
| -Headers $AuthHeader | ||
| } | ||
| catch { | ||
| Write-Trace "ERROR" "Failed to query subscriptions: $($_.Exception.Message)" | ||
| exit 1 | ||
| } | ||
|
|
||
| # ========================= | ||
| # Process subscriptions | ||
| # ========================= | ||
| foreach ($sub in $subscriptions) { | ||
|
|
||
| $stream = $sub.eventStreamId | ||
| $group = $sub.groupName | ||
|
|
||
| #Write-Trace "INFO" "Processing subscription [$stream][$group]" | ||
|
|
||
| $streamEncoded = if ($stream -eq '$all') { | ||
| '%24all' | ||
| } | ||
| else { | ||
| [System.Web.HttpUtility]::UrlEncode($stream) | ||
| } | ||
|
|
||
| $infoUrl = "$BaseUrl/subscriptions/$streamEncoded/$group/info" | ||
|
|
||
| try { | ||
| $info = Invoke-RestMethod ` | ||
| -Method GET ` | ||
| -Uri $infoUrl ` | ||
| -Headers $AuthHeader | ||
| } | ||
| catch { | ||
| Write-Trace "WARN" "Failed to get info for [$stream][$group]: $($_.Exception.Message)" | ||
| continue | ||
| } | ||
|
|
||
| $parkedCount = $info.parkedMessageCount | ||
| #Write-Trace "INFO" "[$stream][$group] parkedMessageCount=$parkedCount" | ||
|
|
||
| if ($parkedCount -gt 0) { | ||
| $replayUrl = "$BaseUrl/subscriptions/$streamEncoded/$group/replayParked?from=0" | ||
|
|
||
| Write-Trace "INFO" "Replaying [$parkedCount] parked messages for [$stream][$group]" | ||
|
|
||
| try { | ||
| Invoke-RestMethod ` | ||
| -Method POST ` | ||
| -Uri $replayUrl ` | ||
| -Headers $AuthHeader | ||
|
|
||
| Write-Trace "INFO" "Replay triggered successfully for [$stream][$group]" | ||
| } | ||
| catch { | ||
| Write-Trace "ERROR" "Replay failed for [$stream][$group]: $($_.Exception.Message)" | ||
| } | ||
| } | ||
| #else { | ||
| #Write-Trace "INFO" "No parked messages for [$stream][$group]" | ||
| #} | ||
| } | ||
|
|
||
| Write-Trace "INFO" "Script completed" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.