Class: Errplane::Worker
- Inherits:
-
Object
- Object
- Errplane::Worker
- Extended by:
- Logger
- Defined in:
- lib/errplane/worker.rb
Constant Summary collapse
- MAX_POST_POINTS =
200
- MAX_TIME_SERIES_NAME_LENGTH =
255
Constants included from Logger
Class Method Summary collapse
- .check_background_queue(thread_num = 0) ⇒ Object
- .current_thread_count ⇒ Object
- .current_threads ⇒ Object
- .post_data(data) ⇒ Object
- .spawn_threads ⇒ Object
Class Method Details
.check_background_queue(thread_num = 0) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/errplane/worker.rb', line 55 def check_background_queue(thread_num = 0) log :debug, "Checking background queue on thread #{thread_num} (#{current_threads.count} active)" begin data = [] while data.size < MAX_POST_POINTS && !Errplane.queue.empty? p = Errplane.queue.pop(true) rescue next; log :debug, "Found data in the queue! (#{p[:n]})" begin if p[:n].size > MAX_TIME_SERIES_NAME_LENGTH log :error, "Time series name too long! Discarding data for: #{p[:n]}" else data.push p end rescue => e log :info, "Instrumentation Error! #{e.inspect} #{e.backtrace.first}" end end post_data(data) unless data.empty? end while Errplane.queue.length > MAX_POST_POINTS end |
.current_thread_count ⇒ Object
31 32 33 |
# File 'lib/errplane/worker.rb', line 31 def current_thread_count() Thread.list.count {|t| t[:errplane]} end |
.current_threads ⇒ Object
27 28 29 |
# File 'lib/errplane/worker.rb', line 27 def current_threads() Thread.list.select {|t| t[:errplane]} end |
.post_data(data) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/errplane/worker.rb', line 14 def post_data(data) if Errplane.configuration.ignore_current_environment? log :debug, "Current environment is ignored, skipping POST." return false else begin Errplane.api.post(data) rescue => e log :error, "Error calling API: #{e.inspect}" end end end |
.spawn_threads ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/errplane/worker.rb', line 35 def spawn_threads() Errplane.configuration.queue_worker_threads.times do |thread_num| log :debug, "Spawning background worker thread #{thread_num}." Thread.new do Thread.current[:errplane] = true at_exit do log :debug, "Thread exiting, flushing queue." check_background_queue(thread_num) until Errplane.queue.empty? end while true sleep Errplane.configuration.queue_worker_polling_interval check_background_queue(thread_num) end end end end |