github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/modules/job/dispatch.go (about) 1 package job 2 3 import ( 4 "context" 5 6 "github.com/pkg/errors" 7 8 confmq "github.com/machinefi/w3bstream/pkg/depends/conf/mq" 9 "github.com/machinefi/w3bstream/pkg/depends/kit/logr" 10 "github.com/machinefi/w3bstream/pkg/depends/kit/mq" 11 "github.com/machinefi/w3bstream/pkg/modules/robot_notifier" 12 "github.com/machinefi/w3bstream/pkg/modules/robot_notifier/lark" 13 ) 14 15 func Dispatch(ctx context.Context, t mq.Task) { 16 ctx, l := logr.Start(ctx, "job.Dispatch", 17 "subject", t.Subject(), 18 "task_id", t.ID(), 19 ) 20 defer l.End() 21 22 tasks := confmq.MustMqFromContext(ctx) 23 24 if err := tasks.TaskBoard.Dispatch(tasks.TaskWorker.Channel, t); err != nil { 25 if body, _err := lark.Build(ctx, "job dispatching", "WARNING", err.Error()); _err != nil { 26 l.Warn(errors.Wrap(_err, "build lark message")) 27 } else { 28 if _err = robot_notifier.Push(ctx, body, nil); _err != nil { 29 l.Warn(errors.Wrap(_err, "notifier push message")) 30 } 31 } 32 33 l.Error(err) 34 } 35 }