gearman-ruby 4.0.3 → 4.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2549af4db82515db032fd209b69d14581d0f4874
4
- data.tar.gz: d53770255855d94b70ff47554e2bc1ffd08e6b6b
3
+ metadata.gz: f8799efeb8ec1766ffb262f401595cf9f1029fdc
4
+ data.tar.gz: e672b3358f6bda8dc55467e1a5af72973d422e2d
5
5
  SHA512:
6
- metadata.gz: 3965b0ea6f6706ccfca686b68e56bdc18f7e2704778e53a165600296c05a9fa88e8b73522f8ab454a8bee5b47c8670c5329d726721be0b71782247dfd87934eb
7
- data.tar.gz: 6d2466dff2c3dd6ff723c87b10a724b95d7453730900842b2fee16f5125b55c9c61fc368233b313b945de580fd85aeac7f9f24d90dfe034c27484a7db13ae33a
6
+ metadata.gz: efea3f3ae2c88664d13b56debf6ec69e533c43136c8b2555f6c93de7ade16406e51ccee0fd27d3a40cecb07f347281f92139b8b30a2cc6a12c1f9ac49c1d36a8
7
+ data.tar.gz: 5e391604849cec1c2ae53b300d9c0812b2a9f55b9a76faa0f9843b48cc4368a82f44adc0d545ad9adbdbae54552ae6115089365361a725c1180f985193a0b66a
@@ -1,14 +1,21 @@
1
1
  $LOAD_PATH.unshift("../lib")
2
2
  require 'rubygems'
3
- require '../lib/gearman'
3
+ require 'gearman'
4
4
 
5
- servers = ['localhost:4730', 'localhost:4731']
5
+ # Control logger
6
+ l = Logger.new($stdout)
7
+ l.level = Logger::DEBUG
8
+ Gearman.logger=l
9
+
10
+ servers = ['localhost:4730']
6
11
 
7
12
  client = Gearman::Client.new(servers)
8
13
  taskset = Gearman::TaskSet.new(client)
9
14
 
10
15
  task = Gearman::Task.new('sleep', 20)
11
- task.on_complete {|d| puts d }
16
+ task.on_status {|n,d| puts "Status: #{n}/#{d} iterations complete" }
12
17
 
18
+ # Add task to taskset
13
19
  taskset.add_task(task)
14
- taskset.wait(100)
20
+ # Submit taskset and wait forever for completion
21
+ taskset.wait_forever
@@ -0,0 +1,22 @@
1
+ $:.push('../lib')
2
+ require 'gearman'
3
+ require 'logger'
4
+
5
+ logger = Logger.new(STDOUT)
6
+ logger.level = Logger::ERROR
7
+ Gearman.logger = logger
8
+
9
+ JOB_COUNT=100000
10
+
11
+ client = Gearman::Client.new('localhost:4730')
12
+
13
+ start_time = Time.now
14
+ (1..JOB_COUNT).each do |jid|
15
+ data = rand(36**8).to_s(36)
16
+ task = Gearman::BackgroundTask.new("reverse_string", data)
17
+ client.do_task(task)
18
+ end
19
+ end_time = Time.now
20
+
21
+ diff = end_time - start_time
22
+ puts "Completed #{JOB_COUNT} jobs in #{diff} seconds, at #{JOB_COUNT.to_f / diff} JPS"
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift '../lib'
3
+ require 'gearman'
4
+
5
+ client = Gearman::Client.new('localhost:4730')
6
+
7
+ # Create 100 foreground jobs, one at a time
8
+ (1..100).each do |jid|
9
+ data = rand(36**8).to_s(36)
10
+ puts "#{jid} #{data}"
11
+ task = Gearman::Task.new('reverse_string', data)
12
+ task.on_complete {|d| puts d }
13
+ client.do_task(task)
14
+ end
15
+
16
+
@@ -10,7 +10,7 @@ logger = Logger.new(STDOUT)
10
10
  # Add a handler for a "sleep" function that takes a single argument, the
11
11
  # number of seconds to sleep before reporting success.
12
12
  w.add_ability("sleep") do |data,job|
13
- seconds = 10
13
+ seconds = data.to_i
14
14
  logger.info "Sleeping for #{seconds} seconds"
15
15
  (1..seconds.to_i).each do |i|
16
16
  sleep 1
@@ -1,11 +1,8 @@
1
- $:.unshift File.join(File.dirname(__FILE__), '..', "lib" )
1
+ $:.unshift '../lib'
2
2
  require 'gearman'
3
3
 
4
4
  # String reverse worker
5
-
6
5
  servers = ['127.0.0.1:4730']
7
-
8
- t = nil
9
6
  jobnum = 0
10
7
 
11
8
  w = Gearman::Worker.new(servers)
@@ -88,7 +88,7 @@ module Gearman
88
88
  end
89
89
  type, data = connection.read_response(remaining)
90
90
  handle_response(task, type, data)
91
- end while [:work_status, :work_data].include? type
91
+ end while [:work_status, :work_data, :work_warning].include? type
92
92
  end
93
93
 
94
94
  else
@@ -129,11 +129,11 @@ module Gearman
129
129
  task.handle_status(numerator, denominator)
130
130
  when :work_warning
131
131
  handle, message = data.split("\0", 2)
132
- Util.logger.debug "Got WORK_WARNING for #{handle}: '#{message}'"
132
+ logger.warn "Got WORK_WARNING for #{handle}: '#{message}'"
133
133
  task.handle_warning(message)
134
134
  when :work_data
135
135
  handle, work_data = data.split("\0", 2)
136
- Util.logger.debug "Got WORK_DATA for #{handle} with #{work_data ? work_data.size : '0'} byte(s) of data"
136
+ logger.debug "Got WORK_DATA for #{handle} with #{work_data ? work_data.size : '0'} byte(s) of data"
137
137
  task.handle_data(work_data)
138
138
  else
139
139
  # Not good.
@@ -1,3 +1,3 @@
1
1
  module Gearman
2
- VERSION = "4.0.3"
2
+ VERSION = '4.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gearman-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.3
4
+ version: 4.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Ewart
@@ -26,8 +26,8 @@ files:
26
26
  - README.md
27
27
  - Rakefile
28
28
  - examples/client.rb
29
- - examples/client_reverse_nohost.rb
30
- - examples/client_reverse_wait.rb
29
+ - examples/client_background_jobs.rb
30
+ - examples/client_reverse_string.rb
31
31
  - examples/worker.rb
32
32
  - examples/worker_reverse_string.rb
33
33
  - gearman-ruby.gemspec
@@ -1,30 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'rubygems'
3
- require '../lib/gearman'
4
- l = Logger.new($stdout)
5
- l.level = Logger::DEBUG
6
- Gearman::Util.logger=l
7
-
8
- # Client using Gearman SUBMIT_JOB_EPOCH (currently requires the gearmand branch lp:~jewart/gearmand/scheduled_jobs_support/)
9
-
10
- t = nil
11
- threadcounter = 0
12
-
13
- client = Gearman::Client.new('192.168.1.1:4730')
14
-
15
-
16
- myid = threadcounter
17
- threadcounter += 1
18
- taskset = Gearman::TaskSet.new(client)
19
-
20
- (1..1000).each do |jid|
21
- data = rand(36**8).to_s(36)
22
- result = data.reverse
23
-
24
- task = Gearman::BackgroundTask.new("reverse_string", data)
25
- puts "#{jid} #{data}"
26
-
27
- #time = Time.now() + rand(120) + 10
28
- #task.schedule(time)
29
- taskset.add_task(task)
30
- end
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $:.unshift File.join(File.dirname(__FILE__), '..', "lib" )
3
- require 'gearman'
4
-
5
- # Client using Gearman SUBMIT_JOB_EPOCH (currently requires the gearmand branch lp:~jewart/gearmand/scheduled_jobs_support/)
6
-
7
- t = nil
8
- threadcounter = 0
9
-
10
- client = Gearman::Client.new('localhost:4730')
11
-
12
-
13
- myid = threadcounter
14
- threadcounter += 1
15
- taskset = Gearman::TaskSet.new(client)
16
-
17
- (1..100).each do |jid|
18
- data = rand(36**8).to_s(36)
19
- puts "#{jid} #{data}"
20
- task = Gearman::Task.new("reverse_string", data)
21
- task.on_complete {|d| puts d }
22
- client.do_task(task)
23
- end
24
-
25
-