-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package activities |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Sleep activity | ||
|
||
This activity allows you to make the current thread sleep for a specified amount of time. | ||
|
||
## Installation | ||
|
||
### Flogo Web | ||
|
||
#### Start | ||
|
||
Start a container of Flogo Web UI : | ||
|
||
```bash | ||
docker run --name flogo -it -d -p 3303:3303 -e FLOGO_NO_ENGINE_RECREATION=false flogo/flogo-docker eula-accept | ||
``` | ||
*The environment variable FLOGO_NO_ENGINE_RECREATION=false allows to force import of installed contributions.* | ||
|
||
#### Installation of the activity | ||
|
||
To install the activity into the started container : | ||
|
||
```bash | ||
docker exec -it flogo sh -c 'cd /tmp/flogo-web/build/server/local/engines/flogo-web && flogo install github.com/square-it/flogo-contrib-activities/sleep' | ||
``` | ||
|
||
Restart the container | ||
```bash | ||
docker restart flogo | ||
``` | ||
|
||
### Flogo CLI | ||
```bash | ||
flogo install github.com/square-it/flogo-contrib-activities/sleep | ||
``` | ||
|
||
## Schema | ||
Inputs and Outputs: | ||
|
||
```json | ||
{ | ||
"inputs":[ | ||
{ | ||
"name": "duration", | ||
"type": "string", | ||
"required": "true" | ||
} | ||
], | ||
"outputs": [ | ||
|
||
] | ||
} | ||
``` | ||
|
||
## Settings | ||
| Setting | Required | Description | | ||
|:------------|:---------|:------------| | ||
| duration | True | The amount of a time during which the thread will be sleeping.<br />This duration can be expressed by any valid expression described by [time.ParseDuration](https://golang.org/pkg/time/#ParseDuration) Go method.<br />For instance: "500ms", "5s", "1m30s" | | ||
|
||
## Outputs | ||
|
||
No output | ||
|
||
## Examples | ||
|
||
### Simple example | ||
|
||
```json | ||
{ | ||
"id": "sleep_1", | ||
"name": "Sleep5s", | ||
"description": "Sleeps for five seconds", | ||
"activity": { | ||
"ref": "github.com/square-it/flogo-contrib-activities/sleep", | ||
"input": { | ||
"duration": "5s" | ||
}, | ||
"output": { | ||
} | ||
} | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "sleep", | ||
"version": "0.0.1", | ||
"type": "flogo:activity", | ||
"title": "Sleep", | ||
"description": "Sleeps for a specified amount of time", | ||
"author": "mathieu.debove@sqits.net", | ||
"ref": "github.com/square-it/flogo-contrib-activities/sleep", | ||
"inputs": [ | ||
{ | ||
"name": "duration", | ||
"type": "string", | ||
"required": "true" | ||
} | ||
], | ||
"outputs": [ | ||
|
||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package sleep | ||
|
||
import ( | ||
"github.com/TIBCOSoftware/flogo-lib/core/activity" | ||
"github.com/TIBCOSoftware/flogo-lib/logger" | ||
"io/ioutil" | ||
"testing" | ||
) | ||
|
||
var activityMetadata *activity.Metadata | ||
|
||
func init() { | ||
log.SetLogLevel(logger.ErrorLevel) | ||
} | ||
|
||
func getActivityMetadata() *activity.Metadata { | ||
if activityMetadata == nil { | ||
jsonMetadataBytes, err := ioutil.ReadFile("activity.json") | ||
if err != nil { | ||
panic("No Json Metadata found for activity.json path") | ||
} | ||
|
||
activityMetadata = activity.NewMetadata(string(jsonMetadataBytes)) | ||
} | ||
|
||
return activityMetadata | ||
} | ||
|
||
func TestCreate(t *testing.T) { | ||
act := NewActivity(getActivityMetadata()) | ||
|
||
if act == nil { | ||
t.Error("Activity Not Created") | ||
t.Fail() | ||
return | ||
} | ||
} |