Sha256: 5fd33bed8ae463e84bbb96b3ba22b5937aa6a5dccb8383a7e3d5419424e66772

Contents?: true

Size: 840 Bytes

Versions: 1

Compression:

Stored size: 840 Bytes

Contents

module Healthety
  extend self

  def workers(&block)
    @workers = []
    @threads = []

    instance_eval(&block)

    start
  end

  def host(host)
    @host = host
  end

  def port(port)
    @port = port
  end

  def worker(name, &block)
    @workers << Worker.new(name, &block)
  end

  def start
    puts message
    transmission = Transmission.new(@host, @port)

    # Catch Ctrl-C and terminate all worker threads.
    trap("INT") { @threads.map(&:kill) }

    @workers.each do |worker|
      @threads << Thread.new do
        loop do
          worker.perform
          transmission.send(worker.name, worker.value, Time.now.utc)
          sleep worker.interval
        end
      end
    end

    @threads.map(&:join)
  end

  def message
    <<-EOM
=> Workers starting to send to #{@host}:#{@port}
=> Ctrl-C to stop
EOM
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
healthety-0.0.2 lib/healthety/healthety.rb