Class: Reporter

Inherits:
Runnable show all
Defined in:
lib/s3-object-processor.rb

Defined Under Namespace

Classes: Report

Instance Method Summary collapse

Methods inherited from Runnable

#on_finish

Constructor Details

#initialize(queue_size, &callback) ⇒ Reporter

Returns a new instance of Reporter.



164
165
166
167
168
169
170
171
172
# File 'lib/s3-object-processor.rb', line 164

def initialize(queue_size, &callback)
	@report_queue = SizedQueue.new(queue_size)
	@processor = callback

	on_finish do
		# flush thread waiting on queue
		@report_queue.max = 999999
	end
end

Instance Method Details

#each(&callback) ⇒ Object



183
184
185
# File 'lib/s3-object-processor.rb', line 183

def each(&callback)
	@sink = callback
end

#joinObject



197
198
199
200
# File 'lib/s3-object-processor.rb', line 197

def join
	@report_queue << :end
	super
end

#report(key, value) ⇒ Object



187
188
189
# File 'lib/s3-object-processor.rb', line 187

def report(key, value)
	@report_queue << [key, value]
end

#runObject



174
175
176
177
178
179
180
181
# File 'lib/s3-object-processor.rb', line 174

def run
	super do
		@processor.call(self) if @processor
		until (report = @report_queue.pop) == :end
			@sink.call(*report) if @sink
		end
	end
end

#time(key) ⇒ Object



191
192
193
194
195
# File 'lib/s3-object-processor.rb', line 191

def time(key)
	time = Time.now.to_f
	yield
	report key, Time.now.to_f - time
end