boss_queue 0.2.3 → 0.2.4

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.2.3
1
+ 0.2.4
data/boss_queue.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "boss_queue"
8
- s.version = "0.2.3"
8
+ s.version = "0.2.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Daniel Nelson"]
@@ -34,10 +34,11 @@ class BossQueue
34
34
 
35
35
  def create_queue
36
36
  # small message size because we are only sending id
37
- # 5 second delay so that we can use eventually consistent reads in DynamoDB
37
+ # minimum 1 second delay so that we don't even try to pick it up until it is likely that the
38
+ # message is ready (or else we waste time just waiting for the saved data to become available)
38
39
  AWS::SQS::QueueCollection.new.create(queue_name, :visibility_timeout => 180,
39
40
  :maximum_message_size => 1024,
40
- :delay_seconds => 5,
41
+ :delay_seconds => 1,
41
42
  :message_retention_period => 1209600)
42
43
  end
43
44
 
@@ -47,7 +48,7 @@ class BossQueue
47
48
  job_dequeued = true
48
49
  # When a block is given, each message is yielded to the block and then deleted as long as the block exits normally - http://docs.aws.amazon.com/AWSRubySDK/latest/frames.html
49
50
  begin
50
- job = BossQueue::Job.shard(table_name).find(job_id.body)
51
+ job = BossQueue::Job.find_by_id(job_id.body, :shard => table_name, :consistent_read => true)
51
52
  job.sqs_queue = sqs_queue
52
53
  job.work
53
54
  rescue AWS::Record::RecordNotFound
@@ -21,6 +21,34 @@ class BossQueue
21
21
 
22
22
  timestamps
23
23
 
24
+ class << self
25
+ # We need consistent reads, so override @find_by_id
26
+ #
27
+ # @param [String] id The id of the record to load.
28
+ # @param [Hash] options
29
+ # @option options [String] :shard Specifies what shard (i.e. table)
30
+ # should be searched.
31
+ # @raise [RecordNotFound] Raises a record not found exception if there
32
+ # was no data found for the given id.
33
+ # @return [Record::HashModel] Returns the record with the given id.
34
+ def find_by_id id, options = {}
35
+
36
+ table = dynamo_db_table(options[:shard])
37
+
38
+ data = table.items[id].attributes.to_h(:consistent_read => options[:consistent_read])
39
+
40
+ raise RecordNotFound, "no data found for id: #{id}" if data.empty?
41
+
42
+ obj = self.new(:shard => table)
43
+ obj.send(:hydrate, id, data)
44
+ obj
45
+
46
+ end
47
+ alias_method :[], :find_by_id
48
+ end
49
+
50
+
51
+
24
52
  def enqueue
25
53
  sqs_queue.send_message(id.to_s)
26
54
  end
@@ -230,7 +230,7 @@ describe "BossQueue module" do
230
230
  @job = double('job')
231
231
  @job.stub(:work)
232
232
  @job.stub(:sqs_queue=)
233
- BossQueue::Job.stub_chain(:shard, :find).and_return(@job)
233
+ BossQueue::Job.stub(:find_by_id).and_return(@job)
234
234
  end
235
235
 
236
236
  it "should dequeue from SQS using the value of sqs_queue_url" do
@@ -245,14 +245,13 @@ describe "BossQueue module" do
245
245
 
246
246
  it "should use the dequeued id to retrieve a BossQueue::Job object" do
247
247
  shard = double('shard')
248
- BossQueue::Job.should_receive(:shard).with(BossQueue.new.table_name).and_return(shard)
249
- shard.should_receive(:find).with('ijk').and_return(@job)
248
+ BossQueue::Job.should_receive(:find_by_id).with('ijk', :shard => BossQueue.new.table_name, :consistent_read => true).and_return(@job)
250
249
  BossQueue.new.work
251
250
  end
252
251
 
253
252
  context "when the dequeued id does not match a BossQueue::Job object" do
254
253
  it "should not raise an exception" do
255
- BossQueue::Job.stub_chain(:shard, :find).and_raise(AWS::Record::RecordNotFound.new)
254
+ BossQueue::Job.stub(:find_by_id).and_raise(AWS::Record::RecordNotFound.new)
256
255
  lambda {
257
256
  BossQueue.new.work
258
257
  }.should_not raise_error
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boss_queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -160,7 +160,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
160
  version: '0'
161
161
  segments:
162
162
  - 0
163
- hash: -141027132593834665
163
+ hash: 2592417147040776871
164
164
  required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  none: false
166
166
  requirements: