publish_scheduled_status_worker.rb 853 B

1234567891011121314151617181920212223242526
  1. # frozen_string_literal: true
  2. class PublishScheduledStatusWorker
  3. include Sidekiq::Worker
  4. sidekiq_options lock: :until_executed, lock_ttl: 1.hour.to_i
  5. def perform(scheduled_status_id)
  6. scheduled_status = ScheduledStatus.find(scheduled_status_id)
  7. scheduled_status.destroy!
  8. PostStatusService.new.call(
  9. scheduled_status.account,
  10. options_with_objects(scheduled_status.params.with_indifferent_access)
  11. )
  12. rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid
  13. true
  14. end
  15. def options_with_objects(options)
  16. options.tap do |options_hash|
  17. options_hash[:application] = Doorkeeper::Application.find(options_hash.delete(:application_id)) if options[:application_id]
  18. options_hash[:thread] = Status.find(options_hash.delete(:in_reply_to_id)) if options_hash[:in_reply_to_id]
  19. end
  20. end
  21. end