Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

monitor emits result of block; some fixes to nook

  • Loading branch information...
commit 1c3820cd187914e03b5010836bb703cda8a67c3f 1 parent fd90ae0
Philip (flip) Kromer mrflip authored
6 examples/server_logs/logline.rb
View
@@ -11,12 +11,6 @@ def page_type
end
end
- def is_page?
- page_type == :page
- end
-
-
-
#
# Regular expression to parse an apache log line.
#
18 examples/server_logs/nook.rb
View
@@ -19,21 +19,27 @@
#
#
class NookMapper < ApacheLogParser
-
# create a Logline object from each record and serialize it flat to disk
def process line
super(line) do |logline|
- # yield logline
- resp = fetcher.get("/your/mom")
- yield [resp.status, resp.body, resp.headers.inspect]
+ start = Time.now
+ resp = fetcher.get(logline.path, :user_agent => logline.ua, :referer => logline.referer)
+ yield [Time.now.to_flat, (Time.now - start).to_f, resp.status, resp.body.size, logline.path, resp.body]
+ end
+ end
+
+ def track record
+ monitor.periodically do |m|
+ m.progress
end
end
# a mock fetcher with a uniformly distributed variable delay
def fetcher
- @fetcher ||= Faraday::Connection.new do |f|
+ @fetcher ||= Faraday::Connection.new(:url => 'http://localhost:80/') do |f|
f.use Faraday::Adapter::Dummy do |dummy|
- dummy.delay = Proc.new{|env| 0.1 + 0.9 * rand() }
+ dummy.delay = Proc.new{|env| 0.05 } # 0.2 * rand()
+ # dummy.body = Proc.new{|env| env[:url] }
end
end
end
4 lib/wukong/periodic_monitor.rb
View
@@ -28,9 +28,9 @@ def periodically *args, &block
if ready?
@last_report = Time.now
if block
- block.call(iter, *args)
+ emit block.call(self, *args)
else
- self.emit progress(*args)
+ emit progress(*args)
end
end
end
6 lib/wukong/streamer/base.rb
View
@@ -28,11 +28,15 @@ def stream
process(*record) do |output_record|
emit output_record
end
- monitor.periodically(record.to_s[0..1000])
+ track(record)
end
after_stream
end
+ def track record
+ monitor.periodically(record.to_s[0..1000])
+ end
+
def each_record &block
$stdin.each(&block)
end
Please sign in to comment.
Something went wrong with that request. Please try again.