class Beanpicker::Server
Used by combine to run a server of jobs
Public Class Methods
new(args=ARGV)
click to toggle source
expect a list of files to load or pick from ARGV
# File lib/beanpicker/job_server.rb, line 15 def initialize(args=ARGV) @args = args end
Public Instance Methods
log_handler()
click to toggle source
Use the Beanpicker::log_handler to log messages
# File lib/beanpicker/job_server.rb, line 63 def log_handler Beanpicker::log_handler end
run()
click to toggle source
Create all workers and verify if exists any Worker
or Worker::Child
to start a loop. If no only exit
# File lib/beanpicker/job_server.rb, line 21 def run debug "Hiring workers..." for arg in @args Worker.new arg end w = c = 0 for worker in Beanpicker::workers w += 1 m = "Worker: #{worker.name} hired to do" f = {} for child in worker.childs c += 1 f[child.job_name] ||= 0 f[child.job_name] += 1 end for job in f.keys.sort m << " #{job}##{f[job]}" end debug m end if w == 0 fatal ["NOBODY WANT TO WORK TO YOU!!", "Have you specified a file?", "e.g. #{$0} lib/my_file_with_jobs.rb"].join("\n") exit end if c == 0 fatal ["ALL YOUR #{w} WORKER#{"S" if w > 1} ARE LAZY AND DON'T WANT TO DO ANYTHING!!", "Have you specified a job in any of yous files?", "e.g. job('no.lazy.worker') { |args| puts args[:my_money] }"].join("\n") exit end debug "#{w} worker#{"s" if w > 1} hired to do #{c} job#{"s" if c > 1}, counting the money..." loop { sleep 1 } end