Private/Get-KadenOpenJournal.ps1
|
function Get-KadenOpenJournal { <# .SYNOPSIS Return the first transaction journal that has not completed. #> [CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$ChildRoot ) $txnRoot = Join-Path $ChildRoot (Join-Path '.kaden' 'transactions') if (-not (Test-Path -LiteralPath $txnRoot)) { return $null } $journals = @(Get-ChildItem -LiteralPath $txnRoot -Recurse -Filter 'journal.json' -File -ErrorAction SilentlyContinue) foreach ($journalFile in $journals) { try { $doc = Get-Content -LiteralPath $journalFile.FullName -Raw | ConvertFrom-Json } catch { return [pscustomobject]@{ Path = $journalFile.FullName Journal = $null Broken = $true } } if ([string]$doc.status -ne 'completed') { return [pscustomobject]@{ Path = $journalFile.FullName Journal = $doc Broken = $false } } } return $null } |