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.

34 lines
898 B

  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
  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. Sidekiq.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}", e.backtrace[0]
  28. end
  29. end