pubsub: added retry on reddit or database busy
This commit is contained in:
parent
1896839664
commit
1b29cf8337
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue