refactor: streamline relation sync worker
This commit is contained in:
@@ -81,16 +81,6 @@ func retryBackoff(attempts int64) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *Worker) processAnimeFetchRetries(ctx context.Context) {
|
func (w *Worker) processAnimeFetchRetries(ctx context.Context) {
|
||||||
pending, err := w.db.CountPendingAnimeFetchRetries(ctx)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("worker: failed to count pending anime fetch retries: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if pending == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
retries, err := w.db.GetDueAnimeFetchRetries(ctx, 20)
|
retries, err := w.db.GetDueAnimeFetchRetries(ctx, 20)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("worker: failed to load due anime fetch retries: %v", err)
|
log.Printf("worker: failed to load due anime fetch retries: %v", err)
|
||||||
@@ -190,17 +180,13 @@ func (w *Worker) syncRelations(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also update the status of the anime itself so we know if it's Not yet aired, etc.
|
|
||||||
animeDetails, err := w.client.GetAnimeByID(ctx, int(a.ID))
|
|
||||||
if err == nil {
|
|
||||||
err = w.db.UpdateAnimeStatus(ctx, database.UpdateAnimeStatusParams{
|
err = w.db.UpdateAnimeStatus(ctx, database.UpdateAnimeStatusParams{
|
||||||
Status: sql.NullString{String: animeDetails.Status, Valid: true},
|
Status: sql.NullString{String: animeData.Status, Valid: true},
|
||||||
ID: a.ID,
|
ID: a.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("worker: failed to update status for %d: %v", a.ID, err)
|
log.Printf("worker: failed to update status for %d: %v", a.ID, err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user