From 13170a33e80ef58ab01e1bcbb746b2fae31d52e3 Mon Sep 17 00:00:00 2001 From: John Costa Date: Tue, 29 Jul 2025 15:40:18 +0100 Subject: [PATCH] fix: adding wait group so we can concurrently call these --- backend/events.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/backend/events.go b/backend/events.go index 158e056..bda6c0f 100644 --- a/backend/events.go +++ b/backend/events.go @@ -10,6 +10,7 @@ import ( "screenmark/screenmark/agents" "screenmark/screenmark/models" "strconv" + "sync" "time" "github.com/charmbracelet/log" @@ -64,14 +65,22 @@ func ListenNewImageEvents(db *sql.DB, notifier *Notifier[Notification]) { } descriptionAgent := agents.NewDescriptionAgent(createLogger("Description 📝", splitWriter), imageModel) - err = descriptionAgent.Describe(createLogger("Description 📓", splitWriter), image.Image.ID, image.Image.ImageName, image.Image.Image) - - if err != nil { - log.Error(err) - } - listAgent := agents.NewListAgent(createLogger("Lists 🖋️", splitWriter), listModel) - listAgent.RunAgent(image.UserID, image.ImageID, image.Image.ImageName, image.Image.Image) + + var wg sync.WaitGroup + wg.Add(2) + + go func() { + descriptionAgent.Describe(createLogger("Description 📓", splitWriter), image.Image.ID, image.Image.ImageName, image.Image.Image) + wg.Done() + }() + + go func() { + listAgent.RunAgent(image.UserID, image.ImageID, image.Image.ImageName, image.Image.Image) + wg.Done() + }() + + wg.Wait() _, err = imageModel.FinishProcessing(ctx, image.ID) if err != nil {