2019-01-05 06:43:28 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class PublishScheduledStatusWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
2023-10-03 04:09:00 -04:00
|
|
|
sidekiq_options lock: :until_executed, lock_ttl: 1.hour.to_i
|
2019-01-20 06:57:05 -05:00
|
|
|
|
2019-01-05 06:43:28 -05:00
|
|
|
def perform(scheduled_status_id)
|
|
|
|
scheduled_status = ScheduledStatus.find(scheduled_status_id)
|
|
|
|
scheduled_status.destroy!
|
|
|
|
|
|
|
|
PostStatusService.new.call(
|
|
|
|
scheduled_status.account,
|
|
|
|
options_with_objects(scheduled_status.params.with_indifferent_access)
|
|
|
|
)
|
|
|
|
rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def options_with_objects(options)
|
|
|
|
options.tap do |options_hash|
|
|
|
|
options_hash[:application] = Doorkeeper::Application.find(options_hash.delete(:application_id)) if options[:application_id]
|
2019-01-06 06:03:27 -05:00
|
|
|
options_hash[:thread] = Status.find(options_hash.delete(:in_reply_to_id)) if options_hash[:in_reply_to_id]
|
2019-01-05 06:43:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|