Ruby/Watchcat

What is Ruby/Watchcat?

Ruby/Watchcat is an extension for the Ruby programming language for the development of watchcatd-aware applications.

Installing Ruby/Watchcat

The first step is to install watchcatd. You also need libwcat to use the C extension. After that, you have two choices:

Install the Ruby extension:

  # gem install ruby-watchcat
  

Install the pure-Ruby library:

  # gem install ruby-watchcat-pure
  

Using Ruby/Watchcat in your scripts

The watchcat API is really simple. The following example scripts should give you a good idea of how to use it:

  require 'watchcat'

  # Create a new cat.
  cat = Watchcat.new :timeout => 10, :signal => 'KILL', :info => 'killing from ruby!'
  loop do
    # Here you do something that could exceed the timeout
    sleep 9 + rand(3) 
    cat.heartbeat # we're still alive
  end
  cat.close # clean the cat's litter box
  
You can also use a block when creating a new cat:
  require 'watchcat'

  Watchcat.new do |cat|
    loop do
      do_something_that_can_be_slow
      cat.heartbeat
    end
  end
  # The cat cleans its own litter box when called with a block.
  

Author

Andre Nathan

License

Ruby/Watchcat is licensed under a MIT-style license.

Download

Ruby gems:

Source tarball:

Dependencies