Sha256: 06f590191b28bc26ad1224a03674938b2b5547769ad76ace3788a95074ff53d5

Contents?: true

Size: 1.01 KB

Versions: 11

Compression:

Stored size: 1.01 KB

Contents

#!/usr/bin/env ruby
require 'rubygems'
require '../lib/gearman'

#Gearman::Util.debug = true

worker = Gearman::Worker.new('localhost')
worker.reconnect_sec = 2

# Additon ability
worker.add_ability('addition') do |data,job|
  values = Marshal.load(data)
  puts "[addition_worker] Calculating #{values.inspect}..."
  # sleep 5
  values.first + values.last
end

# Subtraction ability
worker.add_ability('subtraction') do |data,job|
  values = Marshal.load(data)
  puts "[subtraction_worker] Calculating #{values.inspect}..."
  # sleep 5
  values.first - values.last
end

# Multiplication worker
worker.add_ability('multiplication') do |data,job|
  values = Marshal.load(data)
  puts "[multiplication_worker] Calculating #{values.inspect}..."
  # sleep 5
  values.first * values.last
end

# Division worker
worker.add_ability('division') do |data,job|
  values = Marshal.load(data)
  puts "[division_worker] Calculating #{data.inspect}..."
  # sleep 5
  values.first / values.last
end

# Running the workers
loop do
  worker.work
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
gearman-ruby-3.0.8 examples/calculus_worker.rb
xing-gearman-ruby-1.1.0 examples/calculus_worker.rb
xing-gearman-ruby-1.2.0 examples/calculus_worker.rb
xing-gearman-ruby-1.3.0 examples/calculus_worker.rb
xing-gearman-ruby-1.3.1 examples/calculus_worker.rb
gearman-ruby-3.0.7 examples/calculus_worker.rb
gearman-ruby-3.0.6 examples/calculus_worker.rb
gearman-ruby-3.0.4 examples/calculus_worker.rb
gearman-ruby-3.0.3 examples/calculus_worker.rb
gearman-ruby-3.0.2 examples/calculus_worker.rb
gearman-ruby-3.0.1 examples/calculus_worker.rb