post_process_media_worker.rb 967 B

12345678910111213141516171819202122232425262728293031323334
  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. media_attachment.file.reprocess_original!
  23. media_attachment.processing = :complete
  24. media_attachment.save
  25. rescue ActiveRecord::RecordNotFound
  26. true
  27. end
  28. end