kestrel-client 0.5.7 → 0.5.8

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.7
1
+ 0.5.8
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{kestrel-client}
8
- s.version = "0.5.7"
8
+ s.version = "0.5.8"
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"]
@@ -4,10 +4,14 @@ class Kestrel::Client::Transactional < Kestrel::Client::Proxy
4
4
  # multiple queues.
5
5
  class MultipleQueueException < StandardError; end
6
6
 
7
+ # Raised when a caller attempts to retry a job if
8
+ # there is no current open transaction
9
+ class NoOpenTransaction < StandardError; end
10
+
7
11
  class RetryableJob < Struct.new(:retries, :job); end
8
12
 
9
13
  # Number of times to retry a job before giving up
10
- DEFAULT_RETRIES = 100
14
+ DEFAULT_RETRIES = 10
11
15
 
12
16
  # Pct. of the time during 'normal' processing we check the error queue first
13
17
  ERROR_PROCESSING_RATE = 0.1
@@ -39,6 +43,9 @@ class Kestrel::Client::Transactional < Kestrel::Client::Proxy
39
43
  # ==== Returns
40
44
  # Job, possibly retryable, or nil
41
45
  #
46
+ # ==== Raises
47
+ # MultipleQueueException
48
+ #
42
49
  def get(key, opts = {})
43
50
  raise MultipleQueueException if current_queue && key != current_queue
44
51
 
@@ -69,20 +76,21 @@ class Kestrel::Client::Transactional < Kestrel::Client::Proxy
69
76
  # retry. If the job has been retried DEFAULT_RETRIES times,
70
77
  # gives up entirely.
71
78
  #
79
+ # ==== Parameters
80
+ # item (optional):: if specified, the job set to the error
81
+ # queue with the given payload instead of what
82
+ # was originally fetched.
83
+ #
72
84
  # ==== Returns
73
85
  # Boolean:: true if the job is enqueued in the retry queue, false otherwise
74
86
  #
87
+ # ==== Raises
88
+ # NoOpenTransaction
75
89
  #
76
90
  def retry(item = nil)
77
- job =
78
- if item
79
- current_retries = (@job ? @job.retries : 0)
80
- RetryableJob.new(current_retries, item)
81
- else
82
- @job.dup
83
- end
84
-
85
- return unless job
91
+ raise NoOpenTransaction unless @last_read_queue
92
+
93
+ job = item ? RetryableJob.new(@job.retries, item) : @job.dup
86
94
 
87
95
  job.retries += 1
88
96
 
@@ -18,6 +18,7 @@ describe "Kestrel::Client::Transactional" do
18
18
  returns = [:mcguffin]
19
19
  stub(@raw_kestrel_client).get(@queue, anything) { returns.shift }
20
20
  stub(@raw_kestrel_client).get(@queue + "_errors", anything)
21
+
21
22
  mock(@raw_kestrel_client).get_from_last(@queue + "/close")
22
23
 
23
24
  get_job.should == :mcguffin
@@ -29,6 +30,7 @@ describe "Kestrel::Client::Transactional" do
29
30
  returns = [Kestrel::Client::Transactional::RetryableJob.new(1, :mcguffin)]
30
31
  stub(@raw_kestrel_client).get(@queue + "_errors", anything) { returns.shift }
31
32
  stub(@raw_kestrel_client).get(@queue, anything)
33
+
32
34
  mock(@raw_kestrel_client).get_from_last(@queue + "_errors/close")
33
35
 
34
36
  get_job.should == :mcguffin
@@ -40,6 +42,7 @@ describe "Kestrel::Client::Transactional" do
40
42
  returns = [:mcguffin]
41
43
  stub(@raw_kestrel_client).get(@queue, anything) { returns.shift }
42
44
  stub(@raw_kestrel_client).get(@queue + "_errors", anything)
45
+
43
46
  mock(@raw_kestrel_client).set(@queue + "_errors", anything) do |q,j|
44
47
  j.retries.should == 1
45
48
  j.job.should == :mcguffin
@@ -155,6 +158,16 @@ describe "Kestrel::Client::Transactional" do
155
158
  @kestrel.get(@queue)
156
159
  end
157
160
 
161
+ it "raises an exception if called when there is no open transaction" do
162
+ @kestrel.close_last_transaction
163
+ lambda { @kestrel.retry }.should raise_error(Kestrel::Client::Transactional::NoOpenTransaction)
164
+ end
165
+
166
+ it "raises an exception if retry has already been called" do
167
+ @kestrel.retry
168
+ lambda { @kestrel.retry }.should raise_error(Kestrel::Client::Transactional::NoOpenTransaction)
169
+ end
170
+
158
171
  it "enqueues a fresh failed job to the errors queue with a retry count" do
159
172
  mock(@raw_kestrel_client).set(@queue + "_errors", anything) do |queue, job|
160
173
  job.retries.should == 1
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: 5
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 7
10
- version: 0.5.7
9
+ - 8
10
+ version: 0.5.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Freels