From 252c82f1e46dffbfbeceab75b049759e2c2b35c2 Mon Sep 17 00:00:00 2001 From: Sinh Date: Mon, 26 Dec 2022 15:16:46 +0700 Subject: [PATCH] add client queue --- client/queue.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 client/queue.go diff --git a/client/queue.go b/client/queue.go new file mode 100644 index 0000000..8cb048d --- /dev/null +++ b/client/queue.go @@ -0,0 +1,35 @@ +package client + +import ( + "encoding/json" + "errors" + + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" +) + +// Queue ... +type Queue struct{} + +// GetQueue ... +func GetQueue() Queue { + return Queue{} +} + +func (c Queue) ScheduleTask(p model.QueueScheduleTaskRequest) error { + msg, err := natsio.GetServer().Request(subject.Queue.ScheduleTask, toBytes(p)) + if err != nil { + return err + } + var r struct { + Error string `json:"error"` + } + if err = json.Unmarshal(msg.Data, &r); err != nil { + return err + } + if r.Error != "" { + return errors.New(r.Error) + } + return nil +}