forked from isaqueveras/outis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
outis.go
42 lines (34 loc) · 1.14 KB
/
outis.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
39
40
41
42
package outis
import (
"encoding/json"
"fmt"
"math/rand"
"strconv"
)
type server struct{}
func newOutis() IOutis { return &server{} }
func (server) Go(fn func() error) { fn() }
func (server) Wait() error { return nil }
// Init implements a business rule when initializing a routine
func (server) Init(ctx *Context) error {
ctx.Info(fmt.Sprintf("script '%s' (rid: %s) initialized", ctx.Name, ctx.RoutineID))
return nil
}
// Before implements a business rule before initializing script execution
func (server) Before(ctx *Context) error {
ctx.Id = ID(strconv.FormatInt(rand.Int63(), 10))
ctx.Info(fmt.Sprintf("script '%s' (rid: %s, id: %s) initialized", ctx.Name, ctx.RoutineID, ctx.Id))
return nil
}
// After implements a business rule after initializing script execution
func (server) After(ctx *Context) error {
ctx.Info(fmt.Sprintf("script '%s' (rid: %s, id: %s) finished", ctx.Name, ctx.RoutineID, ctx.Id))
return nil
}
// Event implements a business rule for event handling
func (server) Event(ctx *Context, event Event) {
if metric, ok := event.(EventMetric); ok {
value, _ := json.Marshal(metric)
ctx.Debug(string(value))
}
}