闭社主体 forked from https://github.com/tootsuite/mastodon
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.

34 lines
969 B

  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