Commit 9448cdee authored by John E. Vincent's avatar John E. Vincent

updating examples using DSL

parent 82605a8c
#!/usr/bin/env ruby
require './watcher-idea.rb'
Noah::Watcher.watch do
require File.join(File.dirname(__FILE__), '..','lib','noah','watcher')
class StdoutWatcher < Noah::Watcher
redis_host "redis://127.0.0.1:6379/6"
pattern "noah.Noah::Configuration*"
destination Proc.new {|x| puts x}
run!
......
require 'sinatra'
require 'json'
post '/webhook' do
p request.body.read
x = request.body.read
puts JSON.load(x)
end
#!/usr/bin/env ruby
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
require 'rubygems'
require 'em-hiredis'
require 'em-http-request'
EventMachine.run do
require File.join(File.dirname(__FILE__), '..','lib','noah','watcher')
require 'excon'
# Passing messages...like a boss
@channel = EventMachine::Channel.new
r = EventMachine::Hiredis::Client.connect
r.psubscribe("noah.*")
r.on(:pmessage) do |pattern, event, message|
puts "Got message for #{event}"
@channel.push "#{message}"
end
request = EventMachine::HttpRequest.new('http://localhost:4567/webhook')
sub = @channel.subscribe { |msg|
http = request.post(:body => msg, :head => {"Content-Type" => "application/json"})
}
class HttpPostWatch < Noah::Watcher
redis_host "redis://127.0.0.1:6379/1"
pattern "noah.Noah::Configuration*"
destination Proc.new {|x| ::Excon.post("http://localhost:4567/webhook", :headers => {"Content-Type" => "application/json"}, :body => x)}
run!
end
#!/usr/bin/env ruby
require './watcher-idea.rb'
require 'logger'
log = Logger.new(STDOUT)
require File.join(File.dirname(__FILE__), '..','lib','noah','watcher')
require 'logger'
Noah::Watcher.watch do
class LoggingWatcher < Noah::Watcher
redis_host "redis://127.0.0.1:6379/5"
pattern "noah.Noah::Application*"
destination Proc.new {|x| log.debug(x)}
destination Proc.new {|x| log = Logger.new(STDOUT); log.debug(x)}
run!
end
require 'eventmachine'
require 'uri'
require 'logger'
@log = Logger.new(STDOUT)
@log.level = Logger::DEBUG
require File.join(File.dirname(__FILE__), 'passthrough')
require File.join(File.dirname(__FILE__), '..','vendor','em-hiredis','lib','em-hiredis')
......@@ -42,17 +46,26 @@ module Noah
private
def self.run_watcher(dest)
log = Logger.new(STDOUT)
log.level = Logger::INFO
log.debug "#{dest.inspect}"
redis_url = URI.parse(@my_redis)
db = redis_url.path.gsub(/\//,'')
EventMachine.run do
trap("TERM") { log.info "Killed"; EventMachine.stop }
trap("INT") { log.info "Interrupted"; EventMachine.stop }
channel = EventMachine::Channel.new
r = EventMachine::Hiredis::Client.connect(redis_url.host, redis_url.port)
log.info "Binding to pattern #{db}:#{@my_pattern}"
r.psubscribe("#{db}:#{@my_pattern}")
r.on(:pmessage) do |pattern, event, message|
log.debug "Got message"
channel.push "#{message}"
end
r.errback { log.info "Something went tango-uniform"; EventMachine.stop }
sub = channel.subscribe {|msg| dest.call(msg)}
sub = channel.subscribe {|msg| log.info "Calling message handler"; dest.call(msg)}
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment