gearman-ruby 3.0.2 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -8,8 +8,8 @@ begin
8
8
  Jeweler::Tasks.new do |s|
9
9
  s.name = "gearman-ruby"
10
10
  s.summary = "Library for the Gearman distributed job system"
11
- s.email = "john@unixninjas.org"
12
- s.homepage = "http://github.com/johnewart/gearman-ruby"
11
+ s.email = "gearman.ruby@librelist.com"
12
+ s.homepage = "http://github.com/gearman-ruby/gearman-ruby"
13
13
  s.description = "Library for the Gearman distributed job system"
14
14
  s.authors = ["John Ewart", "Colin Curtin", "Daniel Erat", "Ladislav Martincik", "Pablo Delgado", "Mauro Pompilio", "Antonio Garrote", "Kim Altintop"]
15
15
  end
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 3
3
3
  :minor: 0
4
- :patch: 2
4
+ :patch: 3
@@ -2,13 +2,13 @@ require 'rubygems'
2
2
  #require 'gearman'
3
3
  require '../lib/gearman'
4
4
 
5
- servers = ['localhost:4731']
5
+ servers = ['localhost:4730',]
6
6
 
7
7
  client = Gearman::Client.new(servers)
8
8
  taskset = Gearman::TaskSet.new(client)
9
9
 
10
10
  task = Gearman::Task.new('sleep', 20, { :background => true })
11
- #task.on_complete {|d| puts d }
11
+ task.on_complete {|d| puts d }
12
12
 
13
13
  taskset.add_task(task)
14
- #taskset.wait(100)
14
+ taskset.wait(100)
@@ -7,7 +7,7 @@ require '../lib/gearman'
7
7
  t = nil
8
8
  threadcounter = 0
9
9
 
10
- client = Gearman::Client.new('localhost:4731')
10
+ client = Gearman::Client.new('localhost')
11
11
 
12
12
 
13
13
  myid = threadcounter
@@ -22,6 +22,6 @@ taskset = Gearman::TaskSet.new(client)
22
22
  puts "#{jid} #{data}"
23
23
 
24
24
  time = Time.now() + rand(120) + 10
25
- #task.schedule(time)
25
+ task.schedule(time)
26
26
  taskset.add_task(task)
27
27
  end
@@ -3,18 +3,25 @@ require '../lib/gearman'
3
3
 
4
4
  # String reverse worker
5
5
 
6
- servers = ['localhost:4731']
6
+ servers = ['localhost:4730']
7
7
 
8
+ t = nil
8
9
  jobnum = 0
9
10
 
10
- w = Gearman::Worker.new(servers)
11
- w.add_ability('reverse_string') do |data,job|
12
- result = data.reverse
13
- puts "Job: #{job.inspect} Data: #{data.inspect} Reverse: #{result} "
14
- puts "Completed job ##{jobnum}"
15
- jobnum += 1
16
- result
11
+ (0..1).each do
12
+ t = Thread.new {
13
+ w = Gearman::Worker.new(servers)
14
+ w.add_ability('reverse_string') do |data,job|
15
+ result = data.reverse
16
+ puts "Job: #{job.inspect} Data: #{data.inspect} Reverse: #{result} "
17
+ puts "Completed job ##{jobnum}"
18
+ jobnum += 1
19
+ result
20
+ end
21
+ loop { w.work }
22
+ }
17
23
  end
18
- loop { w.work }
19
24
 
25
+ puts "Waiting for threads..."
26
+ t.join
20
27
 
@@ -248,6 +248,20 @@ class Worker
248
248
  @sockets.values.each {|s| announce_ability(s, func, timeout) }
249
249
  end
250
250
 
251
+
252
+ ##
253
+ # Add an after-ability hook
254
+ #
255
+ # The passed-in block of code will be executed after the work block for
256
+ # jobs with the same function name. It takes two arguments, the result of
257
+ # the work and the original job data. This way, if you need to hook into
258
+ # *after* the job_complete packet is sent to the server, you can do so.
259
+ #
260
+ # N.B The after-ability hook ONLY runs if the ability was successful and no
261
+ # exceptions were raised.
262
+ #
263
+ # @param func function name (without prefix)
264
+ #
251
265
  def after_ability(func, &f)
252
266
  @after_abilities[func] = Ability.new(f)
253
267
  end
@@ -291,6 +305,7 @@ class Worker
291
305
  ret = ability.run(data, Job.new(sock, handle))
292
306
  rescue Exception => e
293
307
  exception = e
308
+ Util.logger.debug "GearmanRuby: Exception: #{e}\n#{e.backtrace.join("\n")}\n"
294
309
  end
295
310
 
296
311
  cmd = if ret && exception.nil?
@@ -316,6 +331,7 @@ class Worker
316
331
  begin
317
332
  after_ability.run(ret, data)
318
333
  rescue Exception => e
334
+ Util.logger.debug "GearmanRuby: Exception: #{e}\n#{e.backtrace.join("\n")}\n"
319
335
  nil
320
336
  end
321
337
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gearman-ruby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 2
10
- version: 3.0.2
9
+ - 3
10
+ version: 3.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Ewart
@@ -22,12 +22,12 @@ autorequire:
22
22
  bindir: bin
23
23
  cert_chain: []
24
24
 
25
- date: 2010-08-20 00:00:00 -07:00
25
+ date: 2010-11-12 00:00:00 -08:00
26
26
  default_executable:
27
27
  dependencies: []
28
28
 
29
29
  description: Library for the Gearman distributed job system
30
- email: john@unixninjas.org
30
+ email: gearman.ruby@librelist.com
31
31
  executables: []
32
32
 
33
33
  extensions: []
@@ -77,9 +77,8 @@ files:
77
77
  - test/mock_worker_test.rb
78
78
  - test/util_test.rb
79
79
  - test/worker_test.rb
80
- - examples/bgclient.rb
81
80
  has_rdoc: true
82
- homepage: http://github.com/johnewart/gearman-ruby
81
+ homepage: http://github.com/gearman-ruby/gearman-ruby
83
82
  licenses: []
84
83
 
85
84
  post_install_message:
@@ -118,7 +117,6 @@ test_files:
118
117
  - test/mock_worker_test.rb
119
118
  - test/util_test.rb
120
119
  - test/worker_test.rb
121
- - examples/bgclient.rb
122
120
  - examples/calculus_client.rb
123
121
  - examples/calculus_worker.rb
124
122
  - examples/client.rb
data/examples/bgclient.rb DELETED
@@ -1,19 +0,0 @@
1
- require 'rubygems'
2
- #require 'gearman'
3
- require '../lib/gearman'
4
- require 'json'
5
-
6
- servers = ['localhost:4731']
7
-
8
- client = Gearman::Client.new(servers)
9
- taskset = Gearman::TaskSet.new(client)
10
- function = "reverse_string"
11
- struct_data = {
12
- :site_id => 45,
13
- :domain => 'www.google.com'
14
- }
15
- #data = JSON.generate(struct_data)
16
- data = "testing"
17
- task = Gearman::BackgroundTask.new(function, data)
18
- taskset.add_task(task)
19
-