Move out SetCallbacks to allow for better DI

This commit is contained in:
Kegan Dougal 2023-06-08 16:59:37 +01:00
parent e753f51d24
commit 08f34ba5c2
2 changed files with 7 additions and 4 deletions

View File

@ -3,11 +3,12 @@ package handler2
import (
"context"
"encoding/json"
"github.com/getsentry/sentry-go"
"hash/fnv"
"os"
"sync"
"github.com/getsentry/sentry-go"
"github.com/matrix-org/sliding-sync/internal"
"github.com/matrix-org/sliding-sync/pubsub"
"github.com/matrix-org/sliding-sync/state"
@ -58,7 +59,6 @@ func NewHandler(
}),
typingMap: make(map[string]uint64),
}
pMap.SetCallbacks(h)
if enablePrometheus {
h.addPrometheusMetrics()

7
v3.go
View File

@ -3,12 +3,13 @@ package slidingsync
import (
"encoding/json"
"fmt"
"github.com/getsentry/sentry-go"
"net/http"
"os"
"strings"
"time"
"github.com/getsentry/sentry-go"
"github.com/gorilla/mux"
"github.com/matrix-org/sliding-sync/internal"
"github.com/matrix-org/sliding-sync/pubsub"
@ -83,11 +84,13 @@ func Setup(destHomeserver, postgresURI, secret string, opts Opts) (*handler2.Han
}
pubSub := pubsub.NewPubSub(bufferSize)
pMap := sync2.NewPollerMap(v2Client, opts.AddPrometheusMetrics)
// create v2 handler
h2, err := handler2.NewHandler(postgresURI, sync2.NewPollerMap(v2Client, opts.AddPrometheusMetrics), storev2, store, v2Client, pubSub, pubSub, opts.AddPrometheusMetrics)
h2, err := handler2.NewHandler(postgresURI, pMap, storev2, store, v2Client, pubSub, pubSub, opts.AddPrometheusMetrics)
if err != nil {
panic(err)
}
pMap.SetCallbacks(h2)
// create v3 handler
h3, err := handler.NewSync3Handler(store, storev2, v2Client, postgresURI, secret, pubSub, pubSub, opts.AddPrometheusMetrics, opts.MaxPendingEventUpdates)