backfill queue: set the dispatch time instead of completed time

This commit is contained in:
Sumner Evans 2022-05-09 10:07:26 -06:00
parent 17c697445d
commit c1bf0e6555
No known key found for this signature in database
GPG key ID: 8904527AB50022FD
3 changed files with 15 additions and 2 deletions

View file

@ -51,7 +51,7 @@ func (bq *BackfillQueue) RunLoop(user *User) {
} else {
bq.log.Debugfln("Unrecognized backfill type %d in queue", backfill.BackfillType)
}
backfill.MarkDone()
backfill.MarkDispatched()
} else {
select {
case <-bq.ReCheckQueue:

View file

@ -167,9 +167,20 @@ func (b *Backfill) Insert() {
}
}
func (b *Backfill) MarkDispatched() {
if b.QueueID == 0 {
b.log.Errorf("Cannot mark backfill as dispatched without queue_id. Maybe it wasn't actually inserted in the database?")
return
}
_, err := b.db.Exec("UPDATE backfill_queue SET dispatch_time=$1 WHERE queue_id=$2", time.Now(), b.QueueID)
if err != nil {
b.log.Warnfln("Failed to mark %s/%s as dispatched: %v", b.BackfillType, b.Priority, err)
}
}
func (b *Backfill) MarkDone() {
if b.QueueID == 0 {
b.log.Errorf("Cannot delete backfill without queue_id. Maybe it wasn't actually inserted in the database?")
b.log.Errorf("Cannot mark backfill done without queue_id. Maybe it wasn't actually inserted in the database?")
return
}
_, err := b.db.Exec("UPDATE backfill_queue SET completed_at=$1 WHERE queue_id=$2", time.Now(), b.QueueID)

View file

@ -136,6 +136,7 @@ func (user *User) handleBackfillRequestsLoop(backfillRequests chan *database.Bac
conv := user.bridge.DB.HistorySync.GetConversation(user.MXID, req.Portal)
if conv == nil {
user.log.Debugfln("Could not find history sync conversation data for %s", req.Portal.String())
req.MarkDone()
continue
}
portal := user.GetPortalByJID(conv.PortalKey.JID)
@ -157,6 +158,7 @@ func (user *User) handleBackfillRequestsLoop(backfillRequests chan *database.Bac
}
user.backfillInChunks(req, conv, portal)
req.MarkDone()
}
}