Created
May 23, 2014 12:29
-
-
Save AlexMocioi/093b098a16456b8d4623 to your computer and use it in GitHub Desktop.
Ruby Gearman Worker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'gearman' | |
require 'json' | |
require 'net/http' | |
require 'uri' | |
require 'pg' | |
w = Gearman::Worker.new(['***.***.***.***:4730']) | |
conn = PGconn.open(:dbname => 'cs_master' , :hostaddr => '***.***.***.***' , :port => '2345') | |
uri = URI.parse("http://***.***.***.***:5984/cimitir/_design/vedere/_view/nume_prenume?limit=11") | |
cDB = Net::HTTP.new(uri.host, uri.port) | |
w.add_ability('aduna11') do |data,job| | |
puts "Lucrez: #{job.handle()}" | |
cDB_response = cDB.request(Net::HTTP::Get.new(uri.request_uri)) | |
ceva = JSON.parse(cDB_response.body) | |
Hash["lucrator" => "ruby-laptop-couchdb", "rezultat" => data.to_i + ceva['rows'].length].to_json | |
res = conn.exec('SELECT count(*) as cate FROM judet where id<12') | |
rez = data.to_i + res[0]['cate'].to_i | |
Hash["lucrator" => "ruby-laptop-pgsql", "rezultat" => rez].to_json | |
end | |
loop { w.work } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment