-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : Introducing cluster deployment mode
- Loading branch information
taotao
committed
Jan 16, 2024
1 parent
ee9765e
commit e1ed5c3
Showing
35 changed files
with
1,374 additions
and
269 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
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
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
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
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
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
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
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
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
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,64 @@ | ||
package behavior | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
|
||
"github.com/pojol/gobot/database" | ||
) | ||
|
||
type behaviorPool struct { | ||
sync.Mutex | ||
saved map[string][]*Tree | ||
} | ||
|
||
func _new_tree(name string) (*Tree, error) { | ||
|
||
dat, err := database.GetBehavior().Find(name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
tree, err := Load(dat.File) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return tree, nil | ||
} | ||
|
||
func Get(name string) *Tree { | ||
bp.Lock() | ||
defer bp.Unlock() | ||
|
||
lst := bp.saved[name] | ||
|
||
n := len(lst) | ||
if n == 0 { | ||
tree, err := _new_tree(name) | ||
if err != nil { | ||
fmt.Println("behaviorPool.Get", err.Error()) | ||
return nil | ||
} | ||
|
||
return tree | ||
} | ||
|
||
x := lst[n-1] | ||
bp.saved[name] = bp.saved[name][0 : n-1] | ||
|
||
return x | ||
} | ||
|
||
func Put(name string, tree *Tree) { | ||
bp.Lock() | ||
defer bp.Unlock() | ||
|
||
tree.Reset() | ||
bp.saved[name] = append(bp.saved[name], tree) | ||
|
||
} | ||
|
||
var bp = &behaviorPool{ | ||
saved: make(map[string][]*Tree), | ||
} |
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
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
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
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
Oops, something went wrong.