Class: RateLimit::Worker
- Inherits:
-
Object
- Object
- RateLimit::Worker
- Includes:
- Throttler
- Defined in:
- lib/rate_limit/worker.rb
Instance Attribute Summary collapse
-
#exceeded_window ⇒ Object
Returns the value of attribute exceeded_window.
-
#limits ⇒ Object
Returns the value of attribute limits.
-
#only_failures ⇒ Object
Returns the value of attribute only_failures.
-
#raise_errors ⇒ Object
Returns the value of attribute raise_errors.
-
#result ⇒ Object
Returns the value of attribute result.
-
#topic ⇒ Object
Returns the value of attribute topic.
-
#value ⇒ Object
Returns the value of attribute value.
-
#windows ⇒ Object
Returns the value of attribute windows.
Instance Method Summary collapse
- #clear_cache_counter ⇒ Object
- #failure! ⇒ Object
- #increment_cache_counter ⇒ Object
-
#initialize(topic:, value:, raise_errors: false, only_failures: false) ⇒ Worker
constructor
A new instance of Worker.
- #limit_exceeded? ⇒ Boolean
- #reloaded_limit_exceeded? ⇒ Boolean
- #success!(skip_increment_cache: false) ⇒ Object
Methods included from Throttler
Constructor Details
#initialize(topic:, value:, raise_errors: false, only_failures: false) ⇒ Worker
Returns a new instance of Worker.
9 10 11 12 13 14 15 16 |
# File 'lib/rate_limit/worker.rb', line 9 def initialize(topic:, value:, raise_errors: false, only_failures: false) @topic = topic.to_s @value = value.to_s @windows = Window.find_all(worker: self, topic: @topic) @result = Result.new(topic: @topic, value: @value) @raise_errors = raise_errors @only_failures = only_failures end |
Instance Attribute Details
#exceeded_window ⇒ Object
Returns the value of attribute exceeded_window.
7 8 9 |
# File 'lib/rate_limit/worker.rb', line 7 def exceeded_window @exceeded_window end |
#limits ⇒ Object
Returns the value of attribute limits.
7 8 9 |
# File 'lib/rate_limit/worker.rb', line 7 def limits @limits end |
#only_failures ⇒ Object
Returns the value of attribute only_failures.
7 8 9 |
# File 'lib/rate_limit/worker.rb', line 7 def only_failures @only_failures end |
#raise_errors ⇒ Object
Returns the value of attribute raise_errors.
7 8 9 |
# File 'lib/rate_limit/worker.rb', line 7 def raise_errors @raise_errors end |
#result ⇒ Object
Returns the value of attribute result.
7 8 9 |
# File 'lib/rate_limit/worker.rb', line 7 def result @result end |
#topic ⇒ Object
Returns the value of attribute topic.
7 8 9 |
# File 'lib/rate_limit/worker.rb', line 7 def topic @topic end |
#value ⇒ Object
Returns the value of attribute value.
7 8 9 |
# File 'lib/rate_limit/worker.rb', line 7 def value @value end |
#windows ⇒ Object
Returns the value of attribute windows.
7 8 9 |
# File 'lib/rate_limit/worker.rb', line 7 def windows @windows end |
Instance Method Details
#clear_cache_counter ⇒ Object
22 23 24 |
# File 'lib/rate_limit/worker.rb', line 22 def clear_cache_counter Window.clear_cache_counter(windows) end |
#failure! ⇒ Object
42 43 44 45 46 47 |
# File 'lib/rate_limit/worker.rb', line 42 def failure! result.failure!(self) RateLimit.config.failure_callback(result) raise Errors::LimitExceededError, result if raise_errors end |
#increment_cache_counter ⇒ Object
18 19 20 |
# File 'lib/rate_limit/worker.rb', line 18 def increment_cache_counter Window.increment_cache_counter(windows) end |
#limit_exceeded? ⇒ Boolean
32 33 34 |
# File 'lib/rate_limit/worker.rb', line 32 def limit_exceeded? exceeded_window.present? end |
#reloaded_limit_exceeded? ⇒ Boolean
26 27 28 29 30 |
# File 'lib/rate_limit/worker.rb', line 26 def reloaded_limit_exceeded? @exceeded_window = Window.find_exceeded(windows) limit_exceeded? end |