You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. class PostProcessMediaWorker
  3. include Sidekiq::Worker
  4. sidekiq_options retry: 1, dead: false
  5. sidekiq_retries_exhausted do |msg|
  6. media_attachment_id = msg['args'].first
  7. ActiveRecord::Base.connection_pool.with_connection do
  8. media_attachment = MediaAttachment.find(media_attachment_id)
  9. media_attachment.processing = :failed
  10. media_attachment.save
  11. rescue ActiveRecord::RecordNotFound
  12. true
  13. end
  14. Sidekiq.logger.error("Processing media attachment #{media_attachment_id} failed with #{msg['error_message']}")
  15. end
  16. def perform(media_attachment_id)
  17. media_attachment = MediaAttachment.find(media_attachment_id)
  18. media_attachment.processing = :in_progress
  19. media_attachment.save
  20. # Because paperclip-av-transcover overwrites this attribute
  21. # we will save it here and restore it after reprocess is done
  22. previous_meta = media_attachment.file_meta
  23. media_attachment.file.reprocess!(:original)
  24. media_attachment.processing = :complete
  25. media_attachment.file_meta = previous_meta.merge(media_attachment.file_meta).with_indifferent_access.slice(*MediaAttachment::META_KEYS)
  26. media_attachment.save
  27. rescue ActiveRecord::RecordNotFound
  28. true
  29. end
  30. end