Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Noah
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Noah
Commits
9448cdee
Commit
9448cdee
authored
Feb 22, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updating examples using DSL
parent
82605a8c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
28 deletions
+33
-28
custom-watcher.rb
examples/custom-watcher.rb
+4
-2
httpclient-server.rb
examples/httpclient-server.rb
+3
-1
httpclient.rb
examples/httpclient.rb
+7
-19
logger.rb
examples/logger.rb
+5
-5
watcher.rb
lib/noah/watcher.rb
+14
-1
No files found.
examples/custom-watcher.rb
View file @
9448cdee
#!/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!
...
...
examples/httpclient-server.rb
View file @
9448cdee
require
'sinatra'
require
'json'
post
'/webhook'
do
p
request
.
body
.
read
x
=
request
.
body
.
read
puts
JSON
.
load
(
x
)
end
examples/httpclient.rb
View file @
9448cdee
#!/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
examples/logger.rb
View file @
9448cdee
#!/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
lib/noah/watcher.rb
View file @
9448cdee
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment