kestrel-client 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.5.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{kestrel-client}
8
- s.version = "0.5.2"
8
+ s.version = "0.5.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matt Freels", "Rael Dornfest"]
12
- s.date = %q{2010-09-30}
12
+ s.date = %q{2010-10-05}
13
13
  s.description = %q{Ruby client for the Kestrel queue server}
14
14
  s.email = %q{rael@twitter.com}
15
15
  s.extra_rdoc_files = [
@@ -4,22 +4,14 @@ class Kestrel::Client::Transactional < Kestrel::Client::Proxy
4
4
  # multiple queues.
5
5
  class MultipleQueueException < StandardError; end
6
6
 
7
-
8
7
  class RetryableJob < Struct.new(:retries, :job); end
9
8
 
10
-
11
9
  # Number of times to retry a job before giving up
12
10
  DEFAULT_RETRIES = 100
13
11
 
14
-
15
12
  # Pct. of the time during 'normal' processing we check the error queue first
16
13
  ERROR_PROCESSING_RATE = 0.1
17
14
 
18
-
19
- # Maximum number of gets to execute before switching servers
20
- MAX_PER_SERVER = 100_000
21
-
22
-
23
15
  # ==== Parameters
24
16
  # client<Kestrel::Client>:: Client
25
17
  # max_retries<Integer>:: Number of times to retry a job before
@@ -31,10 +23,9 @@ class Kestrel::Client::Transactional < Kestrel::Client::Proxy
31
23
  # single server, before changing
32
24
  # servers. Defaults to MAX_PER_SERVER
33
25
  #
34
- def initialize(client, max_retries = nil, error_rate = nil, per_server = nil)
26
+ def initialize(client, max_retries = nil, error_rate = nil)
35
27
  @max_retries = max_retries || DEFAULT_RETRIES
36
28
  @error_rate = error_rate || ERROR_PROCESSING_RATE
37
- @per_server = per_server || MAX_PER_SERVER
38
29
  @counter = 0 # Command counter
39
30
  super(client)
40
31
  end
@@ -77,17 +68,25 @@ class Kestrel::Client::Transactional < Kestrel::Client::Proxy
77
68
  # ==== Returns
78
69
  # Boolean:: true if the job is retryable, false otherwise
79
70
  #
80
- def retry
81
- return unless @job
71
+ def retry(item = nil)
72
+ job =
73
+ if item
74
+ current_retries = (@job ? @job.retries : 0)
75
+ RetryableJob.new(current_retries, item)
76
+ else
77
+ @job
78
+ end
79
+
80
+ return unless job
82
81
 
83
- @job.retries += 1
82
+ job.retries += 1
84
83
 
85
- if should_retry = @job.retries < @max_retries
86
- client.set(current_queue + "_errors", @job)
84
+ if should_retry = job.retries < @max_retries
85
+ client.set(current_queue + "_errors", job)
87
86
  end
88
87
 
89
88
  # close the transaction on the original queue if this is the first retry
90
- close_transaction(@job.retries == 1 ? current_queue : "#{current_queue}_errors")
89
+ close_transaction(job.retries == 1 ? current_queue : "#{current_queue}_errors")
91
90
 
92
91
  should_retry
93
92
  end
@@ -4,7 +4,7 @@ describe "Kestrel::Client::Transactional" do
4
4
  describe "Instance Methods" do
5
5
  before do
6
6
  @raw_kestrel_client = Kestrel::Client.new(*Kestrel::Config.default)
7
- @kestrel = Kestrel::Client::Transactional.new(@raw_kestrel_client, nil, nil, 1)
7
+ @kestrel = Kestrel::Client::Transactional.new(@raw_kestrel_client)
8
8
  stub(@kestrel).rand { 1 }
9
9
  @queue = "some_queue"
10
10
  end
@@ -128,6 +128,14 @@ describe "Kestrel::Client::Transactional" do
128
128
  @kestrel.retry.should be_true
129
129
  end
130
130
 
131
+ it "allows specification of the job to retry" do
132
+ mock(@raw_kestrel_client).set(@queue + "_errors", anything) do |queue, job|
133
+ job.retries.should == 1
134
+ job.job.should == :revised_mcmuffin
135
+ end
136
+ @kestrel.retry(:revised_mcmuffin).should be_true
137
+ end
138
+
131
139
  it "increments the retry count and re-enqueues the retried job" do
132
140
  stub(@kestrel).rand { 0 }
133
141
  stub(@raw_kestrel_client).get(@queue + "_errors", anything) do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kestrel-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 2
10
- version: 0.5.2
9
+ - 3
10
+ version: 0.5.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Freels
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-09-30 00:00:00 -07:00
19
+ date: 2010-10-05 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency