@@ -4,13 +4,15 @@ import (
44 "context"
55 "encoding/json"
66 "errors"
7+ "fmt"
78 "log/slog"
89 "strings"
910 "sync"
1011 "time"
1112
1213 "github.com/google/uuid"
1314 "github.com/w-h-a/workflow/internal/engine/clients/broker"
15+ "github.com/w-h-a/workflow/internal/engine/clients/notifier"
1416 "github.com/w-h-a/workflow/internal/engine/clients/reader"
1517 "github.com/w-h-a/workflow/internal/engine/clients/readwriter"
1618 "github.com/w-h-a/workflow/internal/task"
@@ -23,6 +25,7 @@ import (
2325type Service struct {
2426 broker broker.Broker
2527 readwriter readwriter.ReadWriter
28+ notifier notifier.Notifier
2629 queues map [string ]int
2730 locks map [string ]* sync.RWMutex
2831 mtx sync.RWMutex
@@ -286,6 +289,19 @@ func (s *Service) handleTask(ctx context.Context, data []byte) error {
286289
287290 s .removeTaskLock (t .ID )
288291
292+ event := notifier.Event {
293+ Source : "workflow-coordinator" ,
294+ Type : notifier .Success ,
295+ Title : fmt .Sprintf ("Task %s Completed Successfully" , t .ID ),
296+ Payload : map [string ]any {},
297+ }
298+
299+ if err := s .notifier .Notify (ctx , event ); err != nil {
300+ child .RecordError (err )
301+ child .SetStatus (codes .Error , err .Error ())
302+ return err
303+ }
304+
289305 child .SetStatus (codes .Ok , "task completed event handled" )
290306
291307 return nil
@@ -301,6 +317,21 @@ func (s *Service) handleTask(ctx context.Context, data []byte) error {
301317
302318 s .removeTaskLock (t .ID )
303319
320+ event := notifier.Event {
321+ Source : "workflow-coordinator" ,
322+ Type : notifier .Failure ,
323+ Title : fmt .Sprintf ("Task %s Failed" , t .ID ),
324+ Payload : map [string ]any {
325+ "error_msg" : t .Error ,
326+ },
327+ }
328+
329+ if err := s .notifier .Notify (ctx , event ); err != nil {
330+ child .RecordError (err )
331+ child .SetStatus (codes .Error , err .Error ())
332+ return err
333+ }
334+
304335 child .SetStatus (codes .Ok , "task failed event handled" )
305336
306337 return nil
@@ -377,10 +408,11 @@ func (s *Service) removeTaskLock(id string) {
377408 delete (s .locks , id )
378409}
379410
380- func New (b broker.Broker , rw readwriter.ReadWriter , qs map [string ]int ) * Service {
411+ func New (b broker.Broker , rw readwriter.ReadWriter , n notifier. Notifier , qs map [string ]int ) * Service {
381412 return & Service {
382413 broker : b ,
383414 readwriter : rw ,
415+ notifier : n ,
384416 queues : qs ,
385417 locks : map [string ]* sync.RWMutex {},
386418 mtx : sync.RWMutex {},
0 commit comments