Git Product home page Git Product logo

serf_handler's Introduction

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

serf_handler's People

Contributors

konchan avatar

Stargazers

David Collom avatar

Forkers

davidcollom

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.