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.

26 lines
830 B

  1. # frozen_string_literal: true
  2. class PublishScheduledStatusWorker
  3. include Sidekiq::Worker
  4. sidekiq_options lock: :until_executed
  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