1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 09:34:05 +08:00
This commit is contained in:
shaoying 2022-11-24 02:04:42 +08:00
parent 8a9bb181a5
commit 550d08092f
7 changed files with 25 additions and 76 deletions

View File

@ -35,6 +35,6 @@ func init() {
} }
}) })
}}, }},
}, mdb.HashStatusAction(mdb.FIELD, "time,hash,name,status,cmd"))}, }, mdb.HashStatusAction(mdb.FIELD, "time,hash,status,name,cmd"))},
}) })
} }

View File

@ -20,19 +20,14 @@ func _signal_listen(m *ice.Message, s int, arg ...string) {
} }
} }
func _signal_action(m *ice.Message, arg ...string) { func _signal_action(m *ice.Message, arg ...string) {
mdb.HashSelect(m.Spawn(), arg...).Tables(func(value ice.Maps) { mdb.HashSelect(m.Spawn(), arg...).Tables(func(value ice.Maps) { m.Cmdy(kit.Split(value[ice.CMD])) })
m.Cmdy(kit.Split(value[ice.CMD]))
})
} }
func _signal_process(m *ice.Message, p string, s os.Signal) { func _signal_process(m *ice.Message, p string, s os.Signal) {
if p == "" { if p == "" {
b, _ := file.ReadFile(ice.Info.PidPath) b, _ := file.ReadFile(ice.Info.PidPath)
p = string(b) p = string(b)
} }
if p == "" { if p, e := os.FindProcess(kit.Int(kit.Select(kit.Format(os.Getpid()), p))); e == nil {
p = kit.Format(os.Getpid())
}
if p, e := os.FindProcess(kit.Int(p)); e == nil {
p.Signal(s) p.Signal(s)
} }
} }

View File

@ -8,12 +8,12 @@ import (
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
func _timer_action(m *ice.Message, now time.Time, arg ...string) { func _timer_action(m *ice.Message, now string, arg ...string) {
mdb.HashSelects(m).Tables(func(value ice.Maps) { mdb.HashSelects(m).Tables(func(value ice.Maps) {
if value[mdb.COUNT] == "0" { if value[mdb.COUNT] == "0" {
return return
} }
if kit.Time(value[mdb.TIME]) > kit.Int64(now) { if value[mdb.TIME] > now {
return return
} }
m.Cmd(ROUTINE, mdb.CREATE, mdb.NAME, value[mdb.NAME], kit.Keycb(ROUTINE), value[ice.CMD]) m.Cmd(ROUTINE, mdb.CREATE, mdb.NAME, value[mdb.NAME], kit.Keycb(ROUTINE), value[ice.CMD])
@ -31,14 +31,10 @@ const TIMER = "timer"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
TIMER: {Name: "timer hash auto create prunes", Help: "定时器", Actions: ice.MergeActions(ice.Actions{ 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", Help: "创建"}, mdb.CREATE: {Name: "create name=hi delay=10ms interval=10s count=3 cmd=runtime"},
mdb.PRUNES: {Name: "prunes", Help: "清理", Hand: func(m *ice.Message, arg ...string) { mdb.PRUNES: {Hand: func(m *ice.Message, arg ...string) { mdb.HashPrunesValue(m, mdb.COUNT, "0") }},
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: {Name: "happen", Help: "执行", 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.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, "10s"))},

View File

@ -1,4 +0,0 @@
chapter "lex"
field "分词" lex.split

View File

@ -17,7 +17,7 @@ func _split_tab(text string) (tab int) {
case ' ': case ' ':
tab++ tab++
default: default:
return break
} }
} }
return return
@ -38,27 +38,22 @@ func _split_list(m *ice.Message, file string, arg ...string) ice.Map {
list, line := kit.List(kit.Data(DEEP, -1)), "" list, line := kit.List(kit.Data(DEEP, -1)), ""
m.Cmd(nfs.CAT, file, func(text string) { m.Cmd(nfs.CAT, file, func(text string) {
if strings.TrimSpace(text) == "" { if strings.TrimSpace(text) == "" {
return // 空行 return
} }
if line += text; strings.Count(text, "`")%2 == 1 { if line += text; strings.Count(text, "`")%2 == 1 {
return // 多行 return
} }
if strings.HasPrefix(strings.TrimSpace(text), "# ") { if strings.HasPrefix(strings.TrimSpace(text), "# ") {
return // 注释 return
} }
stack, deep = _split_deep(stack, text) stack, deep = _split_deep(stack, text)
data := kit.Data(DEEP, deep) data := kit.Data(DEEP, deep)
// 回调函数
ls := kit.Split(text, m.Option(SPLIT_SPACE), m.Option(SPLIT_BLOCK), m.Option(SPLIT_QUOTE), m.Option(SPLIT_TRANS)) ls := kit.Split(text, m.Option(SPLIT_SPACE), m.Option(SPLIT_BLOCK), m.Option(SPLIT_QUOTE), m.Option(SPLIT_TRANS))
switch cb := m.OptionCB(SPLIT).(type) { switch cb := m.OptionCB(SPLIT).(type) {
case func(int, []string): case func(int, []string):
cb(deep, ls) cb(deep, ls)
case func(int, []string) []string: case func(int, []string) []string:
ls = cb(deep, ls) ls = cb(deep, ls)
case func(int, []string, ice.Map, ice.List):
case func(int, []string, ice.Map, ice.Map): case func(int, []string, ice.Map, ice.Map):
root, _ := kit.Value(list[0], "list.0").(ice.Map) root, _ := kit.Value(list[0], "list.0").(ice.Map)
cb(deep, ls, data, root) cb(deep, ls, data, root)
@ -66,28 +61,22 @@ func _split_list(m *ice.Message, file string, arg ...string) ice.Map {
ls = cb(deep, ls, data) ls = cb(deep, ls, data)
case func([]string, ice.Map) []string: case func([]string, ice.Map) []string:
ls = cb(ls, data) ls = cb(ls, data)
case func([]string):
cb(ls)
case func([]string) []string: case func([]string) []string:
ls = cb(ls) ls = cb(ls)
case func([]string):
cb(ls)
case nil: case nil:
default: default:
m.ErrorNotImplement(cb) m.ErrorNotImplement(cb)
} }
// 参数字段
for _, k := range arg { for _, k := range arg {
if kit.Value(data, kit.Keym(k), kit.Select("", ls, 0)); len(ls) > 0 { if kit.Value(data, kit.Keym(k), kit.Select("", ls, 0)); len(ls) > 0 {
ls = ls[1:] ls = ls[1:]
} }
} }
// 属性字段
for i := 0; i < len(ls)-1; i += 2 { for i := 0; i < len(ls)-1; i += 2 {
kit.Value(data, kit.Keym(ls[i]), ls[i+1]) kit.Value(data, kit.Keym(ls[i]), ls[i+1])
} }
// 查找节点
for i := len(list) - 1; i >= 0; i-- { for i := len(list) - 1; i >= 0; i-- {
if deep > kit.Int(kit.Value(list[i], kit.Keym(DEEP))) { if deep > kit.Int(kit.Value(list[i], kit.Keym(DEEP))) {
kit.Value(list[i], kit.Keys(mdb.LIST, "-2"), data) kit.Value(list[i], kit.Keys(mdb.LIST, "-2"), data)
@ -120,7 +109,6 @@ func init() {
}}, }},
}) })
} }
func Split(m *ice.Message, arg ...string) ice.Map { func Split(m *ice.Message, arg ...string) ice.Map {
return kit.Value(_split_list(m, arg[0], arg[1:]...), kit.Keys(mdb.LIST, "0")).(ice.Map) return kit.Value(_split_list(m, arg[0], arg[1:]...), kit.Keys(mdb.LIST, "0")).(ice.Map)
} }

View File

@ -20,14 +20,9 @@ type Log struct {
type Frame struct{ p chan *Log } type Frame struct{ p chan *Log }
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 { func (f *Frame) Begin(m *ice.Message, arg ...string) ice.Server {
f.p = make(chan *Log, ice.MOD_BUFS) f.p = make(chan *Log, ice.MOD_BUFS)
ice.Info.Log = func(msg *ice.Message, p, l, s string) { ice.Info.Log = func(m *ice.Message, p, l, s string) { f.p <- &Log{m: m, p: p, l: l, s: s} }
f.p <- &Log{m: msg, p: p, l: l, s: s}
}
return f return f
} }
func (f *Frame) Start(m *ice.Message, arg ...string) bool { func (f *Frame) Start(m *ice.Message, arg ...string) bool {
@ -37,18 +32,15 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
if !ok { if !ok {
return true return true
} }
for _, file := range []string{m.Conf(SHOW, kit.Keys(l.l, FILE)), BENCH} { for _, file := range []string{m.Conf(SHOW, kit.Keys(l.l, FILE)), BENCH} {
if file == "" { if file == "" {
continue continue
} }
view := m.Confm(VIEW, m.Conf(SHOW, kit.Keys(l.l, VIEW))) view := m.Confm(VIEW, m.Conf(SHOW, kit.Keys(l.l, VIEW)))
bio := m.Confv(FILE, kit.Keys(file, FILE)).(*bufio.Writer) bio := m.Confv(FILE, kit.Keys(file, FILE)).(*bufio.Writer)
if bio == nil { if bio == nil {
continue continue
} }
bio.WriteString(l.p) bio.WriteString(l.p)
bio.WriteString(ice.SP) bio.WriteString(ice.SP)
if ice.Info.Colors == true { if ice.Info.Colors == true {
@ -76,6 +68,7 @@ func (f *Frame) Close(m *ice.Message, arg ...string) bool {
close(f.p) close(f.p)
return true return true
} }
func (f *Frame) Spawn(m *ice.Message, c *ice.Context, arg ...string) ice.Server { return &Frame{} }
const ( const (
PREFIX = "prefix" PREFIX = "prefix"
@ -102,42 +95,24 @@ var Index = &ice.Context{Name: "log", Help: "日志模块", Configs: ice.Configs
FILE: {Name: FILE, Help: "日志文件", Value: kit.Dict( FILE: {Name: FILE, Help: "日志文件", Value: kit.Dict(
BENCH, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "bench.log"), mdb.LIST, []string{}), BENCH, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "bench.log"), mdb.LIST, []string{}),
WATCH, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "watch.log"), mdb.LIST, []string{ WATCH, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "watch.log"), mdb.LIST, []string{
mdb.CREATE, mdb.REMOVE, mdb.CREATE, mdb.REMOVE, mdb.INSERT, mdb.DELETE, mdb.MODIFY, mdb.SELECT, mdb.EXPORT, mdb.IMPORT,
mdb.INSERT, mdb.DELETE,
mdb.MODIFY, mdb.SELECT,
mdb.EXPORT, mdb.IMPORT,
}),
ERROR, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "error.log"), mdb.LIST, []string{
ice.LOG_WARN, ice.LOG_ERROR,
}),
TRACE, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "trace.log"), mdb.LIST, []string{
ice.LOG_DEBUG,
}), }),
ERROR, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "error.log"), mdb.LIST, []string{ice.LOG_WARN, ice.LOG_ERROR}),
TRACE, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "trace.log"), mdb.LIST, []string{ice.LOG_DEBUG}),
)}, )},
VIEW: {Name: VIEW, Help: "日志格式", Value: kit.Dict( VIEW: {Name: VIEW, Help: "日志格式", Value: kit.Dict(
GREEN, kit.Dict(PREFIX, "\033[32m", SUFFIX, "\033[0m", mdb.LIST, []string{ GREEN, kit.Dict(PREFIX, "\033[32m", SUFFIX, "\033[0m", mdb.LIST, []string{ice.CTX_START, ice.LOG_CMDS}),
ice.CTX_START, ice.LOG_CMDS, YELLOW, kit.Dict(PREFIX, "\033[33m", SUFFIX, "\033[0m", mdb.LIST, []string{ice.LOG_AUTH, ice.LOG_COST}),
}), RED, kit.Dict(PREFIX, "\033[31m", SUFFIX, "\033[0m", mdb.LIST, []string{ice.CTX_CLOSE, ice.LOG_WARN}),
YELLOW, kit.Dict(PREFIX, "\033[33m", SUFFIX, "\033[0m", mdb.LIST, []string{
ice.LOG_AUTH, ice.LOG_COST,
}),
RED, kit.Dict(PREFIX, "\033[31m", SUFFIX, "\033[0m", mdb.LIST, []string{
ice.CTX_CLOSE, ice.LOG_WARN,
}),
)}, )},
SHOW: {Name: SHOW, Help: "日志分流", Value: kit.Dict()}, SHOW: {Name: SHOW, Help: "日志分流", Value: kit.Dict()},
}, Commands: ice.Commands{ }, Commands: ice.Commands{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
m.Confm(VIEW, nil, func(key string, value ice.Map) { m.Confm(VIEW, nil, func(key string, value ice.Map) {
kit.Fetch(value[mdb.LIST], func(index int, k string) { kit.Fetch(value[mdb.LIST], func(index int, k string) { m.Conf(SHOW, kit.Keys(k, VIEW), key) })
m.Conf(SHOW, kit.Keys(k, VIEW), key)
})
}) })
m.Confm(FILE, nil, func(key string, value ice.Map) { m.Confm(FILE, nil, func(key string, value ice.Map) {
kit.Fetch(value[mdb.LIST], func(index int, k string) { kit.Fetch(value[mdb.LIST], func(index int, k string) { m.Conf(SHOW, kit.Keys(k, FILE), key) })
m.Conf(SHOW, kit.Keys(k, FILE), key)
})
// 日志文件
if f, p, e := logs.CreateFile(kit.Format(value[nfs.PATH])); e == nil { if f, p, e := logs.CreateFile(kit.Format(value[nfs.PATH])); e == nil {
m.Cap(ice.CTX_STREAM, path.Base(p)) m.Cap(ice.CTX_STREAM, path.Base(p))
value[FILE] = bufio.NewWriter(f) value[FILE] = bufio.NewWriter(f)

View File

@ -1 +0,0 @@
chapter "log"