subscribe_worker.rb 894 B

12345678910111213141516171819202122232425262728293031323334
  1. # frozen_string_literal: true
  2. class Pubsubhubbub::SubscribeWorker
  3. include Sidekiq::Worker
  4. sidekiq_options queue: 'push', retry: 10, unique: :until_executed, dead: false, unique_retry: true
  5. sidekiq_retry_in do |count|
  6. case count
  7. when 0
  8. 30.minutes.seconds
  9. when 1
  10. 2.hours.seconds
  11. when 2
  12. 12.hours.seconds
  13. else
  14. 24.hours.seconds * (count - 2)
  15. end
  16. end
  17. sidekiq_retries_exhausted do |msg, _e|
  18. account = Account.find(msg['args'].first)
  19. logger.error "PuSH subscription attempts for #{account.acct} exhausted. Unsubscribing"
  20. ::UnsubscribeService.new.call(account)
  21. end
  22. def perform(account_id)
  23. account = Account.find(account_id)
  24. logger.debug "PuSH re-subscribing to #{account.acct}"
  25. ::SubscribeService.new.call(account)
  26. rescue => e
  27. raise e.class, "Subscribe failed for #{account&.acct}: #{e.message}"
  28. end
  29. end