Skip to content

Instantly share code, notes, and snippets.

@AlexMocioi
Created May 23, 2014 12:29
Show Gist options
  • Save AlexMocioi/093b098a16456b8d4623 to your computer and use it in GitHub Desktop.
Save AlexMocioi/093b098a16456b8d4623 to your computer and use it in GitHub Desktop.
Ruby Gearman Worker
#!/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