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.

24 lines
614 B

  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, 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, poll)
  15. end
  16. rescue ActiveRecord::RecordNotFound
  17. true
  18. end
  19. end