Class: AppPerfRpm::Worker
- Inherits:
-
Object
- Object
- AppPerfRpm::Worker
- Defined in:
- lib/app_perf_rpm/worker.rb
Instance Method Summary collapse
-
#initialize ⇒ Worker
constructor
A new instance of Worker.
- #save(event) ⇒ Object
- #start ⇒ Object
- #start_dispatcher ⇒ Object
- #worker_running? ⇒ Boolean
Constructor Details
#initialize ⇒ Worker
Returns a new instance of Worker.
3 4 5 6 |
# File 'lib/app_perf_rpm/worker.rb', line 3 def initialize AppPerfRpm.logger.info "Starting worker." @dispatcher = Dispatcher.new end |
Instance Method Details
#save(event) ⇒ Object
8 9 10 11 12 |
# File 'lib/app_perf_rpm/worker.rb', line 8 def save(event) start return if event.nil? @dispatcher.add_event(event) end |
#start ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/app_perf_rpm/worker.rb', line 14 def start return if worker_running? ::AppPerfRpm.mutex.synchronize do return if worker_running? start_dispatcher ::AppPerfRpm.logger.info "Worker is running." end end |
#start_dispatcher ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/app_perf_rpm/worker.rb', line 27 def start_dispatcher @worker_thread = Thread.new do ::AppPerfRpm.configuration.reload @dispatcher.reset loop do start = Time.now if @dispatcher.ready? @dispatcher.dispatch @dispatcher.reset end sleep_for = (start + 15 - Time.now) sleep_for = 1 if sleep_for < 1 sleep sleep_for end end @worker_thread.abort_on_exception = true end |
#worker_running? ⇒ Boolean
23 24 25 |
# File 'lib/app_perf_rpm/worker.rb', line 23 def worker_running? @worker_thread && @worker_thread.alive? end |