0.0
No commit activity in last 3 years
No release in over 3 years
Serf event handler for ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0
 Project Readme

serf_handler

Build Status

Serf is a cluster orchestration framework which developed by HashiCorp. Serf allows you to execute your scripts when serf event occurs. You can simply extend SerfHandler and process serf events. Serf_handler is a very simple Ruby framework with no dependencies. I have a lot in reference to this code.

how to install

gem install serf_handler

how to use

#!/usr/bin/env ruby
require 'serf_handler'

class MyEventHandler < SerfHandler
  def initialize
    # if logfile not specified, log outputs to STDOUT.
    super("/path/to/logfile")
  end
  
  # called by SerfHandlerProxy when member-join event occurs
  def member_join
    info "start processing member-join event"
    # other methods to write log: warn, error
    
    # write your code
  end
  
  # called by SerfHandlerProxy when your custome event occurs
  def your_custome_event
    info "start processing custom event"
    # other methods to write log: warn, error

    # write your code
  end
  
  # called by SerfHandlerProxy when you issue custom query
  # ex. serf query your_query_name "PAYLOAD"
  def your_query_name
    # write your code
    
    reponse("query reponse message you want to return")
    # if reponse message exceeds 1024 bytes limitation,
    # SerfHandler returns "message exceeds limit of 1024 bytes." to serf query client.
    # if you implement the methods for queries,
    # you have to set logfile.
    # serf query command returns output of stdout/stderr.
  end
end

if __FILE__ == $0
  handler = SerfHandlerProxy.new
  handler.register('MyRole', MyEventHandler.new)
  # another code
  # handler.regiter('default', MyEventHandler.new)
  handler.run
end

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