summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2018-06-22 19:05:16 +0300
committerSaku Ytti <saku@ytti.fi>2018-06-22 19:05:16 +0300
commit31b863f2eeff3ccbec8d0c0c35caf2c0e1d3e0ef (patch)
treed524cfe6a9819e31e9792cb878f1da23794f644b
parent483a9901280ea436db34f61ef220cc2f4d90b0da (diff)
remove worker smell
-rw-r--r--lib/oxidized/worker.rb76
1 files changed, 42 insertions, 34 deletions
diff --git a/lib/oxidized/worker.rb b/lib/oxidized/worker.rb
index 74b046d..06e8689 100644
--- a/lib/oxidized/worker.rb
+++ b/lib/oxidized/worker.rb
@@ -36,48 +36,17 @@ module Oxidized
Oxidized.logger.debug("lib/oxidized/worker.rb: #{@jobs.size} jobs running in parallel") unless @jobs.empty?
end
+
def process job
node = job.node
node.last = job
node.stats.add job
@jobs.duration job.time
node.running = false
-
if job.status == :success
- @jobs_done += 1 # needed for :nodes_done hook
- Oxidized.Hooks.handle :node_success, :node => node,
- :job => job
- msg = "update #{node.name}"
- msg += " from #{node.from}" if node.from
- msg += " with message '#{node.msg}'" if node.msg
- output = node.output.new
- if output.store node.name, job.config,
- :msg => msg, :email => node.email, :user => node.user, :group => node.group
- node.modified
- Oxidized.logger.info "Configuration updated for #{node.group}/#{node.name}"
- Oxidized.Hooks.handle :post_store, :node => node,
- :job => job,
- :commitref => output.commitref
- end
- node.reset
+ process_success node, job
else
- msg = "#{node.name} status #{job.status}"
- if node.retry < Oxidized.config.retries
- node.retry += 1
- msg += ", retry attempt #{node.retry}"
- @nodes.next node.name
- else
- # Only increment the @jobs_done when we give up retries for a node (or success).
- # As it would otherwise cause @jobs_done to be incremented with generic retries.
- # This would cause :nodes_done hook to desync from running at the end of the nodelist and
- # be fired when the @jobs_done > @nodes.count (could be mid-cycle on the next cycle).
- @jobs_done += 1
- msg += ", retries exhausted, giving up"
- node.retry = 0
- Oxidized.Hooks.handle :node_fail, :node => node,
- :job => job
- end
- Oxidized.logger.warn msg
+ process_failure node, job
end
rescue NodeNotFound
Oxidized.logger.warn "#{node.name} not found, removed while collecting?"
@@ -85,6 +54,45 @@ module Oxidized
private
+ def process_success node, job
+ @jobs_done += 1 # needed for :nodes_done hook
+ Oxidized.Hooks.handle :node_success, node: node,
+ job: job
+ msg = "update #{node.name}"
+ msg += " from #{node.from}" if node.from
+ msg += " with message '#{node.msg}'" if node.msg
+ output = node.output.new
+ if output.store node.name, job.config,
+ msg: msg, email: node.email, user: node.user, group: node.group
+ node.modified
+ Oxidized.logger.info "Configuration updated for #{node.group}/#{node.name}"
+ Oxidized.Hooks.handle :post_store, node: node,
+ job: job,
+ commitref: output.commitref
+ end
+ node.reset
+ end
+
+ def process_failure node, job
+ msg = "#{node.name} status #{job.status}"
+ if node.retry < Oxidized.config.retries
+ node.retry += 1
+ msg += ", retry attempt #{node.retry}"
+ @nodes.next node.name
+ else
+ # Only increment the @jobs_done when we give up retries for a node (or success).
+ # As it would otherwise cause @jobs_done to be incremented with generic retries.
+ # This would cause :nodes_done hook to desync from running at the end of the nodelist and
+ # be fired when the @jobs_done > @nodes.count (could be mid-cycle on the next cycle).
+ @jobs_done += 1
+ msg += ", retries exhausted, giving up"
+ node.retry = 0
+ Oxidized.Hooks.handle :node_fail, :node => node,
+ :job => job
+ end
+ Oxidized.logger.warn msg
+ end
+
def is_cycle_finished?
if @jobs_done > @nodes.count
true