Refactor RedisRouter subscribe function to include timeout parameter
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc 2024-04-23 22:48:37 +02:00
parent 04d2b0246a
commit 5491244d01

View File

@ -59,7 +59,7 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe
}
if msg.Timeout > 0 {
// set timeout for the lookup
r.subscribe(msg)
r.subscribe(msg, int(msg.Timeout))
}
}
// 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
// update messages counter
err := r.Client.Incr("statistics:messages:messagessubscription").Err()
@ -217,7 +217,7 @@ func (r *RedisRouter) subscribe(msg *meowlib.ToServerMessage) (*meowlib.FromServ
case <-messages:
close(done)
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)
}
wg.Wait()