updated postwork jobs pushed by sse

This commit is contained in:
Linrador 2026-06-23 20:55:49 +02:00
parent 724fbf52c9
commit 39c38b6bad
7 changed files with 60 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1435,6 +1435,8 @@ func publishQueuedPostworkState(job *RecordJob, postKey, postFile, postAssetID s
Running: st.Running, Running: st.Running,
MaxParallel: st.MaxParallel, MaxParallel: st.MaxParallel,
}) })
_ = publishJobSnapshot(job.ID)
} }
func handlePostworkEnqueueFailure(job *RecordJob, out string, postTarget JobStatus, postFile, postAssetID string) { func handlePostworkEnqueueFailure(job *RecordJob, out string, postTarget JobStatus, postFile, postAssetID string) {

View File

@ -421,12 +421,30 @@ func isVisiblePostworkJobForSSE(j *RecordJob) bool {
if !isPostworkJobForSSE(j) { if !isPostworkJobForSSE(j) {
return false return false
} }
if isActivePostworkJobForSSE(j) {
return true
}
if isTerminalJobStatusForSSE(j.Status) { if isTerminalJobStatusForSSE(j.Status) {
return false return false
} }
return true return true
} }
func isActivePostworkJobForSSE(j *RecordJob) bool {
if j == nil {
return false
}
if strings.TrimSpace(j.PostWorkKey) == "" {
return false
}
if j.PostWork == nil {
return true
}
state := strings.ToLower(strings.TrimSpace(j.PostWork.State))
return state == "" || state == "queued" || state == "running"
}
func shouldPublishModelEventForJob(j *RecordJob) bool { func shouldPublishModelEventForJob(j *RecordJob) bool {
return isVisibleDownloadJobForSSE(j) || isVisiblePostworkJobForSSE(j) return isVisibleDownloadJobForSSE(j) || isVisiblePostworkJobForSSE(j)
} }

29
backend/sse_test.go Normal file
View File

@ -0,0 +1,29 @@
package main
import "testing"
func TestIsVisiblePostworkJobForSSEAllowsFinishedQueuedPostwork(t *testing.T) {
job := &RecordJob{
Status: JobFinished,
Phase: "postwork",
PostWorkKey: "postwork:test",
PostWork: &PostWorkKeyStatus{
State: "queued",
},
}
if !isVisiblePostworkJobForSSE(job) {
t.Fatal("expected finished job with queued postwork to remain visible for SSE")
}
}
func TestIsVisiblePostworkJobForSSERejectsFinishedWithoutActivePostwork(t *testing.T) {
job := &RecordJob{
Status: JobFinished,
Phase: "postwork",
}
if isVisiblePostworkJobForSSE(job) {
t.Fatal("expected finished job without active postwork to be hidden from SSE")
}
}

View File

@ -1560,6 +1560,11 @@ export default function App() {
const isVisiblePostworkJobForSSE = (job: RecordJob): boolean => { const isVisiblePostworkJobForSSE = (job: RecordJob): boolean => {
if (!isPostworkJobForCount(job)) return false if (!isPostworkJobForCount(job)) return false
const pw = (job as any)?.postWork
const state = String(pw?.state ?? '').trim().toLowerCase()
if (String((job as any)?.postWorkKey ?? '').trim() && (!state || state === 'queued' || state === 'running')) {
return true
}
if (isTerminalJobStatusForCount((job as any)?.status)) return false if (isTerminalJobStatusForCount((job as any)?.status)) return false
return true return true
} }
@ -3141,6 +3146,10 @@ export default function App() {
} }
} }
const onGlobalJob = (ev: MessageEvent) => {
onModelJobEventRef.current?.(ev)
}
void loadJobs() void loadJobs()
void loadDoneCount() void loadDoneCount()
void loadTaskStateOnce() void loadTaskStateOnce()
@ -3161,6 +3170,7 @@ export default function App() {
} }
es.addEventListener('doneChanged', onDoneChanged as any) es.addEventListener('doneChanged', onDoneChanged as any)
es.addEventListener('job', onGlobalJob as any)
es.addEventListener('autostart', onAutostart as any) es.addEventListener('autostart', onAutostart as any)
es.addEventListener('finishedPostwork', onFinishedPostwork as any) es.addEventListener('finishedPostwork', onFinishedPostwork as any)
es.addEventListener('taskState', onTaskState as any) es.addEventListener('taskState', onTaskState as any)
@ -3189,6 +3199,7 @@ export default function App() {
if (es) { if (es) {
es.removeEventListener('doneChanged', onDoneChanged as any) es.removeEventListener('doneChanged', onDoneChanged as any)
es.removeEventListener('job', onGlobalJob as any)
es.removeEventListener('autostart', onAutostart as any) es.removeEventListener('autostart', onAutostart as any)
es.removeEventListener('finishedPostwork', onFinishedPostwork as any) es.removeEventListener('finishedPostwork', onFinishedPostwork as any)
es.removeEventListener('taskState', onTaskState as any) es.removeEventListener('taskState', onTaskState as any)