Don't spin

This commit is contained in:
Neil Alexander 2020-07-02 16:19:48 +01:00
parent 9ad0781831
commit 0214ce3f4f

View file

@ -164,6 +164,9 @@ func (oq *destinationQueue) wakeQueueIfNeeded() {
} else {
log.WithError(err).Errorf("Can't get pending PDU count for %q destination queue", oq.destination)
}
if count > 0 {
oq.wakeServerCh <- true
}
// Then start the queue.
go oq.backgroundSend()
}
@ -182,7 +185,6 @@ func (oq *destinationQueue) backgroundSend() {
for {
// If we have nothing to do then wait either for incoming events, or
// until we hit an idle timeout.
if oq.pendingPDUs.Load() == 0 && len(oq.pendingEDUs) == 0 && len(oq.pendingInvites) == 0 {
select {
case <-oq.wakeServerCh:
// We were woken up because there are new PDUs waiting in the
@ -222,7 +224,6 @@ func (oq *destinationQueue) backgroundSend() {
// send.
return
}
}
// If we are backing off this server then wait for the
// backoff duration to complete first, or until explicitly
@ -329,8 +330,10 @@ func (oq *destinationQueue) nextTransaction(
// Ask the database for any pending PDUs from the next transaction.
// maxPDUsPerTransaction is an upper limit but we probably won't
// actually retrieve that many events.
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
txid, pdus, err := oq.db.GetNextTransactionPDUs(
context.TODO(), // context
ctx, // context
oq.destination, // server name
maxPDUsPerTransaction, // max events to retrieve
)