Module: ExcessFlow
- Defined in:
- lib/excess_flow.rb,
lib/excess_flow/strategy.rb,
lib/excess_flow/constants.rb,
lib/excess_flow/global_mutex.rb,
lib/excess_flow/configuration.rb,
lib/excess_flow/failed_execution.rb,
lib/excess_flow/redis_connection.rb,
lib/excess_flow/throttled_executor.rb,
lib/excess_flow/configuration_error.rb,
lib/excess_flow/fixed_window_strategy.rb,
lib/excess_flow/throttle_configuration.rb,
lib/excess_flow/sliding_window_strategy.rb,
lib/excess_flow/rate_limited_execution_result.rb
Overview
Copyright 2019 ConvertKit, LLC
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Defined Under Namespace
Modules: RedisConnection Classes: Configuration, ConfigurationError, FailedExecution, FixedWindowStrategy, GlobalMutex, RateLimitedExecutionResult, SlidingWindowStrategy, Strategy, ThrottleConfiguration, ThrottledExecutor
Constant Summary collapse
- CONFIGURATION_ERROR_MESSAGE =
'Invalid arguments provided. Please refer to README.md'- COUNTER_PREFIX =
'excess_flow::counter::'- DEFAULT_CONNECTION_POOL =
100- DEFAULT_CONNECTION_TIMEOUT =
3- DEFAULT_REDIS_URL =
'redis://localhost:6379/1'- LOCK_PREFIX =
'excess_flow::lock::'- MUTEX_LOCK_TIME =
1- MUTEX_SLEEP_TIME =
1 / 100_000
- VERSION =
'1.0.2'
Class Method Summary collapse
-
.configuration ⇒ Configuration
Provides access to cache’s configuration.
-
.configure {|configuration| ... } ⇒ void
API to configure cache dynamically during runtime.
-
.redis {|redis| ... } ⇒ Object
API to communicate with Redis database backing cache up.
-
.redis_connection_pool ⇒ ConnectionPool
Accessor to connection pool.
-
.throttle(args, &block) ⇒ ExcessFlow::RateLimitedExecutionResult
Executes passed in block of code rate limited using specified strategy and arguments.
Class Method Details
.configuration ⇒ Configuration
Provides access to cache’s configuration.
58 59 60 |
# File 'lib/excess_flow.rb', line 58 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ void
This method returns an undefined value.
API to configure cache dynamically during runtime.
71 72 73 74 |
# File 'lib/excess_flow.rb', line 71 def configure yield(configuration) nil end |
.redis {|redis| ... } ⇒ Object
API to communicate with Redis database backing cache up.
84 85 86 87 88 |
# File 'lib/excess_flow.rb', line 84 def redis redis_connection_pool.with do |connection| yield connection end end |
.redis_connection_pool ⇒ ConnectionPool
Accessor to connection pool. Defined on top level so it can be memoized on the topmost level
94 95 96 |
# File 'lib/excess_flow.rb', line 94 def redis_connection_pool @redis_connection_pool ||= ExcessFlow::RedisConnection.connection_pool end |
.throttle(args, &block) ⇒ ExcessFlow::RateLimitedExecutionResult
Executes passed in block of code rate limited using specified strategy and arguments. Different call types can be differentiated and configured using arguments.
118 119 120 |
# File 'lib/excess_flow.rb', line 118 def throttle(args, &block) ExcessFlow::ThrottledExecutor.select_strategy_and_execute(args, &block) end |