updated postwork jobs pushed by sse
This commit is contained in:
parent
724fbf52c9
commit
39c38b6bad
BIN
backend/dist/nsfwapp-linux-amd64
vendored
BIN
backend/dist/nsfwapp-linux-amd64
vendored
Binary file not shown.
BIN
backend/dist/nsfwapp.exe
vendored
BIN
backend/dist/nsfwapp.exe
vendored
Binary file not shown.
BIN
backend/dist/nsfwapp_amd64.deb
vendored
BIN
backend/dist/nsfwapp_amd64.deb
vendored
Binary file not shown.
@ -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) {
|
||||||
|
|||||||
@ -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
29
backend/sse_test.go
Normal 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")
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user