summaryrefslogtreecommitdiff
path: root/lib/oxidized/worker.rb
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2013-04-17 17:48:50 +0300
committerSaku Ytti <saku@ytti.fi>2013-04-17 17:48:50 +0300
commit9d217025fac3e335c308f02e7377e14ccfdc0e66 (patch)
treeb90d4d04947fe26a9e592e12d8c4352142380c03 /lib/oxidized/worker.rb
Initial commit
Silly for shit-and-giggles attempt at rancid
Diffstat (limited to 'lib/oxidized/worker.rb')
-rw-r--r--lib/oxidized/worker.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/oxidized/worker.rb b/lib/oxidized/worker.rb
new file mode 100644
index 0000000..adbaa0e
--- /dev/null
+++ b/lib/oxidized/worker.rb
@@ -0,0 +1,34 @@
+module Oxidized
+ require 'oxidized/job'
+ require 'oxidized/jobs'
+ class Worker
+ def initialize nodes
+ @nodes = nodes
+ @jobs = Jobs.new CFG.threads, CFG.interval, @nodes
+ Thread.abort_on_exception = true
+ end
+ def work
+ ended = []
+ @jobs.delete_if { |job| ended << job if not job.alive? }
+ ended.each { |job| process job }
+ while @jobs.size < @jobs.want
+ Log.debug "Jobs #{@jobs.size}, Want: #{@jobs.want}"
+ node = @nodes.get
+ node.running? ? next : node.running = true
+ @jobs.push Job.new node
+ end
+ end
+ def process job
+ node = job.node
+ node.last = job
+ @jobs.duration job.time
+ if job.status == :success
+ node.output.new.update node.name, job.config,
+ :msg => "update #{node.name}", :group => node.group
+ else
+ Log.warn "#{node.name} status #{job.status}"
+ end
+ node.running = false
+ end
+ end
+end