Class: Balsamique::Reporter
- Inherits:
-
Object
- Object
- Balsamique::Reporter
- Defined in:
- lib/balsamique/reporter.rb
Instance Attribute Summary collapse
-
#bq ⇒ Object
Returns the value of attribute bq.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#max_retries ⇒ Object
Returns the value of attribute max_retries.
-
#poll ⇒ Object
Returns the value of attribute poll.
-
#stopped ⇒ Object
Returns the value of attribute stopped.
Instance Method Summary collapse
-
#initialize(balsamique, options = {}) ⇒ Reporter
constructor
A new instance of Reporter.
- #job_status(id) ⇒ Object
- #perform(id, job_status, timestamp, retries) ⇒ Object
- #run ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(balsamique, options = {}) ⇒ Reporter
Returns a new instance of Reporter.
6 7 8 9 10 11 |
# File 'lib/balsamique/reporter.rb', line 6 def initialize(balsamique, = {}) @bq = balsamique @poll = .fetch(:poll, 10.0) @max_retries = .fetch(:max_retries, 20) @logger = .fetch(:logger, Logger.new($stdout)) end |
Instance Attribute Details
#bq ⇒ Object
Returns the value of attribute bq.
13 14 15 |
# File 'lib/balsamique/reporter.rb', line 13 def bq @bq end |
#logger ⇒ Object
Returns the value of attribute logger.
13 14 15 |
# File 'lib/balsamique/reporter.rb', line 13 def logger @logger end |
#max_retries ⇒ Object
Returns the value of attribute max_retries.
13 14 15 |
# File 'lib/balsamique/reporter.rb', line 13 def max_retries @max_retries end |
#poll ⇒ Object
Returns the value of attribute poll.
13 14 15 |
# File 'lib/balsamique/reporter.rb', line 13 def poll @poll end |
#stopped ⇒ Object
Returns the value of attribute stopped.
13 14 15 |
# File 'lib/balsamique/reporter.rb', line 13 def stopped @stopped end |
Instance Method Details
#job_status(id) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/balsamique/reporter.rb', line 23 def job_status(id) status = bq.job_status(id) if status[id] bq.fill_job_failures(status) bq.fill_args_tasks(status) end status[id] end |
#perform(id, job_status, timestamp, retries) ⇒ Object
19 20 21 |
# File 'lib/balsamique/reporter.rb', line 19 def perform(id, job_status, , retries) logger.info("#{id} #{} #{retries} #{job_status.to_json}") end |
#run ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/balsamique/reporter.rb', line 32 def run @stopped = false until stopped do report = bq.pop_report(Time.now.to_f) if report id, , retries = report begin if (status = job_status(id)) perform(id, status, , retries) bq.remove_job(id) unless status[:task] else logger.info("#{id} #{} #{retries} null") end bq.complete_report(id) rescue => error logger.warn( "#{id} #{} #{retries} " + "#{error.class.name} #{error.}") logger.debug(error) bq.complete_report(id) if retries > max_retries end else t_poll = Time.now.to_f + poll * (1.0 - 0.5 * rand()) sleep 0.1 until Time.now.to_f > t_poll || stopped end end end |
#stop ⇒ Object
15 16 17 |
# File 'lib/balsamique/reporter.rb', line 15 def stop @stopped = true end |