Sha256: 9727c91e54facb7df8df989f4660b579803aef17901e463463f22876ff012606

Contents?: true

Size: 1.08 KB

Versions: 11

Compression:

Stored size: 1.08 KB

Contents

#!/usr/bin/env ruby
require 'rubygems'
require '../lib/gearman'
#Gearman::Util.debug = true

# Connect to the local server (at the default port 7003) 
client = Gearman::Client.new('localhost')
taskset = Gearman::TaskSet.new(client)

# Get something to echo
puts '[client] Write a basic arithmetic operation:'
input = gets

operations = input.chomp.scan(/\d+[\+\-\*\/]\d+/).compact
puts "[client] The following operations were found: #{operations.inspect}"

# Setup a task for operation
operations.each do |op|
  # Determining the operation
  case op
    when /\+/
      type, data = 'addition', op.split('+') 
    when /\-/
      type, data = 'subtraction', op.split('-') 
    when /\*/
      type, data = 'multiplication', op.split('*') 
    when /\//
      type, data = 'division', op.split('/') 
  end

  task = Gearman::Task.new(type, Marshal.dump(data.map {|v| v.to_i}))
  task.on_complete {|r| puts "[client] #{type} result is: #{r}" }

  # Sending the task to the server
  puts "[client] Sending values: #{data.inspect}, to the '#{type}' worker"
  taskset.add_task(task)
  taskset.wait(100)
end

Version data entries

11 entries across 11 versions & 2 rubygems

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