Refactor RedisRouter subscribe function to include timeout parameter
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
04d2b0246a
commit
5491244d01
@ -59,7 +59,7 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe
|
|||||||
}
|
}
|
||||||
if msg.Timeout > 0 {
|
if msg.Timeout > 0 {
|
||||||
// set timeout for the lookup
|
// set timeout for the lookup
|
||||||
r.subscribe(msg)
|
r.subscribe(msg, int(msg.Timeout))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// manage Matriochka
|
// manage Matriochka
|
||||||
@ -196,7 +196,7 @@ func goSubscribeAndListen(client *redis.Client, key string, messages chan<- stri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RedisRouter) subscribe(msg *meowlib.ToServerMessage) (*meowlib.FromServerMessage, error) {
|
func (r *RedisRouter) subscribe(msg *meowlib.ToServerMessage, timeout int) (*meowlib.FromServerMessage, error) {
|
||||||
var from_server meowlib.FromServerMessage
|
var from_server meowlib.FromServerMessage
|
||||||
// update messages counter
|
// update messages counter
|
||||||
err := r.Client.Incr("statistics:messages:messagessubscription").Err()
|
err := r.Client.Incr("statistics:messages:messagessubscription").Err()
|
||||||
@ -217,7 +217,7 @@ func (r *RedisRouter) subscribe(msg *meowlib.ToServerMessage) (*meowlib.FromServ
|
|||||||
case <-messages:
|
case <-messages:
|
||||||
close(done)
|
close(done)
|
||||||
return r.checkForMessage(msg)
|
return r.checkForMessage(msg)
|
||||||
case <-time.After(10 * time.Second): // 10 seconds timeout
|
case <-time.After(time.Duration(timeout) * time.Second): // 10 seconds timeout
|
||||||
close(done)
|
close(done)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
Loading…
Reference in New Issue
Block a user