Skip to content

Commit

Permalink
examples updated
Browse files Browse the repository at this point in the history
  • Loading branch information
nareshkumarthota committed Apr 27, 2020
1 parent 7a8da56 commit 50eb9ba
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 66 deletions.
6 changes: 6 additions & 0 deletions examples/flogo/creditcard/imports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main

import (
_ "github.com/project-flogo/rules/ruleaction"
_ "github.com/project-flogo/contrib/trigger/rest"
)
34 changes: 20 additions & 14 deletions examples/flogo/creditcard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,43 @@ import (

_ "github.com/project-flogo/core/data/expression/script"
"github.com/project-flogo/core/engine"
"github.com/project-flogo/core/support/log"

_ "github.com/project-flogo/contrib/trigger/rest"
_ "github.com/project-flogo/rules/ruleaction"
)

var (
cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file")
memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file")
cfgJson string
cfgEngine string
cfgCompressed bool
)

func main() {

cpuProfiling := false

flag.Parse()
if *cpuProfile != "" {
f, err := os.Create(*cpuProfile)
if err != nil {
fmt.Println(fmt.Sprintf("Failed to create CPU profiling file due to error - %s", err.Error()))
fmt.Fprintf(os.Stderr, "Failed to create CPU profiling file: %v\n", err)
os.Exit(1)
}
if err = pprof.StartCPUProfile(f); err != nil {
fmt.Fprintf(os.Stderr, "Failed to start CPU profiling: %v\n", err)
os.Exit(1)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
cpuProfiling = true
}

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

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

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

runtime.GC() // get up-to-date statistics
if err := pprof.WriteHeapProfile(f); err != nil {
fmt.Println(fmt.Sprintf("Failed to write memory profiling data to file due to error - %s", err.Error()))
fmt.Fprintf(os.Stderr, "Failed to write memory profiling data: %v", err)
os.Exit(1)
}
f.Close()
_ = f.Close()
}

if cpuProfiling {
pprof.StopCPUProfile()
}

os.Exit(code)
}
}
6 changes: 6 additions & 0 deletions examples/flogo/simple-kafka/imports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main

import (
_ "github.com/project-flogo/contrib/trigger/kafka"
_ "github.com/project-flogo/rules/ruleaction"
)
38 changes: 22 additions & 16 deletions examples/flogo/simple-kafka/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,43 @@ import (

_ "github.com/project-flogo/core/data/expression/script"
"github.com/project-flogo/core/engine"
"github.com/project-flogo/core/support/log"

_ "github.com/project-flogo/contrib/trigger/kafka"
_ "github.com/project-flogo/rules/ruleaction"
)

var (
cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file")
memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file")
cfgJSON string
cfgJson string
cfgEngine string
cfgCompressed bool
)

func main() {

cpuProfiling := false

flag.Parse()
if *cpuProfile != "" {
f, err := os.Create(*cpuProfile)
if err != nil {
fmt.Println(fmt.Sprintf("Failed to create CPU profiling file due to error - %s", err.Error()))
fmt.Fprintf(os.Stderr, "Failed to create CPU profiling file: %v\n", err)
os.Exit(1)
}
if err = pprof.StartCPUProfile(f); err != nil {
fmt.Fprintf(os.Stderr, "Failed to start CPU profiling: %v\n", err)
os.Exit(1)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
cpuProfiling = true
}

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

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

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

runtime.GC() // get up-to-date statistics
if err := pprof.WriteHeapProfile(f); err != nil {
fmt.Println(fmt.Sprintf("Failed to write memory profiling data to file due to error - %s", err.Error()))
fmt.Fprintf(os.Stderr, "Failed to write memory profiling data: %v", err)
os.Exit(1)
}
f.Close()
_ = f.Close()
}

if cpuProfiling {
pprof.StopCPUProfile()
}

os.Exit(code)
}
}
6 changes: 6 additions & 0 deletions examples/flogo/simple/imports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main

import (
_ "github.com/project-flogo/contrib/trigger/rest"
_ "github.com/project-flogo/rules/ruleaction"
)
41 changes: 23 additions & 18 deletions examples/flogo/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,43 @@ import (

_ "github.com/project-flogo/core/data/expression/script"
"github.com/project-flogo/core/engine"
"github.com/project-flogo/core/support/log"

_ "github.com/project-flogo/contrib/trigger/rest"
_ "github.com/project-flogo/rules/ruleaction"

)

var (
cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file")
memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file")
cfgJson string
cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file")
memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file")
cfgJson string
cfgEngine string
cfgCompressed bool
)

func main() {

cpuProfiling := false

flag.Parse()
if *cpuProfile != "" {
f, err := os.Create(*cpuProfile)
if err != nil {
fmt.Println(fmt.Sprintf("Failed to create CPU profiling file due to error - %s", err.Error()))
fmt.Fprintf(os.Stderr, "Failed to create CPU profiling file: %v\n", err)
os.Exit(1)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
if err = pprof.StartCPUProfile(f); err != nil {
fmt.Fprintf(os.Stderr, "Failed to start CPU profiling: %v\n", err)
os.Exit(1)
}
cpuProfiling = true
}

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

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

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

runtime.GC() // get up-to-date statistics
if err := pprof.WriteHeapProfile(f); err != nil {
fmt.Println(fmt.Sprintf("Failed to write memory profiling data to file due to error - %s", err.Error()))
fmt.Fprintf(os.Stderr, "Failed to write memory profiling data: %v", err)
os.Exit(1)
}
f.Close()
_ = f.Close()
}

if cpuProfiling {
pprof.StopCPUProfile()
}

os.Exit(code)
}
}
6 changes: 6 additions & 0 deletions examples/flogo/trackntrace/imports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main

import (
_ "github.com/project-flogo/contrib/trigger/rest"
_ "github.com/project-flogo/rules/ruleaction"
)
41 changes: 23 additions & 18 deletions examples/flogo/trackntrace/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,43 @@ import (

_ "github.com/project-flogo/core/data/expression/script"
"github.com/project-flogo/core/engine"
"github.com/project-flogo/core/support/log"

_ "github.com/project-flogo/contrib/trigger/rest"
_ "github.com/project-flogo/rules/ruleaction"

)

var (
cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file")
memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file")
cfgJson string
cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file")
memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file")
cfgJson string
cfgEngine string
cfgCompressed bool
)

func main() {

cpuProfiling := false

flag.Parse()
if *cpuProfile != "" {
f, err := os.Create(*cpuProfile)
if err != nil {
fmt.Println(fmt.Sprintf("Failed to create CPU profiling file due to error - %s", err.Error()))
fmt.Fprintf(os.Stderr, "Failed to create CPU profiling file: %v\n", err)
os.Exit(1)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
if err = pprof.StartCPUProfile(f); err != nil {
fmt.Fprintf(os.Stderr, "Failed to start CPU profiling: %v\n", err)
os.Exit(1)
}
cpuProfiling = true
}

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

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

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

runtime.GC() // get up-to-date statistics
if err := pprof.WriteHeapProfile(f); err != nil {
fmt.Println(fmt.Sprintf("Failed to write memory profiling data to file due to error - %s", err.Error()))
fmt.Fprintf(os.Stderr, "Failed to write memory profiling data: %v", err)
os.Exit(1)
}
f.Close()
_ = f.Close()
}

if cpuProfiling {
pprof.StopCPUProfile()
}

os.Exit(code)
}
}

0 comments on commit 50eb9ba

Please sign in to comment.