pubsub: added retry on reddit or database busy

This commit is contained in:
Tigor Hutasuhut 2024-05-23 15:27:36 +07:00
parent 1896839664
commit 1b29cf8337

View file

@ -60,12 +60,19 @@ func (api *API) StartSubredditDownloadPubsub(messages <-chan *message.Message) {
devices, err := models.Devices.Query(ctx, api.db, models.SelectWhere.Devices.Enable.EQ(1)).All() devices, err := models.Devices.Query(ctx, api.db, models.SelectWhere.Devices.Enable.EQ(1)).All()
if err != nil { if err != nil {
msg.Nack()
log.New(ctx).Err(err).Error("failed to query devices") log.New(ctx).Err(err).Error("failed to query devices")
return return
} }
err = api.DownloadSubredditImages(ctx, subreddit, devices) err = api.DownloadSubredditImages(ctx, subreddit, devices)
if err != nil { if err != nil {
if errs.HasCode(err, http.StatusTooManyRequests) {
msg.Nack()
}
if errs.Source(err).Error() == "database is locked" {
msg.Nack()
}
log.New(ctx).Err(err).Error("failed to download subreddit images", "subreddit", subreddit) log.New(ctx).Err(err).Error("failed to download subreddit images", "subreddit", subreddit)
return return
} }