From 80b9412629b0a6cbf0d010f4a561714fc36cb466 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 16 Aug 2023 11:42:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +- 1.json | 3 +- command.go | 7 +- datajson_test.go | 231 +++++++++++++++++++++++----------------------- etc/etc_a.yaml | 4 +- etc/etc_b.yaml | 4 +- etc/etc_c.yaml | 4 +- main.go | 2 +- main/main.go | 27 ++++++ main/start.sh | 15 +++ main/stop.sh | 15 +++ websocket.go | 10 +- websocket_test.go | 11 +-- 13 files changed, 196 insertions(+), 141 deletions(-) create mode 100644 main/main.go create mode 100755 main/start.sh create mode 100755 main/stop.sh diff --git a/.gitignore b/.gitignore index 7a74866..0cd1001 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ fusenrender example-data -*.json \ No newline at end of file +*.json + +*.log \ No newline at end of file diff --git a/1.json b/1.json index a6c45bc..85664dd 100644 --- a/1.json +++ b/1.json @@ -1,7 +1,8 @@ { "id": "c82cff55f2cc5cee3f71300fd8c5d953", "order_id": 0, - "user_id": null, + "user_id": 0, + "guest_id": 0, "sku_ids": [ 16, 19, diff --git a/command.go b/command.go index e8f6c7d..2b80b96 100644 --- a/command.go +++ b/command.go @@ -36,16 +36,15 @@ type Command struct { // QueueItem表示队列中的一个项 type QueueItem struct { - // 队列组名 - Group string `json:"group"` // 组名 + Group string `json:"group"` // 队列组名 - Wid uint64 // 唯一标识id + Source string `json:"source"` // 标记业务来源 // 优先级 Priority uint32 `json:"priority"` // 处理的优先级 // 创建时间 CreateAt time.Time `json:"create_at"` // 创建时间 统一utc // 要排队的数据 - Data any `json:"data"` // 操作的数据结构 + Data any `json:"render_data"` // 操作的数据结构 } func (item *QueueItem) Encode() ([]byte, error) { diff --git a/datajson_test.go b/datajson_test.go index 2c0d2e1..b249de1 100644 --- a/datajson_test.go +++ b/datajson_test.go @@ -1,119 +1,120 @@ package fusenrender_test var sendjson = `{ - "id": "c82cff55f2cc5cee3f71300fd8c5d953", - "order_id": 0, - "user_id": null, - "sku_ids": [ - 16, - 19, - 25, - 13 - ], - "tids": [ - "FSN-PPBX-1", - "FSN-PLUP-4", - "FSN-PPCCT-2" - ], - "data": [ - { - "light": 2, - "refletion": -1, - "scale": "22", - "sku_id": 25, - "tid": "FSN-PPBX-1", - "rotation": "5.4,-41,-4.7", - "filePath": "", - "data": [ - { - "name": "model", - "data": "0,https:\/\/fusenh5.kayue.cn:8011\/storage\/test\/final_JntYgQf85p_temp.png,FSN-PPBX-1_MaskMap,FSN-PPBX-1_Normal,FSN-PPBX-1_BaseMap", - "type": "other", - "layer": "0", - "is_update": 1, - "mode": "Opaque" - }, - { - "name": "shadow", - "data": "0,FSN-PPBX-1,0,0,0", - "type": "other", - "layer": "0", - "is_update": 0, - "mode": "Fade" - } - ] - }, - { - "light": 8, - "refletion": -1, - "scale": "12.5", - "sku_id": 19, - "tid": "FSN-PPCCT-2", - "rotation": "-2,25.5,-1", - "filePath": "", - "data": [ - { - "name": "model", - "data": "0,https:\/\/fusenh5.kayue.cn:8011\/storage\/test\/final_xNf7MC38vc_temp.png,FSN-PPCCT-2_MaskMap,FSN-PPCCT-2_Normal,FSN-PPCCT-2_BaseMap", - "type": "other", - "layer": "0", - "is_update": 1, - "mode": "Opaque" - }, - { - "name": "shadow", - "data": "0,FSN-PPCCT-2,0,0,0", - "type": "other", - "layer": "0", - "is_update": 0, - "mode": "Fade" - }, - { - "name": "model_P", - "data": "0,FSN-PPCCT-2-P,FSN-PPCCT-2-P_MaskMap,FSN-PPCCT-2-P_Normal,FSN-PPCCT-2-P_BaseMap", - "type": "other", - "layer": "0", - "is_update": 0, - "mode": "Fade" - } - ] - }, - { - "light": 7, - "refletion": 7, - "scale": "14", - "sku_id": 16, - "tid": "FSN-PLUP-4", - "rotation": "0,0,0", - "filePath": "", - "data": [ - { - "name": "model", - "data": "0,https:\/\/fusenh5.kayue.cn:8011\/storage\/test\/final_ImDCgYaw9o_temp.png,FSN-PLUP-4_MaskMap,FSN-PLUP-4_Normal,FSN-PLUP-4_BaseMap", - "type": "other", - "layer": "0", - "is_update": 1, - "mode": "Opaque" - }, - { - "name": "shadow", - "data": "0,FSN-PLUP-4,0,0,0", - "type": "other", - "layer": "0", - "is_update": 0, - "mode": "Fade" - }, - { - "name": "model_P", - "data": "0,FSN-PLUP-4-P,FSN-PLUP-4-P_MaskMap,FSN-PLUP-4-P_Normal,FSN-PLUP-4-P_BaseMap", - "type": "other", - "layer": "0", - "is_update": 0, - "mode": "Opaque" - } - ] - } - ], - "is_thousand_face": 0, - "folder": "" + "id": "c82cff55f2cc5cee3f71300fd8c5d953", + "order_id": 0, + "user_id": 0, + "guest_id": 0, + "sku_ids": [ + 16, + 19, + 25, + 13 + ], + "tids": [ + "FSN-PPBX-1", + "FSN-PLUP-4", + "FSN-PPCCT-2" + ], + "data": [ + { + "light": 2, + "refletion": -1, + "scale": "22", + "sku_id": 25, + "tid": "FSN-PPBX-1", + "rotation": "5.4,-41,-4.7", + "filePath": "", + "data": [ + { + "name": "model", + "data": "0,https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/bfc1dcc0f1a9beb49b2182d6c94de6f4bb648cd7b82be75b2e24e0bed3bef798,FSN-PPBX-1_MaskMap,FSN-PPBX-1_Normal,FSN-PPBX-1_BaseMap", + "type": "other", + "layer": "0", + "is_update": 1, + "mode": "Opaque" + }, + { + "name": "shadow", + "data": "0,FSN-PPBX-1,0,0,0", + "type": "other", + "layer": "0", + "is_update": 0, + "mode": "Fade" + } + ] + }, + { + "light": 8, + "refletion": -1, + "scale": "12.5", + "sku_id": 19, + "tid": "FSN-PPCCT-2", + "rotation": "-2,25.5,-1", + "filePath": "", + "data": [ + { + "name": "model", + "data": "0,https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/bfc1dcc0f1a9beb49b2182d6c94de6f4bb648cd7b82be75b2e24e0bed3bef798,FSN-PPCCT-2_MaskMap,FSN-PPCCT-2_Normal,FSN-PPCCT-2_BaseMap", + "type": "other", + "layer": "0", + "is_update": 1, + "mode": "Opaque" + }, + { + "name": "shadow", + "data": "0,FSN-PPCCT-2,0,0,0", + "type": "other", + "layer": "0", + "is_update": 0, + "mode": "Fade" + }, + { + "name": "model_P", + "data": "0,FSN-PPCCT-2-P,FSN-PPCCT-2-P_MaskMap,FSN-PPCCT-2-P_Normal,FSN-PPCCT-2-P_BaseMap", + "type": "other", + "layer": "0", + "is_update": 0, + "mode": "Fade" + } + ] + }, + { + "light": 7, + "refletion": 7, + "scale": "14", + "sku_id": 16, + "tid": "FSN-PLUP-4", + "rotation": "0,0,0", + "filePath": "", + "data": [ + { + "name": "model", + "data": "0,https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/bfc1dcc0f1a9beb49b2182d6c94de6f4bb648cd7b82be75b2e24e0bed3bef798,FSN-PLUP-4_MaskMap,FSN-PLUP-4_Normal,FSN-PLUP-4_BaseMap", + "type": "other", + "layer": "0", + "is_update": 1, + "mode": "Opaque" + }, + { + "name": "shadow", + "data": "0,FSN-PLUP-4,0,0,0", + "type": "other", + "layer": "0", + "is_update": 0, + "mode": "Fade" + }, + { + "name": "model_P", + "data": "0,FSN-PLUP-4-P,FSN-PLUP-4-P_MaskMap,FSN-PLUP-4-P_Normal,FSN-PLUP-4-P_BaseMap", + "type": "other", + "layer": "0", + "is_update": 0, + "mode": "Opaque" + } + ] + } + ], + "is_thousand_face": 0, + "folder": "" }` diff --git a/etc/etc_a.yaml b/etc/etc_a.yaml index 2dc1785..349897c 100644 --- a/etc/etc_a.yaml +++ b/etc/etc_a.yaml @@ -1,4 +1,4 @@ serverid: 1 -host: "localhost" +host: "0.0.0.0" port: 5050 -cluster: [ "localhost:5050","localhost:5051","localhost:5052" ] +cluster: [ "0.0.0.0:5050","0.0.0.0:5051","0.0.0.0:5052" ] diff --git a/etc/etc_b.yaml b/etc/etc_b.yaml index 9464b57..428deca 100644 --- a/etc/etc_b.yaml +++ b/etc/etc_b.yaml @@ -1,4 +1,4 @@ serverid: 2 -host: "localhost" +host: "0.0.0.0" port: 5051 -cluster: [ "localhost:5050","localhost:5051","localhost:5052" ] +cluster: [ "0.0.0.0:5050","0.0.0.0:5051","0.0.0.0:5052" ] diff --git a/etc/etc_c.yaml b/etc/etc_c.yaml index 708d551..83ca341 100644 --- a/etc/etc_c.yaml +++ b/etc/etc_c.yaml @@ -1,4 +1,4 @@ serverid: 3 -host: "localhost" +host: "0.0.0.0" port: 5052 -cluster: [ "localhost:5050","localhost:5051","localhost:5052" ] +cluster: [ "0.0.0.0:5050","0.0.0.0:5051","0.0.0.0:5052" ] diff --git a/main.go b/main.go index 285eae8..ad706fe 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,7 @@ var DequeueHandler = triggered.RegisterExecute(func(params *triggered.Params[boo cs := stateClient.GetNoOPSession() for i := 0; ; i++ { - item, err := stateClient.PopItem(cs, "test") + item, err := stateClient.PopItem(cs, "unity3d") if err != nil { log.Println(err) break diff --git a/main/main.go b/main/main.go new file mode 100644 index 0000000..4de92a7 --- /dev/null +++ b/main/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "flag" + "fmt" + "fusenrender" +) + +var configEnv string + +func init() { + flag.StringVar(&configEnv, "etc", "a", "配置环境(etc文件)") +} + +func main() { + + flag.Parse() + + configFile := fmt.Sprintf("../etc/etc_%s.yaml", configEnv) + + svc, err := fusenrender.LoadConfig(configFile) + if err != nil { + panic(err) + } + + fusenrender.StartNode(svc) +} diff --git a/main/start.sh b/main/start.sh new file mode 100755 index 0000000..b077c43 --- /dev/null +++ b/main/start.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +for env in a b c; do + + # 启动screen + screen_name="screen_$env" + screen -dmS $screen_name + + # 构造日志名 + log="log_$env.log" + + # 使用go run 重定向日志 + screen -S $screen_name -X stuff "go run main.go -env $env >> $log 2>&1\n" + +done \ No newline at end of file diff --git a/main/stop.sh b/main/stop.sh new file mode 100755 index 0000000..d3984c3 --- /dev/null +++ b/main/stop.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +for env in a b c; do + + # 构造screen会话名 + screen_name="screen_$env" + + # 使用-S参数直接停止指定会话 + screen -S $screen_name -X quit + + # 或者使用PID停止 + # screen_pid=$(screen -list | grep $screen_name | awk '{print $1}') + # kill $screen_pid + +done \ No newline at end of file diff --git a/websocket.go b/websocket.go index 1f21a5d..1a00312 100644 --- a/websocket.go +++ b/websocket.go @@ -24,9 +24,9 @@ var upgrader = websocket.Upgrader{ } func HttpListen(ns *dragonboat.NodeHost, port int) { - http.HandleFunc("/api/render/render_notify", callbackHandler) - http.HandleFunc("/api/queue/push", pushRenderTaskHandler) - http.HandleFunc("/ws/pop/queue", queueHandler) + // http.HandleFunc("/api/render/render_notify", callbackHandler) + http.HandleFunc("/api/render/queue/push", pushRenderTaskHandler) + http.HandleFunc("/api/ws/render/queue/pop", queueHandler) log.Printf(":%d", port) http.ListenAndServe(fmt.Sprintf(":%d", port), nil) @@ -162,7 +162,7 @@ func (cli *StateClient) PushItem(cs *client.Session, item *QueueItem) { cs = cli.GetNoOPSession() } - cmd := &CmdEnqueue{Command: Command{Group: "test"}} + cmd := &CmdEnqueue{Command: Command{Group: "unity3d"}} cmd.Item = item data, err := FsPasser.PackToBytes(cmd) @@ -185,7 +185,7 @@ func (cli *StateClient) PopItem(cs *client.Session, group string) (*QueueItem, e cs = cli.GetNoOPSession() } - cmd := &CmdDequeue{Command{Group: "test"}} + cmd := &CmdDequeue{Command{Group: "unity3d"}} data, err := FsPasser.PackToBytes(cmd) if err != nil { log.Println(err) diff --git a/websocket_test.go b/websocket_test.go index ce305b5..a11c831 100644 --- a/websocket_test.go +++ b/websocket_test.go @@ -19,7 +19,6 @@ func TestWebsocketA(t *testing.T) { } fusenrender.StartNode(svc) - } func TestWebsocketB(t *testing.T) { @@ -27,9 +26,7 @@ func TestWebsocketB(t *testing.T) { if err != nil { panic(err) } - fusenrender.StartNode(svc) - } func TestWebsocketC(t *testing.T) { @@ -37,9 +34,7 @@ func TestWebsocketC(t *testing.T) { if err != nil { panic(err) } - fusenrender.StartNode(svc) - } var addr = "localhost:4050" @@ -54,12 +49,12 @@ func TestWebsocketCient(t *testing.T) { C := time.NewTicker(time.Second * 5) for range C.C { item := fusenrender.QueueItem{ - Group: "test", - Wid: fusenrender.UidCreater.Get(), + Group: "unity3d", + CreateAt: time.Now(), Data: sendjson, } - r, err := requests.Post(fmt.Sprintf("http://%s/api/queue/push", addr)).SetBodyJson(item).Execute() + r, err := requests.Post(fmt.Sprintf("http://%s/api/render/queue/push", addr)).SetBodyJson(item).Execute() log.Println(r, err) } }()