1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 01:24:05 +08:00
This commit is contained in:
harveyshao 2022-11-24 10:56:45 +08:00
parent 550d08092f
commit 33170bd6a9
4 changed files with 13 additions and 29 deletions

View File

@ -15,10 +15,10 @@ const EVENT = "event"
func init() {
Index.MergeCommands(ice.Commands{
EVENT: {Name: "event event id auto listen happen", Help: "事件流", Actions: ice.MergeActions(ice.Actions{
LISTEN: {Name: "listen event cmd", Hand: func(m *ice.Message, arg ...string) {
LISTEN: {Name: "listen event cmd", Help: "监听", Hand: func(m *ice.Message, arg ...string) {
mdb.ZoneInsert(m, m.OptionSimple(EVENT, ice.CMD))
}},
HAPPEN: {Name: "happen event arg", Hand: func(m *ice.Message, arg ...string) {
HAPPEN: {Name: "happen event", Help: "触发", Hand: func(m *ice.Message, arg ...string) {
mdb.ZoneSelect(m.Spawn(ice.OptionFields("")), m.Option(EVENT)).Tables(func(value ice.Maps) {
m.Cmdy(kit.Split(value[ice.CMD]), m.Option(EVENT), arg[2:], ice.OptionFields("")).Cost()
})

View File

@ -2,46 +2,27 @@ package gdb
import (
"os"
"strings"
"time"
ice "shylinux.com/x/icebergs"
kit "shylinux.com/x/toolkits"
)
type Frame struct {
s chan os.Signal
}
type Frame struct{ s chan os.Signal }
func (f *Frame) Spawn(m *ice.Message, c *ice.Context, arg ...string) ice.Server {
return &Frame{}
}
func (f *Frame) Begin(m *ice.Message, arg ...string) ice.Server {
list := []string{}
for k := range ice.Info.File {
if strings.HasPrefix(k, ice.Info.Make.Path+ice.PS) {
list = append(list, k)
}
}
for _, k := range list {
ice.Info.File["/require/"+strings.TrimPrefix(k, ice.Info.Make.Path+ice.PS)] = ice.Info.File[k]
delete(ice.Info.File, k)
}
f.s = make(chan os.Signal, 3)
return f
}
func (f *Frame) Start(m *ice.Message, arg ...string) bool {
t := kit.Duration(m.Conf(TIMER, kit.Keym(TICK)))
enable := m.Conf(TIMER, kit.Keym("enable")) == ice.TRUE
for {
select {
case <-time.Tick(t):
if enable {
m.Cmd(TIMER, HAPPEN)
}
case s, ok := <-f.s:
if !ok {
return true
@ -55,6 +36,9 @@ func (f *Frame) Close(m *ice.Message, arg ...string) bool {
close(f.s)
return true
}
func (f *Frame) Spawn(m *ice.Message, c *ice.Context, arg ...string) ice.Server {
return &Frame{}
}
const DEBUG = "debug"
const GDB = "gdb"
@ -64,4 +48,4 @@ var Index = &ice.Context{Name: GDB, Help: "事件模块", Commands: ice.Commands
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { ice.Info.Save(m, TIMER, ROUTINE) }},
}}
func init() { ice.Index.Register(Index, &Frame{}, SIGNAL, TIMER, EVENT, ROUTINE) }
func init() { ice.Index.Register(Index, &Frame{}, SIGNAL, EVENT, TIMER, ROUTINE) }

View File

@ -12,7 +12,7 @@ const ROUTINE = "routine"
func init() {
Index.MergeCommands(ice.Commands{
ROUTINE: {Name: "routine hash auto prunes", Help: "协程池", Actions: ice.MergeActions(ice.Actions{
mdb.CREATE: {Name: "create name", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
mdb.CREATE: {Name: "create name", Hand: func(m *ice.Message, arg ...string) {
m.Go(func() {
cb := m.OptionCB("")
h := mdb.HashCreate(m, m.OptionSimple(mdb.NAME), mdb.STATUS, START, ice.CMD, logs.FileLines(cb))

View File

@ -8,12 +8,12 @@ import (
kit "shylinux.com/x/toolkits"
)
func _timer_action(m *ice.Message, now string, arg ...string) {
func _timer_action(m *ice.Message, now time.Time, arg ...string) {
mdb.HashSelects(m).Tables(func(value ice.Maps) {
if value[mdb.COUNT] == "0" {
return
}
if value[mdb.TIME] > now {
if kit.Time(value[mdb.TIME]) > kit.Int64(now) {
return
}
m.Cmd(ROUTINE, mdb.CREATE, mdb.NAME, value[mdb.NAME], kit.Keycb(ROUTINE), value[ice.CMD])
@ -33,10 +33,10 @@ func init() {
TIMER: {Name: "timer hash auto create prunes", Help: "定时器", Actions: ice.MergeActions(ice.Actions{
mdb.CREATE: {Name: "create name=hi delay=10ms interval=10s count=3 cmd=runtime"},
mdb.PRUNES: {Hand: func(m *ice.Message, arg ...string) { mdb.HashPrunesValue(m, mdb.COUNT, "0") }},
HAPPEN: {Hand: func(m *ice.Message, arg ...string) { _timer_action(m, time.Now().Format(ice.MOD_TIME), arg...) }},
RESTART: {Name: "restart count=3", Hand: func(m *ice.Message, arg ...string) {
HAPPEN: {Hand: func(m *ice.Message, arg ...string) { _timer_action(m, time.Now(), arg...) }},
RESTART: {Name: "restart count=3", Help: "重启", Hand: func(m *ice.Message, arg ...string) {
mdb.HashModify(m, m.OptionSimple(mdb.HashShort(m)), arg)
}},
}, mdb.HashAction(mdb.FIELD, "time,hash,name,delay,interval,count,cmd", TICK, "10s"))},
}, mdb.HashAction(mdb.FIELD, "time,hash,name,delay,interval,count,cmd", TICK, "60s"))},
})
}