lib/backburner/allq_wrapper.rb in backburner-allq-1.0.5 vs lib/backburner/allq_wrapper.rb in backburner-allq-1.0.7

- old
+ new

@@ -77,11 +77,11 @@ { 'expireds' => expireds, 'releases' => releases } end end class AllQWrapper - def initialize(url = Blitline::Constants::ALLQ_DEFAULT_EU_URL) + def initialize(url = 'localhost:8090') allq_conf = Allq::Configuration.new do |config| config.host = url end raw_client = Allq::ApiClient.new(allq_conf) @@ -125,39 +125,34 @@ job = nil job = @client.peek_get(tube_name, buried: true) return nil if job.body.nil? job.body = Base64.decode64(job.body) if job - job_obj = Blitline::AllQJob.new(self, job) + job_obj = Backburner::AllQJob.new(self, job) job_obj end def get(tube_name = 'default') job = nil - delt = Blitline::Utils.get_delta do - job = @client.job_get(tube_name) - end - puts "Allq http get delta: #{delt} #{tube_name} #{job}" if delt.to_f > 1.5 + job = @client.job_get(tube_name) - @recent_times.push(delt.to_f) - @recent_times.shift if @recent_times.size > 2 # Inplace decode job.body = Base64.decode64(job.body) if job&.body - job_obj = Blitline::AllQJob.new(self, job) + job_obj = Backburner::AllQJob.new(self, job) job_obj rescue StandardError => ex if ex.message == "Couldn't resolve host name" - BlitlineLogger.log("COUDNT RESOLVE HOST NAME------ SHOULD REBOOT") + puts("COUDNT RESOLVE HOST NAME------ SHOULD REBOOT") else - BlitlineLogger.log(ex) + puts(ex) end end def close rescue StandardError => ex - BlitlineLogger.log(ex) + puts(ex) end def map_priority(app_priority) app_priority = app_priority.to_i @@ -176,13 +171,13 @@ default end def log_result(job_result) - BlitlineLogger.log("ALLQ-HTTP-JOB-ID=#{job_result.job_id}") + puts("ALLQ-HTTP-JOB-ID=#{job_result.job_id}") rescue StandardError => ex - BlitlineLogger.log(ex) + puts(ex) end def build_new_job(body, options) adjusted_priority = map_priority(options[:pri] || 5) @@ -239,34 +234,31 @@ result = nil begin Timeout.timeout(10) do if body && body.to_s.include?('["default"]') - BlitlineLogger.log "PUTTING DEFAULT! #{caller.inspect}" + puts "PUTTING DEFAULT! #{caller.inspect}" end - delt = Blitline::Utils.get_delta do - if is_parent - new_job = build_new_parent_job(body, options) - result = @client.parent_job_post(new_job) - else - new_job = build_new_job(body, options) - result = @client.job_post(new_job) - end - raise 'PUT returned nil' if result.nil? || result.to_s == '' + if is_parent + new_job = build_new_parent_job(body, options) + result = @client.parent_job_post(new_job) + else + new_job = build_new_job(body, options) + result = @client.job_post(new_job) end - BlitlineLogger.log "Allq http put delta: #{delt}" + raise 'PUT returned nil' if result.nil? || result.to_s == '' end rescue Timeout::Error - BlitlineLogger.log('ALLQ_PUT_TIMEOUT') + puts('ALLQ_PUT_TIMEOUT') sleep(5) retry_count += 1 retry if retry_count < 4 raise 'Failed to put on allq, we are investigating the problem, please try again' rescue StandardError => ex - BlitlineLogger.log('Failed to ALLQ PUT') - BlitlineLogger.log(ex) + puts('Failed to ALLQ PUT') + puts(ex) retry_count += 1 sleep(5) retry if retry_count < 4 raise 'Failed to put on allq, we are investigating the problem, please try again' end @@ -288,28 +280,28 @@ final_stats[name]['parents'] = final_stats[name]['parents'].to_i + tube_ref.parents.to_i end end final_stats rescue StandardError => ex - BlitlineLogger.log(ex) + puts(ex) {} end def get_ready_by_tube(name) count = -1 tube_stats = stats[name] count = tube_stats['ready'].to_i if tube_stats && tube_stats['ready'] count rescue StandardError => ex - BlitlineLogger.log(ex) + puts(ex) -1 end def size result = get_ready_by_tube('default') result.to_i rescue StandardError => ex - BlitlineLogger.log(ex) + puts(ex) 0 end end end