闭社主体 forked from https://github.com/tootsuite/mastodon
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.

20 lines
545 B

  1. # frozen_string_literal: true
  2. class Mastodon::UniqueRetryJobMiddleware
  3. def call(_worker_class, item, _queue, _redis_pool)
  4. return if item['unique_retry'] && retried?(item)
  5. yield
  6. end
  7. private
  8. def retried?(item)
  9. # Use unique digest key of SidekiqUniqueJobs
  10. unique_key = SidekiqUniqueJobs::UNIQUE_DIGEST_KEY
  11. unique_digest = item[unique_key]
  12. class_name = item['class']
  13. retries = Sidekiq::RetrySet.new
  14. retries.any? { |job| job.item['class'] == class_name && job.item[unique_key] == unique_digest }
  15. end
  16. end