class Sidekiq::Hierarchy::PruningSet
An implementation of WorkflowSet
that auto-prunes by time & size to stay within space constraints. Do not use for workflows that cannot be lost (i.e., are in any state of progress, or require followup)
Public Class Methods
max_workflows()
click to toggle source
# File lib/sidekiq/hierarchy/workflow_set.rb, line 95 def self.max_workflows Sidekiq.options[:dead_max_workflows] || Sidekiq.options[:dead_max_jobs] end
timeout()
click to toggle source
# File lib/sidekiq/hierarchy/workflow_set.rb, line 91 def self.timeout Sidekiq.options[:dead_timeout_in_seconds] end
Public Instance Methods
add(workflow)
click to toggle source
Calls superclass method
Sidekiq::Hierarchy::WorkflowSet#add
# File lib/sidekiq/hierarchy/workflow_set.rb, line 99 def add(workflow) prune super end
prune()
click to toggle source
# File lib/sidekiq/hierarchy/workflow_set.rb, line 104 def prune redis do |conn| conn.multi do conn.zrangebyscore(redis_zkey, '-inf', Time.now.to_f - self.class.timeout) # old workflows conn.zrevrange(redis_zkey, self.class.max_workflows, -1) # excess workflows end.flatten.uniq # take the union of both pruning strategies .tap { |to_remove| conn.zrem(redis_zkey, to_remove) if to_remove.any? } end.each { |jid| Workflow.find_by_jid(jid).delete } end