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
fc74cc71
Commit
fc74cc71
authored
Mar 01, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working through the agent process more
parent
e3fc2cc3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
10 deletions
+32
-10
noah-watcher.rb
bin/noah-watcher.rb
+32
-10
No files found.
bin/noah-watcher.rb
View file @
fc74cc71
...
...
@@ -6,6 +6,7 @@ require 'optparse'
require
'em-hiredis'
require
'thin'
require
'noah'
require
'json'
LOGGER
=
Logger
.
new
(
STDOUT
)
...
...
@@ -20,11 +21,27 @@ class EventMachine::NoahAgent
# Some logic to spawn protocol specific agents
# i.e. http, amqp, xmpp, redis, whatever
if
EventMachine
.
reactor_running?
@http_channel
=
EventMachine
::
Channel
.
new
@redis_channel
=
EventMachine
::
Channel
.
new
@log_channel
=
EventMachine
::
Channel
.
new
@http_worker
=
EM
.
spawn
{
|
msg
,
ep
|
logger
=
LOGGER
logger
.
debug
(
"spawning http processor"
)
logger
.
info
(
"got ep on http worker:
#{
ep
}
"
)
logger
.
info
(
"got msg on http worker:
#{
msg
}
"
)
}
@redis_worker
=
EM
.
spawn
{
|
msg
|
logger
=
LOGGER
logger
.
debug
(
"spawning redis worker"
)
logger
.
info
(
"got msg on redis worker:
#{
msg
}
"
)
}
@log_worker
=
EM
.
spawn
{
|
msg
|
logger
=
LOGGER
logger
.
debug
(
"spawning logger worker:
#{
msg
}
"
)
}
@amqp_worker
=
EM
.
spawn
{
|
msg
|
logger
=
LOGGER
logger
.
debug
(
"spawning amqp worker:
#{
msg
}
"
)
}
else
log
.
fatal
(
"Must be inside a reactor!"
)
log
ger
.
fatal
(
"Must be inside a reactor!"
)
end
end
...
...
@@ -37,11 +54,16 @@ class EventMachine::NoahAgent
@logger
.
debug
(
"Current watch count:
#{
@@watchers
.
size
}
"
)
@@watchers
=
Noah
::
Watchers
.
all
@logger
.
debug
(
"New watch count:
#{
@@watchers
.
size
}
"
)
@logger
.
debug
(
@@watchers
)
end
def
process_message
(
msg
)
def
broker
(
msg
)
# This is just for testing for now
@logger
.
info
(
msg
)
@logger
.
info
(
msg
.
class
)
@logger
.
warn
(
msg
)
e
,
m
=
msg
.
split
(
"
\t
"
)
@http_worker
.
notify
m
,
e
end
end
...
...
@@ -49,18 +71,18 @@ EventMachine.run do
logger
=
LOGGER
noah
=
EventMachine
::
NoahAgent
.
new
# Passing messages...like a boss
channel
=
EventMachine
::
Channel
.
new
master_
channel
=
EventMachine
::
Channel
.
new
r
=
EventMachine
::
Hiredis
::
Client
.
connect
logger
.
debug
(
"Starting up"
)
r
.
psubscribe
(
"//noah/*"
)
r
.
on
(
:pmessage
)
do
|
pattern
,
event
,
message
|
noah
.
reread_watchers
if
event
=~
/^\/\/noah\/watcher\/.*/
channel
.
push
"[
#{
event
}
][
#{
message
}
]
"
master_channel
.
push
"
#{
event
}
\t
#{
message
}
"
logger
.
debug
(
"Publishing [
#{
event
}
]"
)
end
sub
=
channel
.
subscribe
{
|
msg
|
noah
.
process_message
(
msg
)
unless
noah
.
watchers
==
0
sub
=
master_
channel
.
subscribe
{
|
msg
|
noah
.
broker
(
msg
)
unless
noah
.
watchers
==
0
}
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