Sha256: dfad8f0c6d64ffcf69bfaad72818fe61d1791b225984cc8597467c19150d1913
Contents?: true
Size: 1.03 KB
Versions: 24
Compression:
Stored size: 1.03 KB
Contents
module RocketJob class ThrottleDefinition attr_reader :method_name, :filter def initialize(method_name, filter) @method_name = method_name.to_sym @filter = filter end # Returns [true|false] whether the throttle was triggered. def throttled?(job, *args) # Throttle exceeded? # Throttle methods can be private. throttled = if args.size.positive? job.method(method_name).arity.zero? ? job.send(method_name) : job.send(method_name, *args) else job.send(method_name) end return false unless throttled job.logger.debug { "Throttle: #{method_name} has been exceeded." } true end # Returns the filter to apply to the job when the above throttle returns true. def extract_filter(job, *args) return filter.call(job, *args) if filter.is_a?(Proc) if args.size.positive? job.method(filter).arity.zero? ? job.send(filter) : job.send(filter, *args) else job.send(filter) end end end end
Version data entries
24 entries across 24 versions & 1 rubygems