Show Suno queue progress and fix track numbering
This commit is contained in:
+35
-1
@@ -15,6 +15,8 @@ New-Item -ItemType Directory -Force -Path $inbox, $logs | Out-Null
|
||||
$queue = [System.Collections.Queue]::new()
|
||||
$queueIds = [System.Collections.Generic.HashSet[string]]::new()
|
||||
$activeJob = $null
|
||||
$lastProgressAt = [DateTime]::MinValue
|
||||
$lastProgressText = ""
|
||||
|
||||
function Resolve-LibraryRoot {
|
||||
param(
|
||||
@@ -135,6 +137,7 @@ function Start-SunoProcess {
|
||||
return [pscustomobject]@{
|
||||
jobId = $jobId
|
||||
pid = $process.Id
|
||||
process = $process
|
||||
log = $stdout
|
||||
errorLog = $stderr
|
||||
}
|
||||
@@ -153,10 +156,12 @@ function Save-Manifest {
|
||||
|
||||
function Update-Queue {
|
||||
if ($script:activeJob -and -not $script:activeJob.Process.HasExited) {
|
||||
Publish-ActiveJobProgress
|
||||
return
|
||||
}
|
||||
|
||||
if ($script:activeJob -and $script:activeJob.Process.HasExited) {
|
||||
Publish-ActiveJobProgress -Force
|
||||
Write-Host "Finished job $($script:activeJob.JobId) exit=$($script:activeJob.Process.ExitCode)"
|
||||
$script:activeJob = $null
|
||||
}
|
||||
@@ -174,7 +179,7 @@ function Update-Queue {
|
||||
$job = Start-SunoProcess $manifestPath
|
||||
$script:activeJob = [pscustomobject]@{
|
||||
JobId = $job.jobId
|
||||
Process = Get-Process -Id $job.pid
|
||||
Process = $job.process
|
||||
TrackId = $item.Id
|
||||
Title = $item.Title
|
||||
Log = $job.log
|
||||
@@ -184,6 +189,35 @@ function Update-Queue {
|
||||
}
|
||||
}
|
||||
|
||||
function Get-LastLogLine {
|
||||
param([string[]]$Paths)
|
||||
|
||||
foreach ($path in $Paths) {
|
||||
if (-not (Test-Path -LiteralPath $path)) { continue }
|
||||
$line = Get-Content -LiteralPath $path -Tail 20 -ErrorAction SilentlyContinue |
|
||||
Where-Object { "$_".Trim() } |
|
||||
Select-Object -Last 1
|
||||
if ($line) { return "$line" }
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
function Publish-ActiveJobProgress {
|
||||
param([switch]$Force)
|
||||
|
||||
if (-not $script:activeJob) { return }
|
||||
$now = Get-Date
|
||||
if (-not $Force -and ($now - $script:lastProgressAt).TotalSeconds -lt 10) { return }
|
||||
|
||||
$line = Get-LastLogLine @($script:activeJob.ErrorLog, $script:activeJob.Log)
|
||||
if (-not $line) { return }
|
||||
if (-not $Force -and $line -eq $script:lastProgressText) { return }
|
||||
|
||||
$script:lastProgressAt = $now
|
||||
$script:lastProgressText = $line
|
||||
Write-Host "[$($script:activeJob.JobId)] $($script:activeJob.Title): $line"
|
||||
}
|
||||
|
||||
function Add-TracksToQueue {
|
||||
param($Tracks, [string]$PageUrl)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user