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
59d284c9
Commit
59d284c9
authored
Mar 06, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
watcher examples may be broken but tests pass
parent
f7e41c63
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
17 additions
and
69 deletions
+17
-69
custom-watcher.rb
examples/custom-watcher.rb
+1
-1
httpclient.rb
examples/httpclient.rb
+2
-2
httpclient2.rb
examples/httpclient2.rb
+7
-7
logger.rb
examples/logger.rb
+1
-1
reconfiguring-sinatra-watcher.rb
examples/reconfiguring-sinatra-watcher.rb
+1
-1
watcher-idea.rb
examples/watcher-idea.rb
+0
-49
models.rb
lib/noah/models.rb
+3
-6
watcher.rb
lib/noah/watcher.rb
+2
-2
No files found.
examples/custom-watcher.rb
View file @
59d284c9
...
...
@@ -4,7 +4,7 @@ require File.join(File.dirname(__FILE__), '..','lib','noah','watcher')
class
StdoutWatcher
<
Noah
::
Watcher
redis_host
"redis://127.0.0.1:6379/0"
pattern
"//noah/configuration/redis_server
.*
"
pattern
"//noah/configuration/redis_server"
destination
Proc
.
new
{
|
x
|
puts
x
}
run!
end
examples/httpclient.rb
View file @
59d284c9
...
...
@@ -5,8 +5,8 @@ require 'excon'
class
HttpPostWatch
<
Noah
::
Watcher
redis_host
"redis://127.0.0.1:6379/
1
"
pattern
"//noah/configuration
/*
"
redis_host
"redis://127.0.0.1:6379/
0
"
pattern
"//noah/configuration"
destination
Proc
.
new
{
|
x
|
::
Excon
.
post
(
"http://localhost:4567/webhook"
,
:headers
=>
{
"Content-Type"
=>
"application/json"
},
:body
=>
x
)}
run!
end
examples/httpclient2.rb
View file @
59d284c9
...
...
@@ -12,16 +12,16 @@ a.valid?
a
.
save
a
.
watch!
:endpoint
=>
'http://localhost:4567/webhook'
# Boom headshot
pp
Noah
::
Watcher
.
find
(
:pattern
=>
"
noah.application.my_kickass_application.*
"
).
first
# Default watch pattern is '
noah.model.name.*
'
pp
Noah
::
Watcher
.
find
(
:pattern
=>
"
//noah/application/my_kickass_application
"
).
first
# Default watch pattern is '
//noah/model/name
'
# You can also register a new watch with a custom pattern
b
=
Noah
::
Applic
ation
.
new
b
.
name
=
"my_
other_awesome_app
"
# You can also register a new watch with a custom pattern
- kind of pointless obviously
b
=
Noah
::
Configur
ation
.
new
b
.
name
=
"my_
awesome_configuration
"
b
.
valid?
b
.
save
b
.
watch!
:endpoint
=>
'http://localhost:4567/webhook'
,
:pattern
=>
'
delete
'
pp
Noah
::
Watcher
.
find
(
:pattern
=>
"
noah.application.my_other_awesome_app.delete
"
).
first
b
.
watch!
:endpoint
=>
'http://localhost:4567/webhook'
,
:pattern
=>
'
//noah/configuration/my_awesome_configuration
'
pp
Noah
::
Watcher
.
find
(
:pattern
=>
"
//noah/configuration/my_awesome_configuration
"
).
first
# There's now a watcher for pattern 'noah.application.my_other_awesome_app.delete'
# The idea now is that some background watcher agent will pick up on these registered watches
...
...
examples/logger.rb
View file @
59d284c9
...
...
@@ -5,7 +5,7 @@ require 'logger'
class
LoggingWatcher
<
Noah
::
Watcher
redis_host
"redis://127.0.0.1:6379/5"
pattern
"//noah/application
/*
"
pattern
"//noah/application"
destination
Proc
.
new
{
|
x
|
log
=
Logger
.
new
(
STDOUT
);
log
.
debug
(
x
)}
run!
end
examples/reconfiguring-sinatra-watcher.rb
View file @
59d284c9
...
...
@@ -5,7 +5,7 @@ require 'excon'
class
HttpPostWatch
<
Noah
::
Watcher
redis_host
"redis://127.0.0.1:6379/0"
pattern
"//noah/configuration/redis_server
.update
"
pattern
"//noah/configuration/redis_server"
destination
Proc
.
new
{
|
x
|
puts
x
;
::
Excon
.
put
(
"http://localhost:4567/webhook"
,
:headers
=>
{
"Content-Type"
=>
"application/json"
},
:body
=>
x
)}
run!
end
examples/watcher-idea.rb
deleted
100644 → 0
View file @
f7e41c63
require
'rubygems'
require
'logger'
require
'eventmachine'
require
'em-hiredis'
module
Noah
class
Watcher
attr_accessor
:my_pattern
,
:my_destination
def
self
.
watch
(
&
blk
)
watcher
=
Noah
::
Watcher
.
new
watcher
.
instance_eval
(
&
blk
)
watcher
end
def
pattern
(
pattern
)
@my_pattern
=
pattern
end
def
destination
(
destination
)
@my_destination
=
destination
end
def
run!
@my_destination
.
nil?
?
(
puts
"Can't run without a destination"
)
:
run_watcher
(
@my_destination
)
end
private
def
run_watcher
(
dest
)
watcher_log
=
Logger
.
new
(
STDOUT
)
EventMachine
.
run
do
watcher_log
.
info
(
"Starting Noah Watcher..."
)
watcher_log
.
info
(
"Filtering on messages:
#{
@my_pattern
}
"
)
channel
=
EventMachine
::
Channel
.
new
r
=
EventMachine
::
Hiredis
::
Client
.
connect
r
.
db
(
5
)
r
.
psubscribe
(
@my_pattern
)
r
.
on
(
:pmessage
)
do
|
pattern
,
event
,
message
|
channel
.
push
"
#{
message
}
"
end
sub
=
channel
.
subscribe
{
|
msg
|
dest
.
call
(
msg
)}
end
end
end
end
lib/noah/models.rb
View file @
59d284c9
...
...
@@ -27,12 +27,9 @@ module Noah
def
watch!
(
opts
=
{
:endpoint
=>
nil
,
:pattern
=>
nil
})
# TODO: There's still a condition here for duplicate watches
# i.e. User already has a wildcard for that endpoint and adds a more narrow scope
# need to handle that either here or in the watcher class
base_pattern
=
"
#{
self
.
patternize_me
}
."
base_pattern
=
"
#{
self
.
patternize_me
}
"
opts
[
:endpoint
].
nil?
?
(
raise
ArgumentError
,
"Need an endpoint"
)
:
endpoint
=
opts
[
:endpoint
]
opts
[
:pattern
].
nil?
?
pattern
=
base_pattern
+
"*"
:
pattern
=
base_pattern
+
opts
[
:pattern
]
opts
[
:pattern
].
nil?
?
pattern
=
base_pattern
:
pattern
=
opts
[
:pattern
]
begin
w
=
Watcher
.
new
:pattern
=>
pattern
,
:endpoint
=>
endpoint
...
...
@@ -45,7 +42,7 @@ module Noah
protected
def
patternize_me
"//noah/
#{
self
.
class_to_lower
}
/
#{
name
.
gsub
(
/^\//
,
''
)
}
"
"//noah/
#{
self
.
class_to_lower
}
/
#{
name
}
"
end
def
stash_name
...
...
lib/noah/watcher.rb
View file @
59d284c9
...
...
@@ -25,7 +25,7 @@ module Noah
def
initialize
@my_redis
||=
ENV
[
'REDIS_URL'
]
@my_pattern
||=
'
noah.*
'
@my_pattern
||=
'
//noah
'
end
def
self
.
redis_host
(
host
)
...
...
@@ -60,7 +60,7 @@ module Noah
# Pulling out dbnum for now. Need to rethink it
#log.info "Binding to pattern #{db}:#{@my_pattern}"
log
.
info
"Binding to pattern
#{
@my_pattern
}
"
r
.
psubscribe
(
"
#{
@my_pattern
}
"
)
r
.
psubscribe
(
"
#{
@my_pattern
}
*
"
)
r
.
on
(
:pmessage
)
do
|
pattern
,
event
,
message
|
log
.
debug
"Got message"
channel
.
push
"
#{
message
}
"
...
...
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