CLI flush action
This commit is contained in:
parent
5f1ed72712
commit
a79904ece6
13
cli/main.go
13
cli/main.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -89,6 +90,18 @@ func main() {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "flush",
|
||||||
|
Usage: "Flush all messages from given queues",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
if msgs := bsq.Flush(c.Args()...); msgs != nil {
|
||||||
|
jsn, _ := json.Marshal(msgs)
|
||||||
|
fmt.Println(string(jsn))
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Failed to flush queues %s\n", strings.Join(c.Args(), ", "))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "status",
|
Name: "status",
|
||||||
Usage: "Show server status",
|
Usage: "Show server status",
|
||||||
|
|
|
@ -103,32 +103,33 @@ func (c *Client) Subscribe(queues ...string) *Message {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Flush(queues ...string) (messages []*Message) {
|
func (c *Client) Flush(queues ...string) []*Message {
|
||||||
url := c.url(flushEndpoint, "?queues=", strings.Join(queues, ","))
|
url := c.url(flushEndpoint, "?queues=", strings.Join(queues, ","))
|
||||||
_, body := c.get(url)
|
_, body := c.get(url)
|
||||||
|
|
||||||
var tmp []map[string]string
|
var tmp []map[string]string
|
||||||
if err := json.Unmarshal(body, &tmp); err != nil {
|
if err := json.Unmarshal(body, &tmp); err != nil {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
messages = []*Message{}
|
messages := []*Message{}
|
||||||
for _, msg := range tmp {
|
for _, msg := range tmp {
|
||||||
messages = append(messages, &Message{msg["queue"], []byte(msg["message"])})
|
messages = append(messages, &Message{msg["queue"], []byte(msg["message"])})
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return messages
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Status() (stat []*QueueInfo) {
|
func (c *Client) Status() []*QueueInfo {
|
||||||
url := c.url(statusEndpoit)
|
url := c.url(statusEndpoit)
|
||||||
_, body := c.get(url)
|
_, body := c.get(url)
|
||||||
|
|
||||||
tmp := make(map[string]map[string]int)
|
tmp := make(map[string]map[string]int)
|
||||||
if err := json.Unmarshal(body, &tmp); err != nil {
|
if err := json.Unmarshal(body, &tmp); err != nil {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stat := []*QueueInfo{}
|
||||||
for queue, info := range tmp {
|
for queue, info := range tmp {
|
||||||
qi := &QueueInfo{
|
qi := &QueueInfo{
|
||||||
Name: queue,
|
Name: queue,
|
||||||
|
@ -138,7 +139,7 @@ func (c *Client) Status() (stat []*QueueInfo) {
|
||||||
stat = append(stat, qi)
|
stat = append(stat, qi)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return stat
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Debug() *DebugInfo {
|
func (c *Client) Debug() *DebugInfo {
|
||||||
|
|
Loading…
Reference in New Issue