mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt some
This commit is contained in:
parent
8a9bb181a5
commit
550d08092f
@ -35,6 +35,6 @@ func init() {
|
||||
}
|
||||
})
|
||||
}},
|
||||
}, mdb.HashStatusAction(mdb.FIELD, "time,hash,name,status,cmd"))},
|
||||
}, mdb.HashStatusAction(mdb.FIELD, "time,hash,status,name,cmd"))},
|
||||
})
|
||||
}
|
||||
|
@ -20,19 +20,14 @@ func _signal_listen(m *ice.Message, s int, arg ...string) {
|
||||
}
|
||||
}
|
||||
func _signal_action(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m.Spawn(), arg...).Tables(func(value ice.Maps) {
|
||||
m.Cmdy(kit.Split(value[ice.CMD]))
|
||||
})
|
||||
mdb.HashSelect(m.Spawn(), arg...).Tables(func(value ice.Maps) { m.Cmdy(kit.Split(value[ice.CMD])) })
|
||||
}
|
||||
func _signal_process(m *ice.Message, p string, s os.Signal) {
|
||||
if p == "" {
|
||||
b, _ := file.ReadFile(ice.Info.PidPath)
|
||||
p = string(b)
|
||||
}
|
||||
if p == "" {
|
||||
p = kit.Format(os.Getpid())
|
||||
}
|
||||
if p, e := os.FindProcess(kit.Int(p)); e == nil {
|
||||
if p, e := os.FindProcess(kit.Int(kit.Select(kit.Format(os.Getpid()), p))); e == nil {
|
||||
p.Signal(s)
|
||||
}
|
||||
}
|
||||
|
@ -8,12 +8,12 @@ import (
|
||||
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) {
|
||||
if value[mdb.COUNT] == "0" {
|
||||
return
|
||||
}
|
||||
if kit.Time(value[mdb.TIME]) > kit.Int64(now) {
|
||||
if value[mdb.TIME] > now {
|
||||
return
|
||||
}
|
||||
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() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
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.PRUNES: {Name: "prunes", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashPrunesValue(m, mdb.COUNT, "0")
|
||||
}},
|
||||
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.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) {
|
||||
mdb.HashModify(m, m.OptionSimple(mdb.HashShort(m)), arg)
|
||||
}},
|
||||
}, mdb.HashAction(mdb.FIELD, "time,hash,name,delay,interval,count,cmd", TICK, "10s"))},
|
||||
|
@ -1,4 +0,0 @@
|
||||
chapter "lex"
|
||||
|
||||
field "分词" lex.split
|
||||
|
@ -17,7 +17,7 @@ func _split_tab(text string) (tab int) {
|
||||
case ' ':
|
||||
tab++
|
||||
default:
|
||||
return
|
||||
break
|
||||
}
|
||||
}
|
||||
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)), ""
|
||||
m.Cmd(nfs.CAT, file, func(text string) {
|
||||
if strings.TrimSpace(text) == "" {
|
||||
return // 空行
|
||||
return
|
||||
}
|
||||
if line += text; strings.Count(text, "`")%2 == 1 {
|
||||
return // 多行
|
||||
return
|
||||
}
|
||||
if strings.HasPrefix(strings.TrimSpace(text), "# ") {
|
||||
return // 注释
|
||||
return
|
||||
}
|
||||
|
||||
stack, deep = _split_deep(stack, text)
|
||||
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))
|
||||
switch cb := m.OptionCB(SPLIT).(type) {
|
||||
case func(int, []string):
|
||||
cb(deep, ls)
|
||||
case func(int, []string) []string:
|
||||
ls = cb(deep, ls)
|
||||
case func(int, []string, ice.Map, ice.List):
|
||||
|
||||
case func(int, []string, ice.Map, ice.Map):
|
||||
root, _ := kit.Value(list[0], "list.0").(ice.Map)
|
||||
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)
|
||||
case func([]string, ice.Map) []string:
|
||||
ls = cb(ls, data)
|
||||
case func([]string):
|
||||
cb(ls)
|
||||
case func([]string) []string:
|
||||
ls = cb(ls)
|
||||
case func([]string):
|
||||
cb(ls)
|
||||
case nil:
|
||||
default:
|
||||
m.ErrorNotImplement(cb)
|
||||
}
|
||||
|
||||
// 参数字段
|
||||
for _, k := range arg {
|
||||
if kit.Value(data, kit.Keym(k), kit.Select("", ls, 0)); len(ls) > 0 {
|
||||
ls = ls[1:]
|
||||
}
|
||||
}
|
||||
|
||||
// 属性字段
|
||||
for i := 0; i < len(ls)-1; i += 2 {
|
||||
kit.Value(data, kit.Keym(ls[i]), ls[i+1])
|
||||
}
|
||||
|
||||
// 查找节点
|
||||
for i := len(list) - 1; i >= 0; i-- {
|
||||
if deep > kit.Int(kit.Value(list[i], kit.Keym(DEEP))) {
|
||||
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 {
|
||||
return kit.Value(_split_list(m, arg[0], arg[1:]...), kit.Keys(mdb.LIST, "0")).(ice.Map)
|
||||
}
|
||||
|
@ -20,14 +20,9 @@ type Log struct {
|
||||
|
||||
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 {
|
||||
f.p = make(chan *Log, ice.MOD_BUFS)
|
||||
ice.Info.Log = func(msg *ice.Message, p, l, s string) {
|
||||
f.p <- &Log{m: msg, p: p, l: l, s: s}
|
||||
}
|
||||
ice.Info.Log = func(m *ice.Message, p, l, s string) { f.p <- &Log{m: m, p: p, l: l, s: s} }
|
||||
return f
|
||||
}
|
||||
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 {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, file := range []string{m.Conf(SHOW, kit.Keys(l.l, FILE)), BENCH} {
|
||||
if file == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
view := m.Confm(VIEW, m.Conf(SHOW, kit.Keys(l.l, VIEW)))
|
||||
bio := m.Confv(FILE, kit.Keys(file, FILE)).(*bufio.Writer)
|
||||
if bio == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
bio.WriteString(l.p)
|
||||
bio.WriteString(ice.SP)
|
||||
if ice.Info.Colors == true {
|
||||
@ -76,6 +68,7 @@ func (f *Frame) Close(m *ice.Message, arg ...string) bool {
|
||||
close(f.p)
|
||||
return true
|
||||
}
|
||||
func (f *Frame) Spawn(m *ice.Message, c *ice.Context, arg ...string) ice.Server { return &Frame{} }
|
||||
|
||||
const (
|
||||
PREFIX = "prefix"
|
||||
@ -102,42 +95,24 @@ var Index = &ice.Context{Name: "log", Help: "日志模块", Configs: ice.Configs
|
||||
FILE: {Name: FILE, Help: "日志文件", Value: kit.Dict(
|
||||
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{
|
||||
mdb.CREATE, mdb.REMOVE,
|
||||
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,
|
||||
mdb.CREATE, mdb.REMOVE, 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}),
|
||||
)},
|
||||
VIEW: {Name: VIEW, Help: "日志格式", Value: kit.Dict(
|
||||
GREEN, kit.Dict(PREFIX, "\033[32m", SUFFIX, "\033[0m", mdb.LIST, []string{
|
||||
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,
|
||||
}),
|
||||
GREEN, kit.Dict(PREFIX, "\033[32m", SUFFIX, "\033[0m", mdb.LIST, []string{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}),
|
||||
)},
|
||||
SHOW: {Name: SHOW, Help: "日志分流", Value: kit.Dict()},
|
||||
}, Commands: ice.Commands{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Confm(VIEW, nil, func(key string, value ice.Map) {
|
||||
kit.Fetch(value[mdb.LIST], func(index int, k string) {
|
||||
m.Conf(SHOW, kit.Keys(k, VIEW), key)
|
||||
})
|
||||
kit.Fetch(value[mdb.LIST], func(index int, k string) { m.Conf(SHOW, kit.Keys(k, VIEW), key) })
|
||||
})
|
||||
m.Confm(FILE, nil, func(key string, value ice.Map) {
|
||||
kit.Fetch(value[mdb.LIST], func(index int, k string) {
|
||||
m.Conf(SHOW, kit.Keys(k, FILE), key)
|
||||
})
|
||||
// 日志文件
|
||||
kit.Fetch(value[mdb.LIST], func(index int, k string) { m.Conf(SHOW, kit.Keys(k, FILE), key) })
|
||||
if f, p, e := logs.CreateFile(kit.Format(value[nfs.PATH])); e == nil {
|
||||
m.Cap(ice.CTX_STREAM, path.Base(p))
|
||||
value[FILE] = bufio.NewWriter(f)
|
||||
|
@ -1 +0,0 @@
|
||||
chapter "log"
|
Loading…
x
Reference in New Issue
Block a user