Skip to content

Commit d6de892

Browse files
Merge pull request #100 from project-flogo/fix-issue-99
Fix issue 99
2 parents 8b7a53a + 50eb9ba commit d6de892

File tree

14 files changed

+143
-76
lines changed

14 files changed

+143
-76
lines changed

examples/flogo/creditcard/flogo.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"appModel": "1.0.0",
77
"imports": [
88
"github.com/project-flogo/contrib/trigger/rest",
9-
"github.com/project-flogo/rules/ruleaction",
10-
"github.com/project-flogo/legacybridge"
9+
"github.com/project-flogo/rules/ruleaction"
1110
],
1211
"triggers": [
1312
{

examples/flogo/creditcard/imports.go

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package main
2+
3+
import (
4+
_ "github.com/project-flogo/rules/ruleaction"
5+
_ "github.com/project-flogo/contrib/trigger/rest"
6+
)

examples/flogo/creditcard/main.go

+20-14
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,43 @@ import (
99

1010
_ "github.com/project-flogo/core/data/expression/script"
1111
"github.com/project-flogo/core/engine"
12-
"github.com/project-flogo/core/support/log"
13-
14-
_ "github.com/project-flogo/contrib/trigger/rest"
15-
_ "github.com/project-flogo/rules/ruleaction"
1612
)
1713

1814
var (
1915
cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file")
2016
memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file")
2117
cfgJson string
18+
cfgEngine string
2219
cfgCompressed bool
2320
)
2421

2522
func main() {
2623

24+
cpuProfiling := false
25+
2726
flag.Parse()
2827
if *cpuProfile != "" {
2928
f, err := os.Create(*cpuProfile)
3029
if err != nil {
31-
fmt.Println(fmt.Sprintf("Failed to create CPU profiling file due to error - %s", err.Error()))
30+
fmt.Fprintf(os.Stderr, "Failed to create CPU profiling file: %v\n", err)
31+
os.Exit(1)
32+
}
33+
if err = pprof.StartCPUProfile(f); err != nil {
34+
fmt.Fprintf(os.Stderr, "Failed to start CPU profiling: %v\n", err)
3235
os.Exit(1)
3336
}
34-
pprof.StartCPUProfile(f)
35-
defer pprof.StopCPUProfile()
37+
cpuProfiling = true
3638
}
3739

3840
cfg, err := engine.LoadAppConfig(cfgJson, cfgCompressed)
3941
if err != nil {
40-
log.RootLogger().Errorf("Failed to create engine: %s", err.Error())
42+
fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err)
4143
os.Exit(1)
4244
}
4345

44-
e, err := engine.New(cfg)
46+
e, err := engine.New(cfg, engine.ConfigOption(cfgEngine, cfgCompressed))
4547
if err != nil {
46-
log.RootLogger().Errorf("Failed to create engine: %s", err.Error())
48+
fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err)
4749
os.Exit(1)
4850
}
4951

@@ -52,17 +54,21 @@ func main() {
5254
if *memProfile != "" {
5355
f, err := os.Create(*memProfile)
5456
if err != nil {
55-
fmt.Println(fmt.Sprintf("Failed to create memory profiling file due to error - %s", err.Error()))
57+
fmt.Fprintf(os.Stderr, "Failed to create memory profiling file: %v\n", err)
5658
os.Exit(1)
5759
}
5860

5961
runtime.GC() // get up-to-date statistics
6062
if err := pprof.WriteHeapProfile(f); err != nil {
61-
fmt.Println(fmt.Sprintf("Failed to write memory profiling data to file due to error - %s", err.Error()))
63+
fmt.Fprintf(os.Stderr, "Failed to write memory profiling data: %v", err)
6264
os.Exit(1)
6365
}
64-
f.Close()
66+
_ = f.Close()
67+
}
68+
69+
if cpuProfiling {
70+
pprof.StopCPUProfile()
6571
}
6672

6773
os.Exit(code)
68-
}
74+
}

examples/flogo/simple-kafka/flogo.json

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
"version": "0.0.1",
55
"description": "Sample Flogo App",
66
"appModel": "1.0.0",
7+
"imports": [
8+
"github.com/project-flogo/contrib/trigger/kafka",
9+
"github.com/project-flogo/rules/ruleaction"
10+
],
711
"triggers": [
812
{
913
"id": "receive_kafka_message",
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package main
2+
3+
import (
4+
_ "github.com/project-flogo/contrib/trigger/kafka"
5+
_ "github.com/project-flogo/rules/ruleaction"
6+
)

examples/flogo/simple-kafka/main.go

+22-16
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,43 @@ import (
99

1010
_ "github.com/project-flogo/core/data/expression/script"
1111
"github.com/project-flogo/core/engine"
12-
"github.com/project-flogo/core/support/log"
13-
14-
_ "github.com/project-flogo/contrib/trigger/kafka"
15-
_ "github.com/project-flogo/rules/ruleaction"
1612
)
1713

1814
var (
1915
cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file")
2016
memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file")
21-
cfgJSON string
17+
cfgJson string
18+
cfgEngine string
2219
cfgCompressed bool
2320
)
2421

2522
func main() {
2623

24+
cpuProfiling := false
25+
2726
flag.Parse()
2827
if *cpuProfile != "" {
2928
f, err := os.Create(*cpuProfile)
3029
if err != nil {
31-
fmt.Println(fmt.Sprintf("Failed to create CPU profiling file due to error - %s", err.Error()))
30+
fmt.Fprintf(os.Stderr, "Failed to create CPU profiling file: %v\n", err)
31+
os.Exit(1)
32+
}
33+
if err = pprof.StartCPUProfile(f); err != nil {
34+
fmt.Fprintf(os.Stderr, "Failed to start CPU profiling: %v\n", err)
3235
os.Exit(1)
3336
}
34-
pprof.StartCPUProfile(f)
35-
defer pprof.StopCPUProfile()
37+
cpuProfiling = true
3638
}
3739

38-
cfg, err := engine.LoadAppConfig(cfgJSON, cfgCompressed)
40+
cfg, err := engine.LoadAppConfig(cfgJson, cfgCompressed)
3941
if err != nil {
40-
log.RootLogger().Errorf("Failed to create engine: %s", err.Error())
42+
fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err)
4143
os.Exit(1)
4244
}
4345

44-
e, err := engine.New(cfg)
46+
e, err := engine.New(cfg, engine.ConfigOption(cfgEngine, cfgCompressed))
4547
if err != nil {
46-
log.RootLogger().Errorf("Failed to create engine: %s", err.Error())
48+
fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err)
4749
os.Exit(1)
4850
}
4951

@@ -52,17 +54,21 @@ func main() {
5254
if *memProfile != "" {
5355
f, err := os.Create(*memProfile)
5456
if err != nil {
55-
fmt.Println(fmt.Sprintf("Failed to create memory profiling file due to error - %s", err.Error()))
57+
fmt.Fprintf(os.Stderr, "Failed to create memory profiling file: %v\n", err)
5658
os.Exit(1)
5759
}
5860

5961
runtime.GC() // get up-to-date statistics
6062
if err := pprof.WriteHeapProfile(f); err != nil {
61-
fmt.Println(fmt.Sprintf("Failed to write memory profiling data to file due to error - %s", err.Error()))
63+
fmt.Fprintf(os.Stderr, "Failed to write memory profiling data: %v", err)
6264
os.Exit(1)
6365
}
64-
f.Close()
66+
_ = f.Close()
67+
}
68+
69+
if cpuProfiling {
70+
pprof.StopCPUProfile()
6571
}
6672

6773
os.Exit(code)
68-
}
74+
}

examples/flogo/simple/flogo.json

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
"version": "0.0.1",
55
"description": "Sample Flogo App",
66
"appModel": "1.0.0",
7+
"imports": [
8+
"github.com/project-flogo/contrib/trigger/rest",
9+
"github.com/project-flogo/rules/ruleaction"
10+
],
711
"triggers": [
812
{
913
"id": "receive_http_message",

examples/flogo/simple/imports.go

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package main
2+
3+
import (
4+
_ "github.com/project-flogo/contrib/trigger/rest"
5+
_ "github.com/project-flogo/rules/ruleaction"
6+
)

examples/flogo/simple/main.go

+23-18
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,43 @@ import (
99

1010
_ "github.com/project-flogo/core/data/expression/script"
1111
"github.com/project-flogo/core/engine"
12-
"github.com/project-flogo/core/support/log"
13-
14-
_ "github.com/project-flogo/contrib/trigger/rest"
15-
_ "github.com/project-flogo/rules/ruleaction"
16-
1712
)
1813

1914
var (
20-
cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file")
21-
memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file")
22-
cfgJson string
15+
cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file")
16+
memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file")
17+
cfgJson string
18+
cfgEngine string
2319
cfgCompressed bool
2420
)
2521

2622
func main() {
2723

24+
cpuProfiling := false
25+
2826
flag.Parse()
2927
if *cpuProfile != "" {
3028
f, err := os.Create(*cpuProfile)
3129
if err != nil {
32-
fmt.Println(fmt.Sprintf("Failed to create CPU profiling file due to error - %s", err.Error()))
30+
fmt.Fprintf(os.Stderr, "Failed to create CPU profiling file: %v\n", err)
3331
os.Exit(1)
3432
}
35-
pprof.StartCPUProfile(f)
36-
defer pprof.StopCPUProfile()
33+
if err = pprof.StartCPUProfile(f); err != nil {
34+
fmt.Fprintf(os.Stderr, "Failed to start CPU profiling: %v\n", err)
35+
os.Exit(1)
36+
}
37+
cpuProfiling = true
3738
}
3839

3940
cfg, err := engine.LoadAppConfig(cfgJson, cfgCompressed)
4041
if err != nil {
41-
log.RootLogger().Errorf("Failed to create engine: %s", err.Error())
42+
fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err)
4243
os.Exit(1)
4344
}
4445

45-
e, err := engine.New(cfg)
46+
e, err := engine.New(cfg, engine.ConfigOption(cfgEngine, cfgCompressed))
4647
if err != nil {
47-
log.RootLogger().Errorf("Failed to create engine: %s", err.Error())
48+
fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err)
4849
os.Exit(1)
4950
}
5051

@@ -53,17 +54,21 @@ func main() {
5354
if *memProfile != "" {
5455
f, err := os.Create(*memProfile)
5556
if err != nil {
56-
fmt.Println(fmt.Sprintf("Failed to create memory profiling file due to error - %s", err.Error()))
57+
fmt.Fprintf(os.Stderr, "Failed to create memory profiling file: %v\n", err)
5758
os.Exit(1)
5859
}
5960

6061
runtime.GC() // get up-to-date statistics
6162
if err := pprof.WriteHeapProfile(f); err != nil {
62-
fmt.Println(fmt.Sprintf("Failed to write memory profiling data to file due to error - %s", err.Error()))
63+
fmt.Fprintf(os.Stderr, "Failed to write memory profiling data: %v", err)
6364
os.Exit(1)
6465
}
65-
f.Close()
66+
_ = f.Close()
67+
}
68+
69+
if cpuProfiling {
70+
pprof.StopCPUProfile()
6671
}
6772

6873
os.Exit(code)
69-
}
74+
}

examples/flogo/trackntrace/flogo.json

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"type": "flogo:app",
44
"version": "0.0.1",
55
"appModel": "1.0.0",
6+
"imports": [
7+
"github.com/project-flogo/contrib/trigger/rest",
8+
"github.com/project-flogo/rules/ruleaction"
9+
],
610
"triggers": [
711
{
812
"id": "receive_http_message",

examples/flogo/trackntrace/imports.go

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package main
2+
3+
import (
4+
_ "github.com/project-flogo/contrib/trigger/rest"
5+
_ "github.com/project-flogo/rules/ruleaction"
6+
)

0 commit comments

Comments
 (0)