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.

40 lines
1.3 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. begin
  9. media_attachment = MediaAttachment.find(media_attachment_id)
  10. media_attachment.processing = :failed
  11. media_attachment.save
  12. rescue ActiveRecord::RecordNotFound
  13. true
  14. end
  15. end
  16. Sidekiq.logger.error("Processing media attachment #{media_attachment_id} failed with #{msg['error_message']}")
  17. end
  18. def perform(media_attachment_id)
  19. media_attachment = MediaAttachment.find(media_attachment_id)
  20. media_attachment.processing = :in_progress
  21. media_attachment.save
  22. # Because paperclip-av-transcover overwrites this attribute
  23. # we will save it here and restore it after reprocess is done
  24. previous_meta = media_attachment.file_meta
  25. media_attachment.file.reprocess!(:original)
  26. media_attachment.processing = :complete
  27. media_attachment.file_meta = previous_meta.merge(media_attachment.file_meta).with_indifferent_access.slice(*MediaAttachment::META_KEYS)
  28. media_attachment.save
  29. rescue ActiveRecord::RecordNotFound
  30. true
  31. end
  32. end