Kahuna

A gem for handling Serf events.

(ka-hoo-na) Hawaiian tern for a man that surfs usually with a degree of skill. from rippinh2o.com

Installation

Add this line to your application's Gemfile:

gem 'kahuna'

And then execute:

$ bundle

Or install it yourself as:

$ gem install kahuna

Example Usage

Create a file named handler like the file below.

#!/usr/bin/env ruby

require 'kahuna'

data = ''
while line = Readline.readline('', true)
  data += line
end

Kahuna::Handler.new(data) do |event, members|
  # Code to execute in response to event
end.execute

exit 0

Make the file executable

$ chmod +x handler

Then pass the file to serf as a handler.

serf agent -event-handler ./handler

Event and Members

Kahuna::Handler yields Kahuna::Event and Kahuna::MemberCollection objects to the block passed to new. The Event object contains all the information about the event parsed from the data sent from Serf and the ENV vars set by Serf.

Serf membership events contain information about the members that participated in the Serf event. This information is the payload for the Serf event, but for Serf user events, the payload is arbitrary. In the case of user events, the current implementation yields nil for the members variable.

You can always get to the raw data sent from Serf through the event object, regardless of whether it is a user event or a membership event.

event.raw_data        #=> "deploy all the things!"

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