examples/worker_reverse_string.rb in gearman-ruby-3.0.2 vs examples/worker_reverse_string.rb in gearman-ruby-3.0.3

- old
+ new

@@ -1,20 +1,27 @@ require 'rubygems' require '../lib/gearman' # String reverse worker -servers = ['localhost:4731'] +servers = ['localhost:4730'] +t = nil jobnum = 0 -w = Gearman::Worker.new(servers) -w.add_ability('reverse_string') do |data,job| - result = data.reverse - puts "Job: #{job.inspect} Data: #{data.inspect} Reverse: #{result} " - puts "Completed job ##{jobnum}" - jobnum += 1 - result +(0..1).each do + t = Thread.new { + w = Gearman::Worker.new(servers) + w.add_ability('reverse_string') do |data,job| + result = data.reverse + puts "Job: #{job.inspect} Data: #{data.inspect} Reverse: #{result} " + puts "Completed job ##{jobnum}" + jobnum += 1 + result + end + loop { w.work } + } end -loop { w.work } +puts "Waiting for threads..." +t.join