restaurant-cheetah / take2 Goto Github PK
View Code? Open in Web Editor NEWEasily define Take2 ๐ฌ to retry API calls, methods, or just a block of code.
License: MIT License
Easily define Take2 ๐ฌ to retry API calls, methods, or just a block of code.
License: MIT License
Currently the take2 configurations are class level.
So in order to implement different set of defaults for two different implementations in same class they must be re-declaired.
I would like to be able to set defaults per method call:
class Service
include Take2
# use class defaults
def call
call_api_with_retry do
# code ..
end
end
# use method defaults
def perform
call_api_with_retry(config_hash) do
# more code..
end
end
end
I want to be able to define custom logger for the retry attempts output.
For example:
class Service
include Take2
logger Logger.new('take2.log')
on_retry proc { |error, tries| self.logger.info "#{self.name} - Retrying.. #{tries} of #{self.retriable_configuration[:retries]} (#{error})" }
end
Take2.configure do |config|
config.retries = 3
config.retriable = [
Net::HTTPServerError,
Net::HTTPServerException,
Net::HTTPRetriableError
].freeze
end
class Service
include Take2
class CustomError < StandardError; end
retriable_errors CustomError
end
Service.retriable_configuration
=> {:retries=>3, :retriable=>[Service::CustomError] ....
Desired behaviour:
Service.retriable_configuration
=> {:retries=>3,
:retriable=>[
Net::HTTPServerError,
Net::HTTPServerException,
Net::HTTPRetriableError,
Service::CustomError
] ...
Unable to reset time_to_sleep to decimal or nil.
Expected:
Take2.reset(time_to_sleep: 1.1)
=> #<Take2::Configuration:0x007f9ac0076388 @retries=1, @retriable=[Net::HTTPServerError, Net::HTTPServerException, Net::HTTPRetriableError, Errno::ECONNRESET, IOError], @retry_proc=#<Proc:0x007f9ac00762c0@/Users/antonmagids/.rvm/gems/ruby-2.4.1/gems/take2-0.0.2/lib/take2/configuration.rb:16>, @retry_condition_proc=#<Proc:0x007f9ac0076298@/Users/antonmagids/.rvm/gems/ruby-2.4.1/gems/take2-0.0.2/lib/take2/configuration.rb:17>, @time_to_sleep=1.1>
Take2.reset(time_to_sleep: nil)
=> #<Take2::Configuration:0x007f9ac0076388 @retries=1, @retriable=[Net::HTTPServerError, Net::HTTPServerException, Net::HTTPRetriableError, Errno::ECONNRESET, IOError], @retry_proc=#<Proc:0x007f9ac00762c0@/Users/antonmagids/.rvm/gems/ruby-2.4.1/gems/take2-0.0.2/lib/take2/configuration.rb:16>, @retry_condition_proc=#<Proc:0x007f9ac0076298@/Users/antonmagids/.rvm/gems/ruby-2.4.1/gems/take2-0.0.2/lib/take2/configuration.rb:17>, @time_to_sleep=nil>
Actual:
Take2.reset(time_to_sleep: 1.1)
=> #ArgumentError: time_to_sleep must be positive integer
Take2.reset(time_to_sleep: nil)
=> #ArgumentError: time_to_sleep must be positive integer
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.