fix(sse): sending correctly formatted events & exiting function

This commit is contained in:
2025-04-22 16:42:04 +01:00
parent 90ea845521
commit 526044d1e3
2 changed files with 4 additions and 1 deletions

View File

@ -46,6 +46,8 @@ func ListenNewImageEvents(db *sql.DB, eventManager *EventManager) {
ctx := context.Background() ctx := context.Background()
go func() { go func() {
time.Sleep(10 * time.Second)
image, err := imageModel.GetToProcessWithData(ctx, imageId) image, err := imageModel.GetToProcessWithData(ctx, imageId)
if err != nil { if err != nil {
databaseEventLog.Error("Failed to GetToProcessWithData", "error", err) databaseEventLog.Error("Failed to GetToProcessWithData", "error", err)

View File

@ -303,9 +303,10 @@ func main() {
return return
case data := <-imageNotifier: case data := <-imageNotifier:
fmt.Printf("Status received: %s\n", data) fmt.Printf("Status received: %s\n", data)
fmt.Fprintf(w, "data: %s-%s\n", data, time.Now().String()) fmt.Fprintf(w, "event: data\ndata: %s-%s\n\n", data, time.Now().String())
w.(http.Flusher).Flush() w.(http.Flusher).Flush()
cancel() cancel()
return
} }
} }
}) })