Skip to content

Commit

Permalink
Allows configuration of the Dead Job Queue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhyman committed Feb 4, 2015
1 parent 32e1a41 commit b9c2982
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Changes.md
@@ -1,3 +1,7 @@
3.3.2 (unreleased)
-----------
- Allows configuration of dead job set size and timeout

3.3.1
-----------

Expand Down
4 changes: 3 additions & 1 deletion lib/sidekiq.rb
Expand Up @@ -25,7 +25,9 @@ module Sidekiq
startup: [],
quiet: [],
shutdown: [],
}
},
dead_max_jobs: 10_000,
dead_timeout_in_seconds: 180 * 24 * 60 * 60 # 6 months
}

def self.❨╯°□°❩╯︵┻━┻
Expand Down
15 changes: 10 additions & 5 deletions lib/sidekiq/api.rb
Expand Up @@ -399,8 +399,8 @@ def kill
Sidekiq.redis do |conn|
conn.multi do
conn.zadd('dead', now, message)
conn.zremrangebyscore('dead', '-inf', now - DeadSet::TIMEOUT)
conn.zremrangebyrank('dead', 0, - DeadSet::MAX_JOBS)
conn.zremrangebyscore('dead', '-inf', now - DeadSet.timeout)
conn.zremrangebyrank('dead', 0, - DeadSet.max_jobs)
end
end
end
Expand Down Expand Up @@ -593,9 +593,6 @@ def retry_all
# Allows enumeration of dead jobs within Sidekiq.
#
class DeadSet < JobSet
TIMEOUT = 180 * 24 * 60 * 60 # 6 months
MAX_JOBS = 10_000

def initialize
super 'dead'
end
Expand All @@ -605,6 +602,14 @@ def retry_all
each(&:retry)
end
end

def self.max_jobs
Sidekiq.options[:dead_max_jobs]
end

def self.timeout
Sidekiq.options[:dead_timeout_in_seconds]
end
end

##
Expand Down
4 changes: 2 additions & 2 deletions lib/sidekiq/middleware/server/retry_jobs.rb
Expand Up @@ -156,8 +156,8 @@ def send_to_morgue(msg)
Sidekiq.redis do |conn|
conn.multi do
conn.zadd('dead', now, payload)
conn.zremrangebyscore('dead', '-inf', now - DeadSet::TIMEOUT)
conn.zremrangebyrank('dead', 0, -DeadSet::MAX_JOBS)
conn.zremrangebyscore('dead', '-inf', now - DeadSet.timeout)
conn.zremrangebyrank('dead', 0, -DeadSet.max_jobs)
end
end
end
Expand Down

0 comments on commit b9c2982

Please sign in to comment.