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
4375abb6
Commit
4375abb6
authored
Feb 26, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding a watch! method to all models
parent
a375ff77
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
63 additions
and
11 deletions
+63
-11
custom-watcher.rb
examples/custom-watcher.rb
+1
-1
httpclient.rb
examples/httpclient.rb
+2
-1
httpclient2.rb
examples/httpclient2.rb
+28
-0
logger.rb
examples/logger.rb
+1
-1
reconfiguring-sinatra-watcher.rb
examples/reconfiguring-sinatra-watcher.rb
+1
-1
models.rb
lib/noah/models.rb
+25
-1
watchers.rb
lib/noah/models/watchers.rb
+5
-6
No files found.
examples/custom-watcher.rb
View file @
4375abb6
...
...
@@ -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.
Noah::C
onfiguration.redis_server.update"
pattern
"noah.
c
onfiguration.redis_server.update"
destination
Proc
.
new
{
|
x
|
puts
x
}
run!
end
examples/httpclient.rb
View file @
4375abb6
...
...
@@ -3,9 +3,10 @@
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
,
'lib'
,
'noah'
,
'watcher'
)
require
'excon'
class
HttpPostWatch
<
Noah
::
Watcher
redis_host
"redis://127.0.0.1:6379/1"
pattern
"noah.
Noah::Configuration
*"
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
0 → 100755
View file @
4375abb6
#!/usr/bin/env ruby
require
'pp'
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
,
'lib'
,
'noah.rb'
)
# This doesn't actually send watch notifications
# but it shows how you could register a new watch
# for the agents to handle
a
=
Noah
::
Application
.
new
a
.
name
=
"my_kickass_application"
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.*'
# You can also register a new watch with a custom pattern
b
=
Noah
::
Application
.
new
b
.
name
=
"my_other_awesome_app"
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
# 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
# See https://github.com/lusis/Noah/wiki/Watcher-Braindump
examples/logger.rb
View file @
4375abb6
...
...
@@ -5,7 +5,7 @@ require 'logger'
class
LoggingWatcher
<
Noah
::
Watcher
redis_host
"redis://127.0.0.1:6379/5"
pattern
"noah.
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 @
4375abb6
...
...
@@ -5,7 +5,7 @@ require 'excon'
class
HttpPostWatch
<
Noah
::
Watcher
redis_host
"redis://127.0.0.1:6379/0"
pattern
"noah.
Noah::C
onfiguration.redis_server.update"
pattern
"noah.
c
onfiguration.redis_server.update"
destination
Proc
.
new
{
|
x
|
puts
x
;
::
Excon
.
put
(
"http://localhost:4567/webhook"
,
:headers
=>
{
"Content-Type"
=>
"application/json"
},
:body
=>
x
)}
run!
end
lib/noah/models.rb
View file @
4375abb6
...
...
@@ -24,11 +24,35 @@ module Noah
self
.
created_at
==
self
.
updated_at
end
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
}
."
opts
[
:endpoint
].
nil?
?
(
raise
ArgumentError
,
"Need an endpoint"
)
:
endpoint
=
opts
[
:endpoint
]
opts
[
:pattern
].
nil?
?
pattern
=
base_pattern
+
"*"
:
pattern
=
base_pattern
+
opts
[
:pattern
]
begin
w
=
Watcher
.
new
:pattern
=>
pattern
,
:endpoint
=>
endpoint
w
.
valid?
?
w
.
save
:
(
raise
"
#{
w
.
errors
}
"
)
w
.
name
rescue
Exception
=>
e
e
.
message
end
end
protected
def
patternize_me
"noah.
#{
self
.
class_to_lower
}
.
#{
name
}
"
end
def
stash_name
@deleted_name
=
self
.
name
end
def
class_to_lower
self
.
class
.
to_s
.
gsub
(
/(.*)::(\w)/
,
'\2'
).
downcase
end
def
dbnum
o
=
Ohm
.
options
.
first
return
"0"
if
o
.
nil?
...
...
@@ -43,7 +67,7 @@ module Noah
self
.
name
.
nil?
?
name
=
@deleted_name
:
name
=
self
.
name
# Pulling out dbnum for now. Need to rethink it
#pub_category = "#{db}:noah.#{self.class.to_s}[#{name}].#{meth}"
pub_category
=
"
noah.
#{
self
.
class
.
to_s
}
.
#{
na
me
}
.
#{
meth
}
"
pub_category
=
"
#{
self
.
patternize_
me
}
.
#{
meth
}
"
Ohm
.
redis
.
publish
(
pub_category
,
self
.
to_hash
.
merge
({
"action"
=>
meth
,
"pubcategory"
=>
pub_category
}).
to_json
)
# self.method_defined? "#{meth}_hook".to_sym
end
...
...
lib/noah/models/watchers.rb
View file @
4375abb6
...
...
@@ -4,28 +4,27 @@ module Noah
# Don't trust anything in here yet
# I'm still trying a few things
attribute
:client
attribute
:pattern
attribute
:endpoint
index
:client
index
:pattern
index
:endpoint
def
validate
super
assert_present
:client
assert_present
:endpoint
assert_present
:pattern
assert_unique
[
:
client
,
:
endpoint
,
:pattern
]
assert_unique
[
:endpoint
,
:pattern
]
end
def
name
@name
=
Digest
::
SHA1
.
hexdigest
"
#{
client
}#{
endpoint
}#{
pattern
}
"
@name
=
Digest
::
SHA1
.
hexdigest
"
#{
endpoint
}#{
pattern
}
"
end
private
def
path_to_pattern
# Not sure about these next two.
# Could get around patterns changing due to namespace changes
def
path_to_pattern
end
def
pattern_to_path
...
...
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