manifold
manifold copied to clipboard
Surface attachment derivative errors
- Promote the attachment right away
- Continue to process derivatives in the background
- Ensure that client continues to show processing placeholder until derivatives exist
- Use Shrine add_metadata plugin to store derivative errors
- Expose derivative errors in the serializer
- Render derivative errors underneath attachment fields
Derivatives job could look like this:
module Attachments
class CreateDerivativesJob < ApplicationJob
queue_as :processing
discard_on ActiveJob::DeserializationError
def perform(record, attachment_name)
uploaded_file = record.public_send(:"#{attachment_name}_attacher")
uploaded_file.create_derivatives # i think this is the method, may need something slightly more since we're no longer promoting here
uploaded_file.add_metadata has_derivatives: true, derivatives_failed_at: nil, derivative_failure_reason: nil, derivative_failure_exception_klass: nil
uploaded_file.write
record.save!
rescue SomeException => e
uploaded_file.add_metadata has_derivatives: false, derivatives_failed_at: Time.current, derivative_failure_reason: e.message, derivative_failure_exception_klass: e.class.name
uploaded_file.write
record.save!
end
end
end