Compare commits
No commits in common. "e791890ea5ed2b3dadccf795e8594426263992ef" and "710a81139c032732ac3b09f957690317c9e4e885" have entirely different histories.
e791890ea5
...
710a81139c
@ -1,13 +1,9 @@
|
|||||||
package routers
|
package routers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
tasks "queues-go/app/storage/mongo/collections"
|
tasks "queues-go/app/storage/mongo/collections"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TaskResponse struct {
|
type TaskResponse struct {
|
||||||
@ -22,20 +18,6 @@ type TakeResponse struct {
|
|||||||
|
|
||||||
var MutexMap map[string]*sync.Mutex
|
var MutexMap map[string]*sync.Mutex
|
||||||
|
|
||||||
func sendLatency(timestamp time.Time, latency int) error {
|
|
||||||
loc, _ := time.LoadLocation("Europe/Moscow")
|
|
||||||
s := fmt.Sprintf(
|
|
||||||
`{"timestamp":"%s","service":"queues","environment":"%s","name":"latency","count":%s}`,
|
|
||||||
timestamp.In(loc).Format("2006-01-02T15:04:05Z"),
|
|
||||||
os.Getenv("STAGE"),
|
|
||||||
latency,
|
|
||||||
)
|
|
||||||
data := []byte(s)
|
|
||||||
r := bytes.NewReader(data)
|
|
||||||
_, err := http.Post("http://monitoring:1237/api/v1/metrics/increment", "application/json", r)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func Take(r *http.Request) (interface{}, int) {
|
func Take(r *http.Request) (interface{}, int) {
|
||||||
queue := r.Header.Get("queue")
|
queue := r.Header.Get("queue")
|
||||||
mutex, ok := MutexMap[queue]
|
mutex, ok := MutexMap[queue]
|
||||||
@ -59,8 +41,6 @@ func Take(r *http.Request) (interface{}, int) {
|
|||||||
Attempt: task.Attempts,
|
Attempt: task.Attempts,
|
||||||
Payload: task.Payload,
|
Payload: task.Payload,
|
||||||
}
|
}
|
||||||
now := time.Now()
|
|
||||||
go sendLatency(now, int(now.Sub(task.PutAt).Milliseconds()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, http.StatusOK
|
return response, http.StatusOK
|
||||||
|
Loading…
Reference in New Issue
Block a user