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
95bbba76
Commit
95bbba76
authored
Mar 15, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more modularizing of agents
parent
cd29b035
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
48 deletions
+56
-48
noah-watcher.rb
bin/noah-watcher.rb
+3
-48
agent.rb
lib/noah/agent.rb
+53
-0
No files found.
bin/noah-watcher.rb
View file @
95bbba76
...
...
@@ -12,8 +12,7 @@ begin
require
'eventmachine'
require
'em-http-request'
require
'noah'
require
'noah/agents/http_agent'
require
'noah/agents/dummy_agent'
require
'noah/agent'
require
'json'
rescue
LoadError
puts
HELP
...
...
@@ -22,57 +21,13 @@ end
LOGGER
=
Logger
.
new
(
STDOUT
)
class
EventMachine
::
NoahAgent
include
EM
::
Deferrable
Noah
::
Agents
::
HttpAgent
.
register
Noah
::
Agents
::
DummyAgent
.
register
@@watchers
=
Noah
::
Watcher
.
watch_list
@@agents
=
Noah
::
Watchers
.
agents
def
initialize
@logger
=
LOGGER
@logger
.
debug
(
"Initializing with
#{
@@watchers
.
size
}
registered watches"
)
@logger
.
debug
(
"
#{
@@agents
}
agents registered"
)
if
EventMachine
.
reactor_running?
self
.
succeed
(
"Succeed callback"
)
else
logger
.
fatal
(
"Must be inside a reactor!"
)
end
end
def
watchers
@@watchers
.
size
end
def
http_worker
@http_worker
end
def
reread_watchers
@logger
.
debug
(
"Found new watches"
)
@logger
.
debug
(
"Current watch count:
#{
@@watchers
.
size
}
"
)
@@watchers
=
Noah
::
Watcher
.
watch_list
@logger
.
debug
(
"New watch count:
#{
@@watchers
.
size
}
"
)
end
def
broker
(
msg
)
e
,
m
=
msg
.
split
(
"|"
)
be
=
Base64
.
encode64
(
e
).
gsub
(
"
\n
"
,
""
)
EM
::
Iterator
.
new
(
@@agents
).
each
do
|
agent
,
iter
|
agent
.
send
(
:notify
,
e
,
m
,
@@watchers
.
clone
)
iter
.
next
end
end
end
EventMachine
.
run
do
EM
.
error_handler
do
|
e
|
L
ogger
.
new
(
STDOUT
)
.
warn
(
e
)
L
OGGER
.
warn
(
e
)
end
logger
=
LOGGER
trap
(
"INT"
)
{
logger
.
debug
(
"Shutting down. Watches will not be fired"
);
EM
.
stop
}
noah
=
EventMachine
::
Noah
Agent
.
new
noah
=
Noah
::
Agent
.
new
noah
.
errback
{
|
x
|
logger
.
error
(
"Errback:
#{
x
}
"
)}
noah
.
callback
{
|
y
|
logger
.
info
(
"Callback:
#{
y
}
"
)}
# Passing messages...like a boss
...
...
lib/noah/agent.rb
0 → 100644
View file @
95bbba76
$:
.
unshift
(
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
".."
,
"lib"
)))
require
'rubygems'
require
'logger'
require
'noah'
require
'noah/agents/http_agent'
require
'noah/agents/dummy_agent'
module
Noah
class
Agent
include
EM
::
Deferrable
Noah
::
Agents
::
HttpAgent
.
register
Noah
::
Agents
::
DummyAgent
.
register
@@watchers
=
Noah
::
Watcher
.
watch_list
@@agents
=
Noah
::
Watchers
.
agents
def
initialize
@logger
=
LOGGER
@logger
.
debug
(
"Initializing with
#{
@@watchers
.
size
}
registered watches"
)
@logger
.
debug
(
"
#{
@@agents
}
agents registered"
)
if
EventMachine
.
reactor_running?
self
.
succeed
(
"Succeed callback"
)
else
logger
.
fatal
(
"Must be inside a reactor!"
)
end
end
def
watchers
@@watchers
.
size
end
def
http_worker
@http_worker
end
def
reread_watchers
@logger
.
debug
(
"Found new watches"
)
@logger
.
debug
(
"Current watch count:
#{
@@watchers
.
size
}
"
)
@@watchers
=
Noah
::
Watcher
.
watch_list
@logger
.
debug
(
"New watch count:
#{
@@watchers
.
size
}
"
)
end
def
broker
(
msg
)
e
,
m
=
msg
.
split
(
"|"
)
be
=
Base64
.
encode64
(
e
).
gsub
(
"
\n
"
,
""
)
EM
::
Iterator
.
new
(
@@agents
).
each
do
|
agent
,
iter
|
agent
.
send
(
:notify
,
e
,
m
,
@@watchers
.
clone
)
iter
.
next
end
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