-
Notifications
You must be signed in to change notification settings - Fork 64
/
activity.go
executable file
·81 lines (63 loc) · 1.66 KB
/
activity.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package log
import (
"fmt"
"github.com/project-flogo/core/activity"
"github.com/project-flogo/core/data/coerce"
)
func init() {
_ = activity.Register(&Activity{})
}
type Input struct {
Message string `md:"message"` // The message to log
AddDetails bool `md:"addDetails"` // Append contextual execution information to the log message
UsePrint bool `md:"usePrint"`
}
func (i *Input) ToMap() map[string]interface{} {
return map[string]interface{}{
"message": i.Message,
"addDetails": i.AddDetails,
"usePrint": i.UsePrint,
}
}
func (i *Input) FromMap(values map[string]interface{}) error {
var err error
i.Message, err = coerce.ToString(values["message"])
if err != nil {
return err
}
i.AddDetails, err = coerce.ToBool(values["addDetails"])
if err != nil {
return err
}
i.UsePrint, err = coerce.ToBool(values["usePrint"])
if err != nil {
return err
}
return nil
}
var activityMd = activity.ToMetadata(&Input{})
// Activity is an Activity that is used to log a message to the console
// inputs : {message, flowInfo}
// outputs: none
type Activity struct {
}
// Metadata returns the activity's metadata
func (a *Activity) Metadata() *activity.Metadata {
return activityMd
}
// Eval implements api.Activity.Eval - Logs the Message
func (a *Activity) Eval(ctx activity.Context) (done bool, err error) {
input := &Input{}
ctx.GetInputObject(input)
msg := input.Message
if input.AddDetails {
msg = fmt.Sprintf("'%s' - HostID [%s], HostName [%s], Activity [%s]", msg,
ctx.ActivityHost().ID(), ctx.ActivityHost().Name(), ctx.Name())
}
if input.UsePrint {
fmt.Println(msg)
} else {
ctx.Logger().Info(msg)
}
return true, nil
}