Commit graph

6 commits

Author SHA1 Message Date
Pierre de La Morinerie
75a1046315 active_storage: refactor concerns
Follow-up of #5953.

Refactor the concerns with two goals:

- Getting closer from the way ActiveStorage adds its own hooks.
  Usually ActiveStorage does this using an `Attachment#after_create`
  hook, which then delegates to the blob to enqueue the job.
- Enqueuing each job only once. By hooking on `Attachment#after_create`,
  we guarantee each job will be added only once.

We then let the jobs themselves check if they are relevant or not, and
retry or discard themselves if necessary.

We also need to update the tests a bit, because Rails'
`perform_enqueued_jobs(&block)` test helper doesn't honor the `retry_on`
clause of jobs. Instead it forwards the exception to the caller – which
makes the test fail.

Instead we use the inline version of `perform_enqueued_jobs()`, without
a block, which properly ignores errors catched by retry_on.
2021-03-16 11:49:14 +01:00
Pierre de La Morinerie
08094e5384 jobs: retry on ActiveStorage::IntegrityError during virus scan
This is the same setting than what ActiveStorage::AnalyzeJob uses.
2021-03-16 10:52:12 +01:00
Pierre de La Morinerie
292dc84eb4 jobs: ignore deleted file in Virus Scan
We have errors in production where the job starts correctly (i.e. the
blob exists), but `blob.open` fails with a `ActiveStorage::FileNotFound`
error.

When checking later in production, the blob has been deleted.

This points to the blob (and the file) being deleted during the virus
scan job.

In that case, ignore the error (rather than retrying the job).
2020-09-03 11:00:59 +02:00
Pierre de La Morinerie
54a4db1c47 config: flip config.active_storage.queues
ActiveStorage jobs are now moved to their own queue.

For consistency, we also move our own analysis jobs (VirusScannerJob)
on the same `:active_storage_analysis` queue.
2020-08-05 16:48:36 +02:00
Pierre de La Morinerie
7a67f1a802 jobs: ignore missing blob during virus scan
We currently have many failed VirusScannerJob enqueued, because the
underlying blob is missing.

This PR fixes the issue by discarding the job in those cases (because if
the blob is gone, the job is never going to succeed).

The implementation is based on a similar issue encoutered by the
ActiveStorage::AnalyzeJob. See 06f8baf73c
2020-07-13 14:35:41 +02:00
Paul Chavard
f113d108c9 Save virus scan status to blob metadata 2019-05-02 15:58:09 +02:00