mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 07:28:27 +00:00
Tweaks to roomserver input with comments
This commit is contained in:
parent
ffa793426c
commit
42a5a52fbd
1 changed files with 10 additions and 3 deletions
|
@ -54,8 +54,10 @@ type Inputer struct {
|
||||||
func (r *Inputer) Start() error {
|
func (r *Inputer) Start() error {
|
||||||
_, err := r.JetStream.Subscribe(
|
_, err := r.JetStream.Subscribe(
|
||||||
r.InputRoomEventTopic,
|
r.InputRoomEventTopic,
|
||||||
|
// We specifically don't use jetstream.WithJetStreamMessage here because we
|
||||||
|
// queue the task off to a room-specific queue and the ACK needs to be sent
|
||||||
|
// later, possibly with an error response to the inputter if synchronous.
|
||||||
func(msg *nats.Msg) {
|
func(msg *nats.Msg) {
|
||||||
_ = msg.InProgress()
|
|
||||||
roomID := msg.Header.Get("room_id")
|
roomID := msg.Header.Get("room_id")
|
||||||
defer roomserverInputBackpressure.With(prometheus.Labels{"room_id": roomID}).Dec()
|
defer roomserverInputBackpressure.With(prometheus.Labels{"room_id": roomID}).Dec()
|
||||||
var inputRoomEvent api.InputRoomEvent
|
var inputRoomEvent api.InputRoomEvent
|
||||||
|
@ -65,17 +67,22 @@ func (r *Inputer) Start() error {
|
||||||
}
|
}
|
||||||
inbox, _ := r.workers.LoadOrStore(roomID, &phony.Inbox{})
|
inbox, _ := r.workers.LoadOrStore(roomID, &phony.Inbox{})
|
||||||
inbox.(*phony.Inbox).Act(nil, func() {
|
inbox.(*phony.Inbox).Act(nil, func() {
|
||||||
_ = msg.InProgress()
|
|
||||||
if err := r.processRoomEvent(context.TODO(), &inputRoomEvent); err != nil {
|
if err := r.processRoomEvent(context.TODO(), &inputRoomEvent); err != nil {
|
||||||
sentry.CaptureException(err)
|
sentry.CaptureException(err)
|
||||||
_ = msg.Respond([]byte(err.Error()))
|
|
||||||
} else {
|
} else {
|
||||||
hooks.Run(hooks.KindNewEventPersisted, inputRoomEvent.Event)
|
hooks.Run(hooks.KindNewEventPersisted, inputRoomEvent.Event)
|
||||||
}
|
}
|
||||||
_ = msg.Ack()
|
_ = msg.Ack()
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
// NATS wants to acknowledge automatically by default when the message is
|
||||||
|
// read from the stream, but we want to override that behaviour by making
|
||||||
|
// sure that we only acknowledge when we're happy we've done everything we
|
||||||
|
// can. This ensures we retry things when it makes sense to do so.
|
||||||
nats.ManualAck(),
|
nats.ManualAck(),
|
||||||
|
// NATS will try to redeliver things to us automatically if we don't ack
|
||||||
|
// or nak them within a certain amount of time. This stops that from
|
||||||
|
// happening, so we don't end up doing a lot of unnecessary duplicate work.
|
||||||
nats.MaxDeliver(0),
|
nats.MaxDeliver(0),
|
||||||
)
|
)
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue