diff options
author | abcang <abcang1015@gmail.com> | 2017-09-06 03:56:20 +0900 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-09-05 20:56:20 +0200 |
commit | be7ffa2d7539d5a1946a3933cb9d242b9fac0ddc (patch) | |
tree | 7def482f34aed6f0bf079d3b277520023d181d59 /lib | |
parent | e821c00e743160474072e78483f568dc4fdc6887 (diff) |
Do not execute the job with the same arguments as the retry job (#4814)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mastodon/unique_retry_job_middleware.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/mastodon/unique_retry_job_middleware.rb b/lib/mastodon/unique_retry_job_middleware.rb new file mode 100644 index 000000000..75da8a0c9 --- /dev/null +++ b/lib/mastodon/unique_retry_job_middleware.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class Mastodon::UniqueRetryJobMiddleware + def call(_worker_class, item, _queue, _redis_pool) + return if item['unique_retry'] && retried?(item) + yield + end + + private + + def retried?(item) + # Use unique digest key of SidekiqUniqueJobs + unique_key = SidekiqUniqueJobs::UNIQUE_DIGEST_KEY + unique_digest = item[unique_key] + class_name = item['class'] + retries = Sidekiq::RetrySet.new + + retries.any? { |job| job.item['class'] == class_name && job.item[unique_key] == unique_digest } + end +end |