forked from project-flogo/contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
activity.go
60 lines (45 loc) · 1.21 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
package channel
import (
"fmt"
"github.com/project-flogo/core/activity"
"github.com/project-flogo/core/engine/channels"
)
func init() {
_ = activity.Register(&Activity{})
}
var activityMd = activity.ToMetadata(&Input{})
// Activity is an Activity that is used to publish some data on a channel
// inputs : {channel, data}
// outputs: none
type Activity struct {
}
// Metadata returns the activity's metadata
func (a *Activity) Metadata() *activity.Metadata {
return activityMd
}
// Eval publishes the data on the specified channel
func (a *Activity) Eval(ctx activity.Context) (done bool, err error) {
input := &Input{}
err = ctx.GetInputObject(input)
if err != nil {
return false, err
}
if len(input.Channel) == 0 {
return false, fmt.Errorf("channel name must be specified")
}
ch := channels.Get(input.Channel)
if ch == nil {
return false, fmt.Errorf("channel '%s' not registered with engine", input.Channel)
}
blocking := true
//todo should we allow publish new wait?
if blocking {
ch.Publish(input.Data)
} else {
ch.PublishNoWait(input.Data)
}
if logger := ctx.Logger(); logger.DebugEnabled() {
logger.Debugf("Published on '%s' value: %+v", input.Channel, input.Data)
}
return true, nil
}