Add retry for failed media downloads and tootctl media refresh
#11775
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We download media attachments synchronously when processing a new remote status, so that we have all the information we need before the status is distributed to end-users through the streaming API &co. However, sometimes the download fails due to high load on the origin server, or Wasabi being an awfully unstable service. In those cases, we want to retry downloading specifically that attachment at a later time.
With this, a separate Sidekiq job will be queued with a random delay between 30 seconds and 10 minutes that attempts to re-download that attachment at most 3 times with exponential backoff.
Separately, there's a fix for not processing more than 4 media attachments for a status, since they will never be used within Mastodon (close #9325).
Furthermore, a new tootctl command,
tootctl media refresh
allows to re-download attachments for a particular status, a particular account, or a particular domain.