Project

porcupine

0.01
No commit activity in last 3 years
No release in over 3 years
JRuby wrapper for Hystrix
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
~> 2.0

Runtime

 Project Readme

Porcupine

Porcupine is a JRuby wrapper for Netflix's Hystrix library. It simplifies instantiating HystrixCommands and throws Ruby exceptions for most things that can go wrong (execution failures, timeouts, short circuits, no threads in the thread pool).

Installation

Add this line to your application's Gemfile:

gem 'porcupine'

And then execute:

$ bundle

Or install it yourself as:

$ gem install porcupine

Usage

Instantiate a Porcupine object and give it a name, a group name (optional), a timeout (optional) and a block:

porcupine = Porcupine.new("Sleeping Beauty", "Disney Characters", 10_000) { sleep(50) }

You can also provide a Setter directly:

setter = com.netflix.hystrix.HystrixCommand::Setter.withGroupKey(com.netflix.hystrix.HystrixCommandGroupKey::Factory.asKey("Disney Characters"))
                                                   .andCommandKey(com.netflix.hystrix.HystrixCommandKey::Factory.asKey("Sleeping Beauty"))
porcupine = Porcupine.new(setter) { sleep(50) }

Then either you can request a result immediately:

porcupine.execute

Or retrieve a Future and get the result later:

future = porcupine.queue
future.get # Blocks on the result

Subscribing to an event is also supported:

observer = porcupine.observe
observer.subscribe { puts "done!" } # Will puts "done!" when finished

If you provide an onError function, then the function will receive exceptions raised:

observer = porcupine.observe
on_next  = lambda {|val| puts "All good: #{val}"}
on_error = lambda {|exception| puts "Uh oh: #{exception}"}
observer.subscribe(on_next, on_error)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request