class Resque::Plugins::ResqueCleaner::Limiter
Through the Limiter class, you accesses only the last x(default 1000) jobs.
Attributes
maximum[RW]
Public Class Methods
new(cleaner)
click to toggle source
# File lib/resque_cleaner.rb, line 217 def initialize(cleaner) @cleaner = cleaner @maximum = @@default_maximum @locked = false end
Public Instance Methods
all(index=0,count=1)
click to toggle source
Wraps Resque's all and returns always array.
# File lib/resque_cleaner.rb, line 249 def all(index=0,count=1) jobs = @cleaner.failure.all( index, count) jobs = [] unless jobs jobs = [jobs] unless jobs.is_a?(Array) jobs.each{|j| j.extend FailedJobEx} jobs end
count()
click to toggle source
Returns limited count.
# File lib/resque_cleaner.rb, line 230 def count if @locked @jobs.size else on? ? @maximum : @cleaner.failure.count end end
default_maximum()
click to toggle source
# File lib/resque_cleaner.rb, line 207 def default_maximum @@default_maximum end
default_maximum=(v)
click to toggle source
# File lib/resque_cleaner.rb, line 211 def default_maximum=(v) @@default_maximum = v end
jobs()
click to toggle source
Returns jobs. If numbers of jobs is more than maximum, it returns only the maximum.
# File lib/resque_cleaner.rb, line 240 def jobs if @locked @jobs else all( - count, count) end end
lock() { || ... }
click to toggle source
Assuming new failures pushed while cleaner is dealing with failures, you need to lock the range.
# File lib/resque_cleaner.rb, line 268 def lock old = @locked unless @locked total_count = @cleaner.failure.count if total_count>@maximum @start_index = total_count-@maximum @jobs = all( @start_index, @maximum) else @start_index = 0 @jobs = all( 0, total_count) end end @locked = true yield ensure @locked = old end
on?()
click to toggle source
Returns true if limiter is ON: number of failed jobs is more than maximum value.
# File lib/resque_cleaner.rb, line 225 def on? @cleaner.failure.count > @maximum end
start_index()
click to toggle source
Returns a start index of jobs in :failed list.
# File lib/resque_cleaner.rb, line 258 def start_index if @locked @start_index else on? ? @cleaner.failure.count-@maximum : 0 end end