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
88e0d993
Commit
88e0d993
authored
Mar 17, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small performance refactor in agent -
https://gist.github.com/875564
parent
d213ead3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
8 deletions
+20
-8
Rakefile
Rakefile
+5
-0
noah-watcher.rb
bin/noah-watcher.rb
+8
-6
agent.rb
lib/noah/agent.rb
+2
-1
http_agent.rb
lib/noah/agents/http_agent.rb
+5
-1
No files found.
Rakefile
View file @
88e0d993
...
...
@@ -127,3 +127,8 @@ end
task
:start_demo
do
puts
"Soon, young padawan"
end
desc
"Start an irb session with all libraries loaded"
task
:shell
do
sh
"irb -r./lib/noah.rb"
end
bin/noah-watcher.rb
View file @
88e0d993
...
...
@@ -20,7 +20,8 @@ rescue LoadError => e
exit
end
LOGGER
=
Logger
.
new
(
STDOUT
)
LOGGER
=
Logger
.
new
(
'rundeck-test.log'
)
#LOGGER = Logger.new(STDOUT)
EventMachine
.
run
do
EM
.
error_handler
do
|
e
|
...
...
@@ -32,7 +33,7 @@ EventMachine.run do
noah
.
errback
{
|
x
|
logger
.
error
(
"Errback:
#{
x
}
"
)}
noah
.
callback
{
|
y
|
logger
.
info
(
"Callback:
#{
y
}
"
)}
# Passing messages...like a boss
master_channel
=
EventMachine
::
Channel
.
new
#
master_channel = EventMachine::Channel.new
r
=
EventMachine
::
Hiredis
::
Client
.
connect
r
.
errback
{
|
x
|
logger
.
error
(
"Unable to connect to redis:
#{
x
}
"
)}
...
...
@@ -40,11 +41,12 @@ EventMachine.run do
r
.
psubscribe
(
"//noah/*"
)
r
.
on
(
:pmessage
)
do
|
pattern
,
event
,
message
|
noah
.
reread_watchers
if
event
=~
/^\/\/noah\/watcher\/.*/
master_channel
.
push
"
#{
event
}
|
#{
message
}
"
noah
.
broker
(
"
#{
event
}
|
#{
message
}
"
)
unless
noah
.
watchers
==
0
#master_channel.push "#{event}|#{message}"
end
sub
=
master_channel
.
subscribe
{
|
msg
|
#
sub = master_channel.subscribe {|msg|
# We short circuit if we have no watchers
noah
.
broker
(
msg
)
unless
noah
.
watchers
==
0
}
#
noah.broker(msg) unless noah.watchers == 0
#
}
end
lib/noah/agent.rb
View file @
88e0d993
...
...
@@ -40,7 +40,8 @@ module Noah
def
broker
(
msg
)
e
,
m
=
msg
.
split
(
"|"
)
be
=
Base64
.
encode64
(
e
).
gsub
(
"
\n
"
,
""
)
# Below isn't being used right now
#be = Base64.encode64(e).gsub("\n","")
EM
::
Iterator
.
new
(
@@agents
).
each
do
|
agent
,
iter
|
agent
.
send
(
:notify
,
e
,
m
,
@@watchers
.
clone
)
iter
.
next
...
...
lib/noah/agents/http_agent.rb
View file @
88e0d993
...
...
@@ -11,9 +11,13 @@ module Noah::Agents
logger
=
LOGGER
logger
.
info
(
"
#{
NAME
}
: Worker initiated"
)
logger
.
debug
(
"
#{
NAME
}
: got event -
#{
event
}
"
)
# TODO
# I can save work by only decoding once.
# This is retarded doing it twice.
# Populate matches with decoded data for chrissakes
matches
=
watch_list
.
find_all
{
|
w
|
event
=~
/^
#{
Base64
.
decode64
(
w
)
}
/
}
logger
.
debug
(
"
#{
PREFIX
}
: Found
#{
matches
.
size
}
possible matches for
#{
event
}
"
)
EM
::
Iterator
.
new
(
matches
).
each
do
|
watch
,
iter
|
EM
::
Iterator
.
new
(
matches
,
100
).
each
do
|
watch
,
iter
|
p
,
ep
=
Base64
.
decode64
(
watch
).
split
(
"|"
)
if
ep
=~
/^
#{
PREFIX
}
/
logger
.
info
(
"
#{
NAME
}
: Sending message to (
#{
ep
}
) for pattern (
#{
p
}
)"
)
...
...
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