Skip to content

Commit

Permalink
Revert removal of dynamic Mist trigger setup (#1365)
Browse files Browse the repository at this point in the history
  • Loading branch information
leszko authored Aug 22, 2024
1 parent 79b04ee commit ec0c2a4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
25 changes: 25 additions & 0 deletions handlers/misttriggers/trigger_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)

Expand Down Expand Up @@ -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)
}
Expand Down
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ec0c2a4

Please sign in to comment.