Changeset 1549
- Timestamp:
- 04/22/08 10:55:58 (3 weeks ago)
- Files:
-
- hive/trunk/worker_bee/lib/worker_bee.rb (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
hive/trunk/worker_bee/lib/worker_bee.rb
r1483 r1549 1 1 module Hive 2 2 class WorkerBee 3 attr_reader : hive, :config3 attr_reader :interval, :config 4 4 5 5 def initialize(config) 6 begin 7 @config = config 8 rescue SystemCallError 9 raise "Couldn't find or read the conf/worker.yml file. Tried: #{f}" 10 end 11 6 @config = config 7 12 8 if @config["access_key"] == "nil" 13 9 raise "Access Key is not set." 14 10 end 15 11 12 @config["poll_interval"] ||= 5 13 @interval = @config["poll_interval"] * 60 14 15 STDOUT.print "Poll interval set to: #{@interval} minutes" 16 16 17 hive = config["hive_url"] 17 18 hive << "/" unless hive[/\/$/] … … 42 43 return true 43 44 rescue Exception => e 44 STDERR.print "Can't reach Global hive @ #{@config["ping_url"]} exception: #{e}\n"45 STDERR.print "Can't reach Community Hive @ #{@config["ping_url"]} exception: #{e}\n" 45 46 return false 46 47 end 47 48 end 48 49 49 # Need to test this50 # Send the data to the community hive (JSON encoded) 50 51 def ship_data 51 52 # Grab data from the local DB, serialize … … 54 55 55 56 if job 56 #STDOUT.print "Job to process!"57 58 57 encoded_data = ActiveSupport::JSON.encode(job.job_data) 59 58 begin … … 64 63 STDOUT.print "Error sending data: #{e.message}" 65 64 end 66 67 65 end 68 66 end 69 67 70 # Main loop 68 # Main loop 69 # Do a ping to update the heartbeat table for Community Hive and 70 # Ship data if any available 71 71 def run 72 72 loop do 73 73 if ping? 74 74 ship_data 75 end 76 77 sleep(5*60) # 5 minutes 75 end 76 sleep(@interval) 78 77 end 79 78 end … … 95 94 def process_response(res) 96 95 if %w(200 201).include? res.code 97 res.body98 elsif res.code == "403"99 raise "Unauthorized"100 else101 raise "HTTP Error. Status: #{res.code} #{res.body}"102 end96 res.body 97 elsif res.code == "403" 98 raise "Unauthorized" 99 else 100 raise "HTTP Error. Status: #{res.code} #{res.body}" 101 end 103 102 end 104 103 105 104 def parse_url(url) 106 url = "http://#{url}" unless url.match(/^http/)107 URI.parse(url)108 end105 url = "http://#{url}" unless url.match(/^http/) 106 URI.parse(url) 107 end 109 108 110 109 def request_method(verb)
