1
0
forked from x/icebergs

add team.miss

This commit is contained in:
shaoying 2019-12-18 10:09:14 +08:00
parent 6a0c8e3fd7
commit a2dfaa3b19
9 changed files with 174 additions and 51 deletions

View File

@ -70,6 +70,13 @@ var Index = &Context{Name: "ice", Help: "冰山模块",
c.Close(m.Spawn(c), arg...)
os.Exit(kit.Int(kit.Select("0", arg, 0)))
}},
"restart": {Name: "restart", Help: "hello", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
switch kit.Select("0", arg, 0) {
case "0":
c.Close(m.Spawn(c), arg...)
os.Exit(kit.Int(kit.Select("0", arg, 0)))
}
}},
"_exit": {Name: "_init", Help: "hello", Hand: func(m *Message, c *Context, cmd string, arg ...string) {
}},
},

View File

@ -44,15 +44,30 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
}},
"runtime": {Name: "runtime", Help: "hello", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}},
"system": {Name: "system", Help: "hello", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
"system": {Name: "system", Help: "hello", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
cmd := exec.Command(arg[0], arg[1:]...)
cmd.Dir = m.Option("cmd_dir")
if m.Option("cmd_type") == "daemon" {
m.Gos(m, func(m *ice.Message) {
if e := cmd.Start(); e != nil {
m.Log("warn", "%v start %s", arg, e)
} else if e := cmd.Wait(); e != nil {
m.Log("warn", "%v wait %s", arg, e)
} else {
m.Log("info", "%v exit", arg)
}
})
return
}
out := bytes.NewBuffer(make([]byte, 0, 1024))
err := bytes.NewBuffer(make([]byte, 0, 1024))
sys := exec.Command(arg[0], arg[1:]...)
sys.Stdout = out
sys.Stderr = err
cmd.Stdout = out
cmd.Stderr = err
if e := sys.Run(); e != nil {
if e := cmd.Run(); e != nil {
m.Echo("error: ").Echo(kit.Select(e.Error(), err.String()))
return
}

View File

@ -3,6 +3,7 @@ package mdb
import (
"github.com/shylinux/icebergs"
"github.com/shylinux/toolkits"
"strings"
)
var Index = &ice.Context{Name: "mdb", Help: "数据模块",
@ -18,6 +19,24 @@ var Index = &ice.Context{Name: "mdb", Help: "数据模块",
kit.Value(data, arg[i], arg[i+1])
}
}},
"select": {Name: "select config table index offend limit match value", Help: "修改数据", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 3 {
meta := m.Confm(arg[0], arg[1]+".meta")
index := kit.Int(arg[2]) - kit.Int(meta["offset"]) - 1
data := m.Confm(arg[0], arg[1]+".list."+kit.Format(index))
m.Push(arg[2], data)
} else {
m.Option("cache.offend", kit.Select("0", arg, 3))
m.Option("cache.limit", kit.Select("10", arg, 4))
m.Option("cache.match", kit.Select("", arg, 5))
m.Option("cache.value", kit.Select("", arg, 6))
fields := strings.Split(arg[7], " ")
m.Grows(arg[0], arg[1], func(index int, value map[string]interface{}) {
m.Push("id", value, fields)
})
}
}},
},
}

View File

@ -1,11 +1,13 @@
package nfs
import (
"github.com/shylinux/icebergs"
"github.com/shylinux/toolkits"
"bufio"
"crypto/sha1"
"encoding/hex"
"fmt"
"github.com/shylinux/icebergs"
"io/ioutil"
"os"
"path"
@ -132,7 +134,7 @@ var Index = &ice.Context{Name: "nfs", Help: "文件模块",
"dir": {Name: "dir", Help: "目录", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
rg, _ := regexp.Compile(m.Option("dir_reg"))
dir(m, arg[0], arg[1], 0, false, "both", rg,
strings.Split("time size line path", " "), "2006-01-02 15:04:05")
strings.Split(kit.Select("time size line path", arg, 2), " "), "2006-01-02 15:04:05")
}},
},
}

View File

@ -44,7 +44,7 @@ func (web *WEB) Login(msg *ice.Message, w http.ResponseWriter, r *http.Request)
msg.Option("username", sub.Append("username")))
}
msg.Runs("_login", msg.Option("path"), kit.Simple(msg.Optionv("cmds"))...)
msg.Runs("_login", msg.Option("url"), kit.Simple(msg.Optionv("cmds"))...)
return true
}
func (web *WEB) HandleWSS(m *ice.Message, safe bool, c *websocket.Conn) {
@ -154,7 +154,7 @@ func (web *WEB) HandleCmd(m *ice.Message, key string, cmd *ice.Command) {
msg.Option("referer", r.Header.Get("Referer"))
msg.Option("accept", r.Header.Get("Accept"))
msg.Option("method", r.Method)
msg.Option("path", r.URL.Path)
msg.Option("url", r.URL.Path)
msg.Option("sessid", "")
// 请求环境
@ -200,8 +200,7 @@ func (web *WEB) HandleCmd(m *ice.Message, key string, cmd *ice.Command) {
if web.Login(msg, w, r) {
msg.Log("cmd", "%s %s", msg.Target().Name, key)
cmd.Hand(msg, msg.Target(), msg.Option("path"), kit.Simple(msg.Optionv("cmds"))...)
msg.Set("option")
cmd.Hand(msg, msg.Target(), msg.Option("url"), kit.Simple(msg.Optionv("cmds"))...)
w.Write([]byte(msg.Formats("meta")))
}
})
@ -335,10 +334,18 @@ var Index = &ice.Context{Name: "web", Help: "网页模块",
web := m.Target().Server().(*WEB)
m.Gos(m, func(m *ice.Message) {
web.HandleWSS(m, false, s)
m.Log("space", "close %v %v", h, kit.Formats(m.Confv("space")))
m.Confv("space", []string{"hash", h}, "")
})
}
}},
"space": &ice.Command{Name: "space", Help: "", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 {
m.Conf("space", "hash", func(key string, value map[string]interface{}) {
m.Push(key, value)
})
return
}
web := m.Target().Server().(*WEB)
switch arg[0] {
case "connect":
@ -381,7 +388,7 @@ var Index = &ice.Context{Name: "web", Help: "网页模块",
web := m.Target().Server().(*WEB)
web.send[id] = m
m.Add("detail", arg[1:]...)
m.Set("detail", arg[1:]...)
socket.WriteMessage(MSG_MAPS, []byte(m.Format("meta")))
m.Call(true, func(msg *ice.Message) *ice.Message {
m.Copy(msg)

View File

@ -5,12 +5,63 @@ import (
_ "github.com/shylinux/icebergs/base"
"github.com/shylinux/icebergs/base/web"
"github.com/shylinux/toolkits"
"os"
"path"
"strings"
)
var Index = &ice.Context{Name: "team", Help: "团队模块",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{},
Configs: map[string]*ice.Config{
"miss": {Value: map[string]interface{}{
"meta": map[string]interface{}{
"path": "usr/local/work",
"cmd": []interface{}{"cli.system", "sh", "ice.sh", "start", "web.space", "connect"},
},
"list": map[string]interface{}{},
"hash": map[string]interface{}{},
}},
},
Commands: map[string]*ice.Command{
"miss": {Name: "miss", Help: "任务", Meta: map[string]interface{}{
"exports": []interface{}{"you", "name"},
"detail": []interface{}{"启动", "停止"},
}, List: []interface{}{
map[string]interface{}{"type": "text", "value": "", "name": "name"},
map[string]interface{}{"type": "text", "value": "", "name": "type"},
map[string]interface{}{"type": "button", "value": "创建"},
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
if len(arg) > 1 {
switch arg[1] {
case "启动":
case "停止":
m.Cmd("web.space", arg[0], "exit", "1")
return
}
}
if len(arg) > 0 {
if !strings.Contains(arg[0], "-") {
arg[0] = m.Time("20060102-") + arg[0]
}
p := path.Join(m.Conf("miss", "meta.path"), arg[0])
if _, e := os.Stat(p); e != nil {
os.MkdirAll(p, 0777)
}
if !m.Confs("web.space", "hash."+arg[0]) {
m.Option("cmd_dir", p)
m.Option("cmd_type", "daemon")
m.Cmd(m.Confv("miss", "meta.cmd"))
}
}
m.Cmdy("nfs.dir", "", m.Conf("miss", "meta.path"), "time name")
m.Table(func(index int, value map[string]string, head []string) {
m.Push("status", kit.Select("stop", "start", m.Confs("web.space", "hash."+value["name"])))
})
}},
"task": {Name: "task", Help: "任务", List: []interface{}{
map[string]interface{}{"type": "select", "value": "create", "values": "create action cancel finish"},
map[string]interface{}{"type": "text", "value": "", "name": "name"},
@ -19,16 +70,14 @@ var Index = &ice.Context{Name: "team", Help: "团队模块",
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
switch arg[0] {
case "create":
m.Log("waht", "%v", m.Conf("web.chat.group", "hash."+m.Option("sess.river")+".task"))
meta := m.Grow("web.chat.group", []string{"hash", m.Option("sess.river"), "task"}, map[string]interface{}{
"name": arg[1],
"text": kit.Select("", arg, 2),
"status": "prepare",
"status": "准备",
"begin_time": m.Time(),
"close_time": m.Time("3h"),
})
m.Log("info", "create task %v", kit.Format(meta))
m.Log("waht", "%v %v", meta["count"], m.Conf("web.chat.group", "hash."+m.Option("sess.river")+".task"))
m.Echo("%v", meta["count"])
case "action":
case "cancel":
@ -42,42 +91,37 @@ var Index = &ice.Context{Name: "team", Help: "团队模块",
map[string]interface{}{"type": "text", "value": "", "name": "match"},
map[string]interface{}{"type": "text", "value": "", "name": "value"},
map[string]interface{}{"type": "button", "value": "查看"},
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
prefix := []string{"mdb.update", "web.chat.group", "hash." + m.Option("sess.river") + ".task", arg[0]}
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
msg := m.Cmd("mdb.select", "web.chat.group", "hash."+m.Option("sess.river")+".task", arg[0])
switch arg[1] {
case "准备":
m.Cmd(prefix, "status", arg[1],
"extra.list.-2.time", m.Time(),
"extra.list.-3.status", arg[1],
)
case "准备", "开始", "取消", "完成":
msg.Log("what", "%v %v", msg.Append("status"), arg[1])
if msg.Append("status") == arg[1] {
arg = arg[4:]
case "开始":
m.Cmd(prefix, "status", arg[1], "begin_time", m.Time(),
"extra.list.-2.time", m.Time(),
"extra.list.-3.status", arg[1],
)
arg = arg[4:]
case "取消":
m.Cmd(prefix, "status", arg[1], "close_time", m.Time(),
"extra.list.-2.time", m.Time(),
"extra.list.-3.status", arg[1],
)
arg = arg[4:]
case "完成":
m.Cmd(prefix, "status", arg[1], "close_time", m.Time(),
"extra.list.-2.time", m.Time(),
"extra.list.-3.status", arg[1],
)
break
}
prefix := []string{"mdb.update", "web.chat.group", "hash." + m.Option("sess.river") + ".task", arg[0], "status", arg[1]}
status := map[string][]string{
"准备->开始": []string{"begin_time", m.Time(), "close_time", m.Time("3h")},
"准备->取消": []string{"begin_time", m.Time(), "close_time", m.Time()},
"准备->完成": []string{"begin_time", m.Time(), "close_time", m.Time()},
"开始->准备": []string{"begin_time", m.Time(), "close_time", m.Time("3h")},
"开始->取消": []string{"close_time", m.Time()},
"开始->完成": []string{"close_time", m.Time()},
}[msg.Append("status")+"->"+arg[1]]
suffix := []string{"extra.list.-2.time", m.Time(), "extra.list.-3.status", arg[1]}
if len(status) > 0 {
m.Cmd(prefix, status, suffix)
}
arg = arg[4:]
}
m.Option("cache.offend", kit.Select("0", arg, 0))
m.Option("cache.limit", kit.Select("10", arg, 1))
m.Option("cache.match", kit.Select("", arg, 2))
m.Option("cache.value", kit.Select("", arg, 3))
m.Grows("web.chat.group", []string{"hash", m.Option("sess.river"), "task"}, func(index int, value map[string]interface{}) {
m.Push("id", value, []string{"id", "status", "begin_time", "close_time", "name", "text"})
})
m.Cmdy("mdb.select", "web.chat.group", "hash."+m.Option("sess.river")+".task", "0",
kit.Select("0", arg, 0), kit.Select("10", arg, 1), kit.Select("", arg, 2), kit.Select("", arg, 3),
kit.Select("id status begin_time close_time name text", arg, 4))
}},
},
}

View File

@ -1,5 +1,6 @@
#! /bin/sh
export ice_app=${ice_app:="ice.app"}
export ice_err=${ice_err:="boot.log"}
export ice_serve=${ice_serve:="web.serve"}
@ -37,7 +38,7 @@ build() {
start() {
[ -d usr/volcanos ] || git clone https://github.com/shylinux/volcanos usr/volcanos
while true; do
date && bin/shy 2>$ice_err && log "\n\nrestarting..." && sleep 1 || break
date && $ice_app $* 2>$ice_err && log "\n\nrestarting..." && sleep 1 || break
done
}
log() { echo -e $*; }

View File

@ -14,4 +14,7 @@ context
cli.go
ctx.go
toolkits
type.go
core.go
misc.go
`}}

25
type.go
View File

@ -315,8 +315,12 @@ func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Messa
sort.Strings(list)
}
for _, k := range list {
if k == "key" {
m.Add("append", k, k)
} else {
m.Add("append", k, kit.Format(value[k]))
}
}
return m
}
return m.Add("append", key, kit.Format(value))
@ -325,6 +329,27 @@ func (m *Message) Echo(str string, arg ...interface{}) *Message {
m.meta["result"] = append(m.meta["result"], fmt.Sprintf(str, arg...))
return m
}
func (m *Message) Table(cbs ...interface{}) *Message {
if len(cbs) > 0 {
switch cb := cbs[0].(type) {
case func(int, map[string]string, []string):
nrow := 0
for _, k := range m.meta["append"] {
if len(m.meta[k]) > nrow {
nrow = len(m.meta[k])
}
}
for i := 0; i < nrow; i++ {
line := map[string]string{}
for _, k := range m.meta["append"] {
line[k] = kit.Select("", m.meta[k], i)
}
cb(i, line, m.meta["append"])
}
}
}
return m
}
func (m *Message) Option(key string, arg ...interface{}) string {
return kit.Select("", kit.Simple(m.Optionv(key, arg...)), 0)
}