Compare commits
No commits in common. "a564621d8062dc53d4d505467ce998600e09fa75" and "59869821f3fabfabd9d78c2dd7bb08fe94be5f4a" have entirely different histories.
a564621d80
...
59869821f3
@ -1,8 +1,11 @@
|
||||
package routers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
tasks "queues-go/app/storage/mongo/collections"
|
||||
"queues-go/app/storage/redis"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TaskResponse struct {
|
||||
@ -17,17 +20,17 @@ type TakeResponse struct {
|
||||
|
||||
func Take(r *http.Request) (interface{}, int) {
|
||||
queue := r.Header.Get("queue")
|
||||
// mutex := redis.Sync.NewMutex(fmt.Sprintf("lock_queues_%s", queue))
|
||||
// for {
|
||||
// err := mutex.Lock()
|
||||
// if err != nil {
|
||||
// time.Sleep(time.Millisecond * 5)
|
||||
// } else {
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
mutex := redis.Sync.NewMutex(fmt.Sprintf("lock_queues_%s", queue))
|
||||
for {
|
||||
err := mutex.Lock()
|
||||
if err != nil {
|
||||
time.Sleep(time.Millisecond * 5)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
task, err := tasks.Take(queue)
|
||||
// mutex.Unlock()
|
||||
mutex.Unlock()
|
||||
if err != nil {
|
||||
return nil, http.StatusInternalServerError
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user