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
89005432
Commit
89005432
authored
Feb 23, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
self-reconfiguring Sinatra example
parent
360dea62
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
6 deletions
+53
-6
custom-watcher.rb
examples/custom-watcher.rb
+2
-2
reconfiguring-sinatra-watcher.rb
examples/reconfiguring-sinatra-watcher.rb
+11
-0
reconfiguring-sinatra.rb
examples/reconfiguring-sinatra.rb
+32
-0
models.rb
lib/noah/models.rb
+4
-2
watcher.rb
lib/noah/watcher.rb
+4
-2
No files found.
examples/custom-watcher.rb
View file @
89005432
...
...
@@ -3,8 +3,8 @@
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
*
"
redis_host
"redis://127.0.0.1:6379/
0
"
pattern
"noah.Noah::Configuration
.redis_server.update
"
destination
Proc
.
new
{
|
x
|
puts
x
}
run!
end
examples/reconfiguring-sinatra-watcher.rb
0 → 100755
View file @
89005432
#!/usr/bin/env ruby
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
,
'lib'
,
'noah'
,
'watcher'
)
require
'excon'
class
HttpPostWatch
<
Noah
::
Watcher
redis_host
"redis://127.0.0.1:6379/0"
pattern
"noah.Noah::Configuration.redis_server.update"
destination
Proc
.
new
{
|
x
|
puts
x
;
::
Excon
.
put
(
"http://localhost:4567/webhook"
,
:headers
=>
{
"Content-Type"
=>
"application/json"
},
:body
=>
x
)}
run!
end
examples/reconfiguring-sinatra.rb
0 → 100644
View file @
89005432
require
'sinatra'
require
'ohm'
require
'open-uri'
require
'json'
set
:noah_server
,
'http://localhost:5678'
set
:noah_client_name
,
'my_sinatra_app'
def
get_config_from_noah
(
setting
)
begin
c
=
open
(
"
#{
settings
.
noah_server
}
/c/
#{
settings
.
noah_client_name
}
/
#{
setting
}
"
).
read
set
setting
.
to_sym
,
c
end
end
get_config_from_noah
(
'redis_server'
)
def
get_redis_version
Ohm
.
connect
:url
=>
settings
.
redis_server
Ohm
.
redis
.
info
[
"redis_version"
]
end
get
"/"
do
"Redis version:
#{
get_redis_version
}
"
end
put
"/webhook"
do
data
=
JSON
.
parse
(
request
.
body
.
read
)
settings
.
redis_server
=
data
[
"body"
]
resp
=
{
:message
=>
"reconfigured"
,
:setting
=>
data
[
"name"
],
:body
=>
data
[
"body"
]}.
to_json
"
#{
resp
}
"
end
lib/noah/models.rb
View file @
89005432
...
...
@@ -47,8 +47,10 @@ module Noah
define_method
(
"notify_via_redis_
#{
meth
}
"
.
to_sym
)
do
db
=
self
.
dbnum
self
.
name
.
nil?
?
name
=
@deleted_name
:
name
=
self
.
name
pub_category
=
"
#{
db
}
:noah.
#{
self
.
class
.
to_s
}
[name].
#{
meth
}
"
Ohm
.
redis
.
publish
(
pub_category
,
self
.
to_json
)
# 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
}
.
#{
name
}
.
#{
meth
}
"
Ohm
.
redis
.
publish
(
pub_category
,
self
.
to_hash
.
merge
({
"action"
=>
meth
,
"pubcategory"
=>
pub_category
}).
to_json
)
end
end
end
...
...
lib/noah/watcher.rb
View file @
89005432
...
...
@@ -57,8 +57,10 @@ module Noah
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
}
"
)
# 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
.
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