-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner_listeners.go
38 lines (33 loc) · 978 Bytes
/
runner_listeners.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package server
import (
"context"
"github.com/iron-io/functions/api/models"
)
type RunnerListener interface {
// BeforeDispatch called before a function run
BeforeDispatch(ctx context.Context, route *models.Route) error
// AfterDispatch called after a function run
AfterDispatch(ctx context.Context, route *models.Route) error
}
// AddRunListeners adds a listener that will be fired before and after a function run.
func (s *Server) AddRunnerListener(listener RunnerListener) {
s.runnerListeners = append(s.runnerListeners, listener)
}
func (s *Server) FireBeforeDispatch(ctx context.Context, route *models.Route) error {
for _, l := range s.runnerListeners {
err := l.BeforeDispatch(ctx, route)
if err != nil {
return err
}
}
return nil
}
func (s *Server) FireAfterDispatch(ctx context.Context, route *models.Route) error {
for _, l := range s.runnerListeners {
err := l.AfterDispatch(ctx, route)
if err != nil {
return err
}
}
return nil
}