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 +4 -4
- data/examples/client.rb +11 -4
- data/examples/client_background_jobs.rb +22 -0
- data/examples/client_reverse_string.rb +16 -0
- data/examples/worker.rb +1 -1
- data/examples/worker_reverse_string.rb +1 -4
- data/lib/gearman/client.rb +3 -3
- data/lib/gearman/version.rb +1 -1
- metadata +3 -3
- data/examples/client_reverse_nohost.rb +0 -30
- data/examples/client_reverse_wait.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8799efeb8ec1766ffb262f401595cf9f1029fdc
|
4
|
+
data.tar.gz: e672b3358f6bda8dc55467e1a5af72973d422e2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efea3f3ae2c88664d13b56debf6ec69e533c43136c8b2555f6c93de7ade16406e51ccee0fd27d3a40cecb07f347281f92139b8b30a2cc6a12c1f9ac49c1d36a8
|
7
|
+
data.tar.gz: 5e391604849cec1c2ae53b300d9c0812b2a9f55b9a76faa0f9843b48cc4368a82f44adc0d545ad9adbdbae54552ae6115089365361a725c1180f985193a0b66a
|
data/examples/client.rb
CHANGED
@@ -1,14 +1,21 @@
|
|
1
1
|
$LOAD_PATH.unshift("../lib")
|
2
2
|
require 'rubygems'
|
3
|
-
require '
|
3
|
+
require 'gearman'
|
4
4
|
|
5
|
-
|
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.
|
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
|
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
|
+
|
data/examples/worker.rb
CHANGED
@@ -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 =
|
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
|
data/lib/gearman/client.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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.
|
data/lib/gearman/version.rb
CHANGED
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.
|
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/
|
30
|
-
- examples/
|
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
|
-
|