-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathactivity.go
56 lines (42 loc) · 1.35 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
package sleep
import (
"github.com/TIBCOSoftware/flogo-lib/core/activity"
"github.com/TIBCOSoftware/flogo-lib/logger"
"time"
)
var log = logger.GetLogger("activity-sleep")
// SleepActivity is a stub for your Activity implementation
type SleepActivity struct {
metadata *activity.Metadata
}
// NewActivity creates a new activity
func NewActivity(metadata *activity.Metadata) activity.Activity {
return &SleepActivity{metadata: metadata}
}
// Metadata implements activity.Activity.Metadata
func (a *SleepActivity) Metadata() *activity.Metadata {
return a.metadata
}
// Eval implements activity.Activity.Eval
func (a *SleepActivity) Eval(activityContext activity.Context) (done bool, err error) {
// check input timeToSleepInMs
durationParameter, ok := activityContext.GetInput("duration").(string)
if !ok {
log.Error("The duration parameter is not a string.")
return false, nil
}
duration, err := time.ParseDuration(durationParameter)
if err != nil {
log.Errorf("Unable to parse duration '%s'.", durationParameter)
log.Error("Please read available format at https://golang.org/pkg/time/#ParseDuration.")
return false, nil
}
if duration == 0 {
log.Debug("No need to sleep.")
return true, nil
}
log.Debugf("Amount of time to sleep: %s", duration)
time.Sleep(duration)
log.Debugf("Thread has slept for %d ms", duration)
return true, nil
}