GithubHelp home page GithubHelp logo

nfedyashev / retryable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from czottmann/retryable

476.0 9.0 36.0 217 KB

Retryable is general-purpose retrying library, written in Ruby, to simplify the task of adding retry behavior to just about anything.

License: MIT License

Ruby 100.00%

retryable's Issues

Readme is confusing regarding sleep vs sleep_method

The default configuration object includes both sleep and sleep_method but the "Sleeping" section shows a lambda being given to sleep: and not sleep_method:

Is that an error in the Sleeping section? (I came here today because it seems that sleep with a lambda used to work but doesn't seem to be working now.

image

Feature: "Reset time" option for tries

Some kind of "reset time" option for tries would be nice.
When this option is set it should reset the tries count back to 0.
Why could this be useful?

I wrote a script that connects to a mysql server, sometimes i need to restart the server, so i wrapped my code with this gem.
When the server is restarting, a exception is raised, then it waits 10 seconds, the server is online again end everything is fine,
except i restart the server multiple times a week then the tries count is reached an the script stops.
but if i could define a timeout after the tries count is resetted this would work perfect.

sorry for my bad english, i hope you can understand what i mean.

Update image version

Hi,

The version 3.0.5 is from 2019.
There are changes being made since then. I am interested specifically the ruby compatibility for the v3.1 and v3.2 that was done in Jan 2023.
Are those changes inside of 3.0.5 version? Do you plan on releasing a new image version?

Thanks!

Force-trigger exception/retry

Is there a way to force an exception that Retryable would pick up?
I'm trying to retry if HTTParty response.code is not a 200 or 204. I can get it to raise, but that goes to my begin/rescue, and skips out of Retryable's logic.

def httpPost(results, url = @url)
    #ensure_cb = Proc.new { |retries| puts "Total Retries: #{retries}" }
    exception_cb = Proc.new { |exception| puts "For URL: #{url}\nRetry-rescued error: #{exception.inspect}"}
    begin
      Retryable.retryable(:exception_cb => exception_cb, tries: 10, sleep: lambda { |n| 4**n }, on: [Errno::ECONNREFUSED, SocketError, Net::ReadTimeout, HTTParty::Error, Timeout::Error, Errno::EPIPE, OpenSSL::SSL::SSLError, EOFError]) do |retries, exception|
        response = HTTParty.post(url, body: results.to_json, headers: {'Content-Type' => 'application/json', 'User-Agent' => 'SendGrid 1.0'})
        puts "Attempt #{retries} failed with exception: #{exception}" if retries > 0
        exception if not [200, 204].include?(response.code) #throw http-code-level error if not a 200 or 204
        puts "Total Attempts: #{retries + 1}" if retries > 0
        return response
      end
    rescue StandardError => e
      puts "#{Time.now} - httpPost error: #{e.inspect}"
    end
  end

constant ::TimeoutError is deprecated

All references to TimeoutError should be changed to Timeout::Error, at least for Ruby versions newer than 2.3. It seems that TimeoutError was deprecated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.