Skip to content
Snippets Groups Projects
Unverified Commit 4394a07e authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Use Pub/Sub instead of keyspace events to watch for notifications

parent 00886ef6
No related branches found
No related tags found
1 merge request!129WIP: Use Pub/Sub instead of keyspace events to watch for notifications
Pipeline #
Loading
Loading
@@ -3,7 +3,6 @@ package redis
import (
"fmt"
"log"
"strings"
"sync"
"time"
 
Loading
Loading
@@ -35,10 +34,7 @@ func init() {
}
 
const (
keyPubSpacePrefix = "__keyspace@*__:"
keyPubSpaceRunner = keyPubSpacePrefix + "runner:build_queue:*"
promStatusMiss = "miss"
promStatusHit = "hit"
keyPubSpaceRunner = "runner:build_queue_notifications"
)
 
// KeyChan holds a key and a channel
Loading
Loading
@@ -50,16 +46,15 @@ type KeyChan struct {
func processInner(conn redis.Conn) {
defer conn.Close()
psc := redis.PubSubConn{Conn: conn}
if err := psc.PSubscribe(keyPubSpaceRunner); err != nil {
if err := psc.Subscribe(keyPubSpaceRunner); err != nil {
return
}
defer psc.PUnsubscribe(keyPubSpaceRunner)
defer psc.Unsubscribe(keyPubSpaceRunner)
 
for {
switch v := psc.Receive().(type) {
case redis.PMessage:
key := strings.TrimPrefix(string(v.Channel), keyPubSpacePrefix)
notifyChanWatchers(key)
case redis.Message:
notifyChanWatchers(string(v.Data))
case error:
return
}
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment