Skip to content

Commit

Permalink
feat: update behavior3
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangliang committed Feb 21, 2022
1 parent 7bf7504 commit e5592c5
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 37 deletions.
103 changes: 74 additions & 29 deletions examples/hello/hello.b3
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"data": {
"version": "0.3.0",
"scope": "project",
"selectedTree": "9b312d53-62e7-40c4-800b-a5722e88ed8b",
"selectedTree": "5daf5bdf-0bea-45b6-bcae-0a5fd0e66181",
"trees": [
{
"version": "0.3.0",
Expand Down Expand Up @@ -132,6 +132,24 @@
"y": -108
}
},
"4624bd47-4cdd-4d95-8cbe-bf3217308b7f": {
"id": "4624bd47-4cdd-4d95-8cbe-bf3217308b7f",
"name": "Sequence",
"category": "composite",
"title": "Sequence",
"description": "",
"properties": {},
"display": {
"x": -24,
"y": 24
},
"children": [
"87d3e037-156b-475e-b935-287a732981ae",
"ec58b1b2-fd58-4064-8382-96ddda694b45",
"3752a7e4-8211-4d53-8a4e-51721b9af7cb",
"67fcb644-e242-4e93-90b4-a5758fe25808"
]
},
"ec58b1b2-fd58-4064-8382-96ddda694b45": {
"id": "ec58b1b2-fd58-4064-8382-96ddda694b45",
"name": "helloC",
Expand All @@ -156,24 +174,6 @@
"y": 48
}
},
"4624bd47-4cdd-4d95-8cbe-bf3217308b7f": {
"id": "4624bd47-4cdd-4d95-8cbe-bf3217308b7f",
"name": "Sequence",
"category": "composite",
"title": "Sequence",
"description": "",
"properties": {},
"display": {
"x": -24,
"y": 24
},
"children": [
"87d3e037-156b-475e-b935-287a732981ae",
"ec58b1b2-fd58-4064-8382-96ddda694b45",
"3752a7e4-8211-4d53-8a4e-51721b9af7cb",
"67fcb644-e242-4e93-90b4-a5758fe25808"
]
},
"67fcb644-e242-4e93-90b4-a5758fe25808": {
"id": "67fcb644-e242-4e93-90b4-a5758fe25808",
"name": "Wait",
Expand Down Expand Up @@ -306,32 +306,77 @@
"y": -72
},
"children": [
"65e8cffc-e20a-46b8-86fa-7d1e39203942",
"2e4c4cd5-5096-42ba-97da-db592db381e0"
"2bc194c4-b059-4690-a4c7-86eff85dad6a"
]
},
"65e8cffc-e20a-46b8-86fa-7d1e39203942": {
"id": "65e8cffc-e20a-46b8-86fa-7d1e39203942",
"2bc194c4-b059-4690-a4c7-86eff85dad6a": {
"id": "2bc194c4-b059-4690-a4c7-86eff85dad6a",
"name": "Parallel",
"category": "composite",
"title": "Parallel",
"description": "",
"properties": {},
"display": {
"x": -144,
"y": -72
},
"children": [
"4a9cd44e-05de-4719-82a8-3508a25184b6",
"8e3369d7-1349-4428-8193-e24a34108db7"
]
},
"2e75e63c-251e-4d59-840c-e5ec60325be4": {
"id": "2e75e63c-251e-4d59-840c-e5ec60325be4",
"name": "helloB",
"category": "action",
"title": "helloB",
"description": "",
"properties": {},
"display": {
"x": -108,
"y": -144
"x": 468,
"y": -192
}
},
"2e4c4cd5-5096-42ba-97da-db592db381e0": {
"id": "2e4c4cd5-5096-42ba-97da-db592db381e0",
"4a9cd44e-05de-4719-82a8-3508a25184b6": {
"id": "4a9cd44e-05de-4719-82a8-3508a25184b6",
"name": "MemSequence",
"category": "composite",
"title": "MemSequence",
"description": "",
"properties": {},
"display": {
"x": 0,
"y": -192
},
"children": [
"66467819-ee0e-4fca-80db-6205cac0842c"
]
},
"66467819-ee0e-4fca-80db-6205cac0842c": {
"id": "66467819-ee0e-4fca-80db-6205cac0842c",
"name": "Repeater",
"category": "decorator",
"title": "Repeat <maxLoop>x",
"description": "",
"properties": {
"maxLoop": 10
},
"display": {
"x": 204,
"y": -192
},
"child": "2e75e63c-251e-4d59-840c-e5ec60325be4"
},
"8e3369d7-1349-4428-8193-e24a34108db7": {
"id": "8e3369d7-1349-4428-8193-e24a34108db7",
"name": "helloD",
"category": "action",
"title": "helloD",
"description": "",
"properties": {},
"display": {
"x": -108,
"y": 0
"x": 60,
"y": 48
}
}
},
Expand Down
11 changes: 7 additions & 4 deletions examples/hello/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
_ "embed"
"encoding/json"
"fmt"
"time"

"github.com/LilithGames/agent-go/pkg/agent"
"github.com/LilithGames/agent-go/tools/log"
"github.com/hasura/go-graphql-client"
"github.com/magicsea/behavior3go"
"github.com/magicsea/behavior3go/core"
"github.com/rs/xid"
"math/rand"
"time"
)

//go:embed task.yaml
Expand Down Expand Up @@ -64,6 +64,8 @@ func HelloA(tick agent.Ticker) (behavior3go.Status, error) {
}

func HelloB(tick agent.Ticker) (behavior3go.Status, error) {
time.Sleep(time.Second)
fmt.Println("main process...")
return behavior3go.SUCCESS, nil
}

Expand All @@ -84,8 +86,9 @@ func HelloC(tick agent.Ticker) (behavior3go.Status, error) {
}

func HelloD(tick agent.Ticker) (behavior3go.Status, error) {
time.Sleep(time.Millisecond * time.Duration(rand.Intn(10)))
return behavior3go.SUCCESS, nil
time.Sleep(time.Second)
fmt.Println("heartbeat...")
return behavior3go.RUNNING, nil
}

func HelloE(tick agent.Ticker) (behavior3go.Status, error) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ require (

replace (
github.com/hasura/go-graphql-client => github.com/LilithGames/go-graphql-client v1.0.4
github.com/magicsea/behavior3go => github.com/LilithGames/behavior3go v1.0.2
github.com/magicsea/behavior3go => github.com/LilithGames/behavior3go v1.0.3
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/AsynkronIT/protoactor-go v0.0.0-20211018041209-5fdd594ca443 h1:t3w3eo
github.com/AsynkronIT/protoactor-go v0.0.0-20211018041209-5fdd594ca443/go.mod h1:/hOxjCMSgM8fEDuQeUrNvz+WWRcMosGmMJb5dm79vHU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/LilithGames/behavior3go v1.0.2 h1:A53hDYXen/ocoXR161Xbq9tocQ32vjjztBk0IiJbwEE=
github.com/LilithGames/behavior3go v1.0.2/go.mod h1:bqTRjmUHkU8u5UmTRzPJWkZeGRj6AJaYBlXksX5lpBc=
github.com/LilithGames/behavior3go v1.0.3 h1:uyCJvrViEwlJQQy+9KMk43p43cbRfxA1y0uuo+zeg+4=
github.com/LilithGames/behavior3go v1.0.3/go.mod h1:bqTRjmUHkU8u5UmTRzPJWkZeGRj6AJaYBlXksX5lpBc=
github.com/LilithGames/go-graphql-client v1.0.4 h1:AUwNRlIBIdn4DW1dvqJgkM+mgkB1Vba6u1/TTXAW08c=
github.com/LilithGames/go-graphql-client v1.0.4/go.mod h1:78viDEV6ew82QUorDE/bxDsdtG2QM4uqdsn5L3ROcww=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
Expand Down
4 changes: 3 additions & 1 deletion pkg/agent/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ func (n *Action) recoverPanic(name string, tick *Tick) {
outcome.Class = transfer.CLASS_HANDLER
outcome.Err = fmt.Sprintf("receive panic: %v", r)
tick.actorCtx().Send(tick.stat(), &outcome)
n.addMetric(tick.GetTree().GetTitile(), name, behavior3go.ERROR)
task := tick.GetTree().GetTitile()
n.addMetric(task, name, behavior3go.ERROR)
log.Error("handler panic", zap.String("handler", name), zap.String("task", task), zap.Error(fmt.Errorf("panic: %v", r)))
}
}

Expand Down

0 comments on commit e5592c5

Please sign in to comment.