poll_expiration_notify_worker.rb 600 B

123456789101112131415161718192021222324
  1. # frozen_string_literal: true
  2. class PollExpirationNotifyWorker
  3. include Sidekiq::Worker
  4. sidekiq_options lock: :until_executed
  5. def perform(poll_id)
  6. poll = Poll.find(poll_id)
  7. # Notify poll owner and remote voters
  8. if poll.local?
  9. ActivityPub::DistributePollUpdateWorker.perform_async(poll.status.id)
  10. NotifyService.new.call(poll.account, poll)
  11. end
  12. # Notify local voters
  13. poll.votes.includes(:account).map(&:account).select(&:local?).each do |account|
  14. NotifyService.new.call(account, poll)
  15. end
  16. rescue ActiveRecord::RecordNotFound
  17. true
  18. end
  19. end