All Projects β†’ octokit β†’ Octopoller.rb

octokit / Octopoller.rb

Licence: mit
A micro gem for polling and retrying. Perfect for making repeating requests.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Octopoller.rb

Reattempt
🀞 Give your functions another chance
Stars: ✭ 570 (+1800%)
Mutual labels:  retry
Resilience4j
Resilience4j is a fault tolerance library designed for Java8 and functional programming
Stars: ✭ 7,521 (+24970%)
Mutual labels:  retry
Tty Which
Cross-platform implementation of Unix `which` command
Stars: ✭ 11 (-63.33%)
Mutual labels:  ruby-gem
Mobility
Pluggable Ruby translation framework
Stars: ✭ 644 (+2046.67%)
Mutual labels:  ruby-gem
Finite machine
A minimal finite state machine with a straightforward syntax.
Stars: ✭ 772 (+2473.33%)
Mutual labels:  ruby-gem
Luffy
Luffy is a simple resilience and transient-fault handling library
Stars: ✭ 19 (-36.67%)
Mutual labels:  retry
Ransack
Object-based searching.
Stars: ✭ 5,020 (+16633.33%)
Mutual labels:  ruby-gem
Gentleman
Full-featured, plugin-driven, extensible HTTP client toolkit for Go
Stars: ✭ 886 (+2853.33%)
Mutual labels:  retry
Pastebin
Just another Pastebin.com CLI script, but you can even login with your user account.
Stars: ✭ 5 (-83.33%)
Mutual labels:  ruby-gem
Data mining
The Ruby DataMining Gem, is a little collection of several Data-Mining-Algorithms
Stars: ✭ 10 (-66.67%)
Mutual labels:  ruby-gem
Nokogiri
Nokogiri (ι‹Έ) makes it easy and painless to work with XML and HTML from Ruby.
Stars: ✭ 5,748 (+19060%)
Mutual labels:  ruby-gem
Truemail
πŸš€ Configurable framework agnostic plain Ruby πŸ“¨ email validator/verifier. Verify email via Regex, DNS and SMTP. Be sure that email address valid and exists.
Stars: ✭ 717 (+2290%)
Mutual labels:  ruby-gem
Groovehq
Ruby gem for GrooveHQ api
Stars: ✭ 22 (-26.67%)
Mutual labels:  ruby-gem
Stateview
✨ StateView is an invisible, zero-sized View that can be used to lazily inflate loadingView/emptyView/retryView at runtime.
Stars: ✭ 573 (+1810%)
Mutual labels:  retry
Backtrace
Ruby gem to print exception backtrace nicely
Stars: ✭ 14 (-53.33%)
Mutual labels:  ruby-gem
Pastel
Terminal output styling with intuitive and clean API.
Stars: ✭ 569 (+1796.67%)
Mutual labels:  ruby-gem
Omniauth Pge
OmniAuth Strategy for PG&E
Stars: ✭ 6 (-80%)
Mutual labels:  ruby-gem
Zache
Zero-footprint Ruby In-Memory Thread-Safe Cache
Stars: ✭ 30 (+0%)
Mutual labels:  ruby-gem
Devise Jwt
JWT token authentication with devise and rails
Stars: ✭ 881 (+2836.67%)
Mutual labels:  ruby-gem
Gitlab
Ruby wrapper and CLI for the GitLab REST API
Stars: ✭ 939 (+3030%)
Mutual labels:  ruby-gem

Octopoller πŸ¦‘

battle tested.

Build Status

Octopoller is a micro gem for polling and retrying, perfect for making repeating requests.

Octopoller.poll(timeout: 15.seconds) do
  begin
    client.request_progress # ex. request a long running job's status
  rescue Error
    :re_poll
  end
end

# => { "status" => 200,  "body" => "πŸ¦‘" }

About

Octopoller was originally created for the purpose of polling GitHub's Source Imports API for a repo's import status. It is now the backbone of GitHub Classroom's import starter code process.

Installation

Add this line to your application's Gemfile:

gem 'octopoller'

And then execute:

$ bundle

Or install it yourself as:

$ gem install octopoller

Usage

Octopoller exposes a single function poll. Here is what the API looks like:

# Polls until success
# Re-runs when the block returns `:re_poll`
#
# wait      - The time delay in seconds between polls (default is 1 second)
#           - When given the argument `:exponentially` the action will be retried with exponetial backoff
# timeout   - The maximum number of seconds the poller will execute
# retries   - The maximum number of times the action will be retried
# yield     - A block that will execute, and if `:re_poll` is returned it will re-run
#           - Re-runs until something is returned or the timeout/retries is reached
# raise     - Raises an Octopoller::TimeoutError if the timeout is reached
# raise     - Raises an Octopoller::TooManyAttemptsError if the retries is reached
#
def poll(wait: 1.second, timeout: nil, retries: nil)
  ...

Octopoller has 3 use cases:

  • Poll something with a set timeout
  • Poll something with a set number of retries
  • Poll something with exponential backoff

Here's what using Octpoller is like for each of the use cases listed above:

  • Poll with a timeout:

    Octopoller.poll(timeout: 15.seconds) do
      puts "πŸ¦‘"
      :re_poll
    end
    
    # => "πŸ¦‘"
    # => "πŸ¦‘"
    # ... (for 15 seconds)
    # Timed out patiently (Octopoller::TimeOutError)
    
  • Poll with retries:

    Octopoller.poll(retries: 2) do
      puts "πŸ¦‘"
      :re_poll
    end
    
    # => "πŸ¦‘"
    # => "πŸ¦‘"
    # => "πŸ¦‘"
    # Tried maximum number of attempts (Octopoller::TooManyAttemptsError)
    
  • Poll with exponential backoff:

    start = Time.now
    Octopoller.poll(wait: :exponentially, retries: 4) do
      puts Time.now - start
      :re_poll
    end
    
    # => 0.5 seconds
    # => 1 second
    # => 2 seconds
    # => 4 seconds
    # => 8 seconds
    # Tried maximum number of attempts (Octopoller::TooManyAttemptsError)
    

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/octokit/octopoller.rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Octopoller project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].