Pārlūkot izejas kodu

backfill queue: set the dispatch time instead of completed time

Sumner Evans 3 gadi atpakaļ
vecāks
revīzija
c1bf0e6555
3 mainītis faili ar 15 papildinājumiem un 2 dzēšanām
  1. 1 1
      backfillqueue.go
  2. 12 1
      database/backfillqueue.go
  3. 2 0
      historysync.go

+ 1 - 1
backfillqueue.go

@@ -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:

+ 12 - 1
database/backfillqueue.go

@@ -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)

+ 2 - 0
historysync.go

@@ -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()
 	}
 }