diff --git a/handlers/misttriggers/trigger_broker.go b/handlers/misttriggers/trigger_broker.go index 50b460c46..ff40cc7b8 100644 --- a/handlers/misttriggers/trigger_broker.go +++ b/handlers/misttriggers/trigger_broker.go @@ -2,9 +2,11 @@ package misttriggers import ( "context" + "fmt" "sync" "github.com/golang/glog" + "github.com/livepeer/catalyst-api/clients" "golang.org/x/sync/errgroup" ) @@ -27,6 +29,8 @@ import ( // handler for these sorts of triggers. type TriggerBroker interface { + SetupMistTriggers(clients.MistAPIClient, string) error + OnStreamBuffer(func(context.Context, *StreamBufferPayload) error) TriggerStreamBuffer(context.Context, *StreamBufferPayload) @@ -72,6 +76,27 @@ type triggerBroker struct { streamSourceFuncs funcGroup[StreamSourcePayload] } +var triggers = map[string]bool{ + TRIGGER_PUSH_END: false, + TRIGGER_PUSH_OUT_START: true, + TRIGGER_PUSH_REWRITE: true, + TRIGGER_STREAM_BUFFER: false, + TRIGGER_LIVE_TRACK_LIST: false, + TRIGGER_USER_NEW: true, + TRIGGER_USER_END: false, + TRIGGER_STREAM_SOURCE: true, +} + +func (b *triggerBroker) SetupMistTriggers(mist clients.MistAPIClient, triggerCallback string) error { + for name, sync := range triggers { + err := mist.AddTrigger([]string{}, name, triggerCallback, sync) + if err != nil { + return fmt.Errorf("error setting up mist trigger trigger=%s error=%w", name, err) + } + } + return nil +} + func (b *triggerBroker) OnStreamBuffer(cb func(context.Context, *StreamBufferPayload) error) { b.streamBufferFuncs.RegisterNoResponse(cb) } diff --git a/main.go b/main.go index ad5e12558..0d5a833d6 100644 --- a/main.go +++ b/main.go @@ -317,6 +317,17 @@ func main() { } if cli.IsClusterMode() { + // Configure Mist Triggers + if cli.MistEnabled && cli.MistTriggerSetup { + mistTriggerHandlerEndpoint := fmt.Sprintf("%s/api/mist/trigger", cli.OwnInternalURL()) + err := broker.SetupMistTriggers(mist, mistTriggerHandlerEndpoint) + if err != nil { + glog.Error("catalyst-api was unable to communicate with MistServer to set up its triggers.") + glog.Error("hint: are you trying to boot catalyst-api without Mist for development purposes? use the flag -no-mist") + glog.Fatalf("error setting up Mist triggers err=%s", err) + } + } + // Start cron style apps to run periodically if cli.ShouldMistCleanup() { app := "mist-cleanup.sh"