chore-core 3.2.3 → 4.0.0
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.
- checksums.yaml +5 -5
- data/LICENSE.txt +1 -1
- data/README.md +170 -153
- data/chore-core.gemspec +2 -3
- data/lib/chore.rb +20 -0
- data/lib/chore/cli.rb +1 -2
- data/lib/chore/configuration.rb +1 -1
- data/lib/chore/consumer.rb +41 -9
- data/lib/chore/job.rb +2 -0
- data/lib/chore/publisher.rb +18 -2
- data/lib/chore/queues/filesystem/consumer.rb +18 -13
- data/lib/chore/queues/filesystem/publisher.rb +1 -1
- data/lib/chore/queues/sqs.rb +22 -13
- data/lib/chore/queues/sqs/consumer.rb +61 -33
- data/lib/chore/queues/sqs/publisher.rb +26 -17
- data/lib/chore/strategies/consumer/batcher.rb +6 -6
- data/lib/chore/strategies/consumer/single_consumer_strategy.rb +5 -5
- data/lib/chore/strategies/consumer/threaded_consumer_strategy.rb +6 -6
- data/lib/chore/strategies/consumer/throttled_consumer_strategy.rb +10 -11
- data/lib/chore/strategies/worker/helpers/ipc.rb +0 -1
- data/lib/chore/unit_of_work.rb +2 -1
- data/lib/chore/version.rb +3 -3
- data/lib/chore/worker.rb +4 -4
- data/spec/chore/consumer_spec.rb +1 -1
- data/spec/chore/queues/filesystem/filesystem_consumer_spec.rb +5 -7
- data/spec/chore/queues/sqs/consumer_spec.rb +117 -76
- data/spec/chore/queues/sqs/publisher_spec.rb +49 -60
- data/spec/chore/queues/sqs_spec.rb +32 -41
- data/spec/chore/strategies/consumer/single_consumer_strategy_spec.rb +3 -3
- data/spec/chore/strategies/consumer/threaded_consumer_strategy_spec.rb +6 -6
- data/spec/chore/strategies/worker/forked_worker_strategy_spec.rb +1 -1
- data/spec/chore/strategies/worker/single_worker_strategy_spec.rb +1 -1
- data/spec/chore/worker_spec.rb +21 -21
- data/spec/spec_helper.rb +1 -1
- data/spec/support/queues/sqs/fake_objects.rb +18 -0
- metadata +9 -13
@@ -1,74 +1,63 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
let(:job) { {'class' => 'TestJob', 'args'=>[1,2,'3']}}
|
6
|
-
let(:queue_name) { 'test_queue' }
|
7
|
-
let(:queue_url) {"http://www.queue_url.com/test_queue"}
|
8
|
-
let(:queue) { double('queue', :send_message => nil) }
|
9
|
-
let(:sqs) do
|
10
|
-
double('sqs', :queues => double('queues', :named => queue, :url_for => queue_url, :[] => queue))
|
11
|
-
end
|
12
|
-
let(:publisher) { Queues::SQS::Publisher.new }
|
13
|
-
let(:pool) { double("pool") }
|
3
|
+
describe Chore::Queues::SQS::Publisher do
|
4
|
+
include_context 'fake objects'
|
14
5
|
|
15
|
-
|
16
|
-
|
17
|
-
|
6
|
+
let(:publisher) { Chore::Queues::SQS::Publisher.new }
|
7
|
+
let(:job) { {'class' => 'TestJob', 'args'=>[1,2,'3']}}
|
8
|
+
let(:send_message_result) { double(Aws::SQS::Types::SendMessageResult, :data => job) }
|
18
9
|
|
19
|
-
|
20
|
-
|
21
|
-
|
10
|
+
before(:each) do
|
11
|
+
allow(Aws::SQS::Client).to receive(:new).and_return(sqs)
|
12
|
+
allow(sqs).to receive(:send_message).and_return(send_message_result)
|
13
|
+
end
|
22
14
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
:log_level => :debug
|
28
|
-
)
|
29
|
-
publisher.publish(queue_name,job)
|
30
|
-
end
|
15
|
+
it 'should configure sqs' do
|
16
|
+
expect(Aws::SQS::Client).to receive(:new)
|
17
|
+
publisher.publish(queue_name,job)
|
18
|
+
end
|
31
19
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
20
|
+
it 'should not create a new SQS client before every publish' do
|
21
|
+
expect(Aws::SQS::Client).to receive(:new).once
|
22
|
+
2.times { publisher.send(:queue, queue_name) }
|
23
|
+
end
|
36
24
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
25
|
+
it 'should lookup the queue when publishing' do
|
26
|
+
expect(sqs).to receive(:get_queue_url).with(queue_name: queue_name)
|
27
|
+
publisher.publish(queue_name, job)
|
28
|
+
end
|
41
29
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
30
|
+
it 'should create send an encoded message to the specified queue' do
|
31
|
+
expect(sqs).to receive(:send_message).with(queue_url: queue_url, message_body: job.to_json)
|
32
|
+
publisher.publish(queue_name,job)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should lookup multiple queues if specified' do
|
36
|
+
second_queue_name = queue_name + '2'
|
37
|
+
expect(sqs).to receive(:get_queue_url).with(queue_name: queue_name)
|
38
|
+
expect(sqs).to receive(:get_queue_url).with(queue_name: second_queue_name)
|
39
|
+
|
40
|
+
publisher.publish(queue_name, job)
|
41
|
+
publisher.publish(second_queue_name, job)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should only lookup a named queue once' do
|
45
|
+
expect(sqs).to receive(:get_queue_url).with(queue_name: queue_name).once
|
46
|
+
4.times { publisher.publish(queue_name, job) }
|
47
|
+
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
describe '#reset_connection!' do
|
50
|
+
it 'should empty API client connection pool after a call to reset_connection!' do
|
51
|
+
expect(Aws).to receive(:empty_connection_pools!)
|
52
|
+
Chore::Queues::SQS::Publisher.reset_connection!
|
53
|
+
publisher.send(:queue, queue_name)
|
52
54
|
end
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
publisher.queue(queue_name)
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'should not reset the connection between calls' do
|
63
|
-
sqs = publisher.queue(queue_name)
|
64
|
-
sqs.should be publisher.queue(queue_name)
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'should reconfigure sqs' do
|
68
|
-
Chore::Queues::SQS::Publisher.reset_connection!
|
69
|
-
AWS::SQS.should_receive(:new)
|
70
|
-
publisher.queue(queue_name)
|
71
|
-
end
|
56
|
+
# TODO: this test seems like basic identity (i.e. not even a real test)
|
57
|
+
it 'should not reset the connection between calls' do
|
58
|
+
expect(Aws).to receive(:empty_connection_pools!).once
|
59
|
+
Chore::Queues::SQS::Publisher.reset_connection!
|
60
|
+
4.times { publisher.send(:queue, queue_name ) }
|
72
61
|
end
|
73
62
|
end
|
74
63
|
end
|
@@ -1,53 +1,44 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
allow(fake_queue).to receive(:delete)
|
3
|
+
describe Chore::Queues::SQS do
|
4
|
+
include_context 'fake objects'
|
5
|
+
|
6
|
+
context "when managing queues" do
|
7
|
+
before(:each) do
|
8
|
+
allow(Aws::SQS::Client).to receive(:new).and_return(sqs)
|
9
|
+
allow(sqs).to receive(:create_queue).and_return(queue)
|
10
|
+
allow(sqs).to receive(:delete_queue).and_return(Struct.new(nil))
|
11
|
+
allow(queue).to receive(:delete).and_return(sqs.delete_queue(queue))
|
12
|
+
allow(Chore).to receive(:prefixed_queue_names).and_return([queue_name])
|
13
|
+
allow(queue).to receive(:delete)
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
it 'should create queues that are defined in its internal job name list' do
|
17
|
+
#Only one job defined in the spec suite
|
18
|
+
expect(sqs).to receive(:create_queue).with(queue_name: queue_name)
|
19
|
+
Chore::Queues::SQS.create_queues!
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
it 'should delete queues that are defined in its internal job name list' do
|
23
|
+
#Only one job defined in the spec suite
|
24
|
+
expect(sqs).to receive(:delete_queue).with(queue_url: sqs.get_queue_url.queue_url)
|
25
|
+
Chore::Queues::SQS.delete_queues!
|
26
|
+
end
|
23
27
|
|
24
|
-
|
25
|
-
|
26
|
-
expect(
|
27
|
-
Chore::Queues::SQS.create_queues!
|
28
|
+
context 'and checking for existing queues' do
|
29
|
+
it 'checks for existing queues' do
|
30
|
+
expect(described_class).to receive(:existing_queues).and_return([])
|
31
|
+
Chore::Queues::SQS.create_queues!(true)
|
28
32
|
end
|
29
33
|
|
30
|
-
it '
|
31
|
-
|
32
|
-
expect(
|
33
|
-
Chore::Queues::SQS.delete_queues!
|
34
|
+
it 'raises an error if a queue does exist' do
|
35
|
+
allow(described_class).to receive(:existing_queues).and_return([queue_name])
|
36
|
+
expect{Chore::Queues::SQS.create_queues!(true)}.to raise_error(RuntimeError)
|
34
37
|
end
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
Chore::Queues::SQS.create_queues!(true)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'raises an error if a queue does exist' do
|
43
|
-
allow(described_class).to receive(:existing_queues).and_return([queue_name])
|
44
|
-
expect{Chore::Queues::SQS.create_queues!(true)}.to raise_error(RuntimeError)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'does not raise an error if a queue does not exist' do
|
48
|
-
allow(described_class).to receive(:existing_queues).and_return([])
|
49
|
-
expect{Chore::Queues::SQS.create_queues!(true)}.not_to raise_error
|
50
|
-
end
|
39
|
+
it 'does not raise an error if a queue does not exist' do
|
40
|
+
allow(described_class).to receive(:existing_queues).and_return([])
|
41
|
+
expect{Chore::Queues::SQS.create_queues!(true)}.not_to raise_error
|
51
42
|
end
|
52
43
|
end
|
53
44
|
end
|
@@ -11,13 +11,13 @@ describe Chore::Strategy::SingleConsumerStrategy do
|
|
11
11
|
fetcher.stub(:manager) { manager }
|
12
12
|
Chore.config.stub(:queues).and_return(test_queues)
|
13
13
|
Chore.config.stub(:consumer).and_return(consumer)
|
14
|
-
|
14
|
+
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should consume and then assign a message" do
|
18
18
|
consumer.should_receive(:new).with(test_queues.first).and_return(consumer)
|
19
|
-
consumer.should_receive(:consume).and_yield(1, 'test-queue', 60, "test", 0)
|
20
|
-
manager.should_receive(:assign).with(Chore::UnitOfWork.new(1, 'test-queue', 60, "test", 0, consumer))
|
19
|
+
consumer.should_receive(:consume).and_yield(1, nil, 'test-queue', 60, "test", 0)
|
20
|
+
manager.should_receive(:assign).with(Chore::UnitOfWork.new(1, nil, 'test-queue', 60, "test", 0, consumer))
|
21
21
|
strategy.fetch
|
22
22
|
end
|
23
23
|
end
|
@@ -29,8 +29,8 @@ describe Chore::Strategy::ThreadedConsumerStrategy do
|
|
29
29
|
before(:each) do
|
30
30
|
fetcher.stub(:consumers) { [consumer] }
|
31
31
|
fetcher.stub(:manager) { manager }
|
32
|
-
Chore.configure do |c|
|
33
|
-
c.queues = ['test']
|
32
|
+
Chore.configure do |c|
|
33
|
+
c.queues = ['test']
|
34
34
|
c.consumer = consumer
|
35
35
|
c.batch_size = batch_size
|
36
36
|
end
|
@@ -40,7 +40,7 @@ describe Chore::Strategy::ThreadedConsumerStrategy do
|
|
40
40
|
let(:batch_size) { 2 }
|
41
41
|
|
42
42
|
it "should queue but not assign the message" do
|
43
|
-
consumer.any_instance.should_receive(:consume).and_yield(1, 'test-queue', 60, "test", 0)
|
43
|
+
consumer.any_instance.should_receive(:consume).and_yield(1, nil, 'test-queue', 60, "test", 0)
|
44
44
|
strategy.fetch
|
45
45
|
strategy.batcher.batch.size.should == 1
|
46
46
|
|
@@ -60,7 +60,7 @@ describe Chore::Strategy::ThreadedConsumerStrategy do
|
|
60
60
|
|
61
61
|
it "should assign the batch" do
|
62
62
|
manager.should_receive(:assign)
|
63
|
-
consumer.any_instance.should_receive(:consume).and_yield(1, 'test-queue', 60, "test", 0)
|
63
|
+
consumer.any_instance.should_receive(:consume).and_yield(1, nil, 'test-queue', 60, "test", 0)
|
64
64
|
strategy.fetch
|
65
65
|
strategy.batcher.batch.size.should == 0
|
66
66
|
end
|
@@ -90,8 +90,8 @@ describe Chore::Strategy::ThreadedConsumerStrategy do
|
|
90
90
|
|
91
91
|
before do
|
92
92
|
fetcher.stub(:consumers) { [bad_consumer] }
|
93
|
-
Chore.configure do |c|
|
94
|
-
c.queues = ['test']
|
93
|
+
Chore.configure do |c|
|
94
|
+
c.queues = ['test']
|
95
95
|
c.consumer = bad_consumer
|
96
96
|
c.batch_size = batch_size
|
97
97
|
c.threads_per_queue = 1
|
@@ -13,6 +13,7 @@ describe Chore::Strategy::ForkedWorkerStrategy do
|
|
13
13
|
let(:job) do
|
14
14
|
Chore::UnitOfWork.new(
|
15
15
|
SecureRandom.uuid,
|
16
|
+
nil,
|
16
17
|
'test',
|
17
18
|
job_timeout,
|
18
19
|
Chore::Encoder::JsonEncoder.encode(TestJob.job_hash([1,2,"3"])),
|
@@ -296,4 +297,3 @@ describe Chore::Strategy::ForkedWorkerStrategy do
|
|
296
297
|
end
|
297
298
|
end
|
298
299
|
end
|
299
|
-
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Chore::Strategy::SingleWorkerStrategy do
|
4
4
|
let(:manager) { double('Manager') }
|
5
5
|
let(:job_timeout) { 60 }
|
6
|
-
let(:job) { Chore::UnitOfWork.new(SecureRandom.uuid, 'test', job_timeout, Chore::Encoder::JsonEncoder.encode(TestJob.job_hash([1,2,"3"])), 0) }
|
6
|
+
let(:job) { Chore::UnitOfWork.new(SecureRandom.uuid, nil, 'test', job_timeout, Chore::Encoder::JsonEncoder.encode(TestJob.job_hash([1,2,"3"])), 0) }
|
7
7
|
subject { described_class.new(manager) }
|
8
8
|
|
9
9
|
describe '#stop!' do
|
data/spec/chore/worker_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe Chore::Worker do
|
|
23
23
|
:publisher => FakePublisher,
|
24
24
|
:max_attempts => 100,
|
25
25
|
:dedupe_lambda => lambda { |first, second, third| first }
|
26
|
-
|
26
|
+
|
27
27
|
def perform(first, second, third)
|
28
28
|
return second
|
29
29
|
end
|
@@ -35,7 +35,7 @@ describe Chore::Worker do
|
|
35
35
|
:publisher => FakePublisher,
|
36
36
|
:max_attempts => 100,
|
37
37
|
:dedupe_lambda => lambda { |first, second, third| first }
|
38
|
-
|
38
|
+
|
39
39
|
def perform(first, second)
|
40
40
|
return second
|
41
41
|
end
|
@@ -52,9 +52,9 @@ describe Chore::Worker do
|
|
52
52
|
|
53
53
|
shared_examples_for "a worker" do
|
54
54
|
it 'processing a single job' do
|
55
|
-
work = Chore::UnitOfWork.new('1', 'test', 60, encoded_job, 0, consumer)
|
55
|
+
work = Chore::UnitOfWork.new('1', nil, 'test', 60, encoded_job, 0, consumer)
|
56
56
|
SimpleJob.should_receive(:perform).with(*payload)
|
57
|
-
consumer.should_receive(:complete).with('1')
|
57
|
+
consumer.should_receive(:complete).with('1', nil)
|
58
58
|
w = Chore::Worker.new(work, {:payload_handler => payload_handler})
|
59
59
|
w.start
|
60
60
|
end
|
@@ -62,7 +62,7 @@ describe Chore::Worker do
|
|
62
62
|
it 'processing multiple jobs' do
|
63
63
|
work = []
|
64
64
|
10.times do |i|
|
65
|
-
work << Chore::UnitOfWork.new(i, 'test', 60, encoded_job, 0, consumer)
|
65
|
+
work << Chore::UnitOfWork.new(i, nil, 'test', 60, encoded_job, 0, consumer)
|
66
66
|
end
|
67
67
|
SimpleJob.should_receive(:perform).exactly(10).times
|
68
68
|
consumer.should_receive(:complete).exactly(10).times
|
@@ -77,7 +77,7 @@ describe Chore::Worker do
|
|
77
77
|
it 'should call complete for each unique value' do
|
78
78
|
allow(consumer).to receive(:duplicate_message?).and_return(false)
|
79
79
|
work = []
|
80
|
-
work << Chore::UnitOfWork.new(1, 'dedupe_test', 60, Chore::Encoder::JsonEncoder.encode(SimpleDedupeJob.job_hash([rand,2,'3'])), 0, consumer)
|
80
|
+
work << Chore::UnitOfWork.new(1, nil, 'dedupe_test', 60, Chore::Encoder::JsonEncoder.encode(SimpleDedupeJob.job_hash([rand,2,'3'])), 0, consumer)
|
81
81
|
SimpleDedupeJob.should_receive(:perform).exactly(1).times
|
82
82
|
consumer.should_receive(:complete).exactly(1).times
|
83
83
|
Chore::Worker.start(work, {:payload_handler => payload_handler})
|
@@ -87,9 +87,9 @@ describe Chore::Worker do
|
|
87
87
|
context 'when the dedupe lambda does not take the same number of arguments as perform' do
|
88
88
|
it 'should raise an error and not complete the job' do
|
89
89
|
work = []
|
90
|
-
work << Chore::UnitOfWork.new(1, 'invalid_dedupe_test', 60, Chore::Encoder::JsonEncoder.encode(InvalidDedupeJob.job_hash([rand,2,'3'])), 0, consumer)
|
91
|
-
work << Chore::UnitOfWork.new(2, 'invalid_dedupe_test', 60, Chore::Encoder::JsonEncoder.encode(InvalidDedupeJob.job_hash([rand,2,'3'])), 0, consumer)
|
92
|
-
work << Chore::UnitOfWork.new(1, 'invalid_dedupe_test', 60, Chore::Encoder::JsonEncoder.encode(InvalidDedupeJob.job_hash([rand,2,'3'])), 0, consumer)
|
90
|
+
work << Chore::UnitOfWork.new(1, nil, 'invalid_dedupe_test', 60, Chore::Encoder::JsonEncoder.encode(InvalidDedupeJob.job_hash([rand,2,'3'])), 0, consumer)
|
91
|
+
work << Chore::UnitOfWork.new(2, nil, 'invalid_dedupe_test', 60, Chore::Encoder::JsonEncoder.encode(InvalidDedupeJob.job_hash([rand,2,'3'])), 0, consumer)
|
92
|
+
work << Chore::UnitOfWork.new(1, nil, 'invalid_dedupe_test', 60, Chore::Encoder::JsonEncoder.encode(InvalidDedupeJob.job_hash([rand,2,'3'])), 0, consumer)
|
93
93
|
consumer.should_not_receive(:complete)
|
94
94
|
Chore::Worker.start(work, {:payload_handler => payload_handler})
|
95
95
|
end
|
@@ -109,7 +109,7 @@ describe Chore::Worker do
|
|
109
109
|
let(:queue_timeouts) { [10, 20, 30] }
|
110
110
|
let(:work) do
|
111
111
|
queue_timeouts.map do |queue_timeout|
|
112
|
-
Chore::UnitOfWork.new('1', 'test', queue_timeout, Chore::Encoder::JsonEncoder.encode(job), 0, consumer)
|
112
|
+
Chore::UnitOfWork.new('1', nil, 'test', queue_timeout, Chore::Encoder::JsonEncoder.encode(job), 0, consumer)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
let(:worker) do
|
@@ -140,14 +140,14 @@ describe Chore::Worker do
|
|
140
140
|
let(:job) { "Not-A-Valid-Json-String" }
|
141
141
|
|
142
142
|
it 'should fail cleanly' do
|
143
|
-
work = Chore::UnitOfWork.new(2,'test',60,job,0,consumer)
|
143
|
+
work = Chore::UnitOfWork.new(2,nil,'test',60,job,0,consumer)
|
144
144
|
consumer.should_not_receive(:complete)
|
145
145
|
Chore.should_receive(:run_hooks_for).with(:on_failure, job, anything())
|
146
146
|
Chore::Worker.start(work)
|
147
147
|
end
|
148
148
|
|
149
149
|
it 'should reject job' do
|
150
|
-
work = Chore::UnitOfWork.new(2,'test',60,job,0,consumer)
|
150
|
+
work = Chore::UnitOfWork.new(2,nil,'test',60,job,0,consumer)
|
151
151
|
consumer.should_receive(:reject).with(2)
|
152
152
|
Chore::Worker.start(work)
|
153
153
|
end
|
@@ -158,14 +158,14 @@ describe Chore::Worker do
|
|
158
158
|
end
|
159
159
|
|
160
160
|
it 'should permanently fail' do
|
161
|
-
work = Chore::UnitOfWork.new(2,'test',60,job,9,consumer)
|
161
|
+
work = Chore::UnitOfWork.new(2,nil,'test',60,job,9,consumer)
|
162
162
|
Chore.should_receive(:run_hooks_for).with(:on_permanent_failure, 'test', job, anything())
|
163
163
|
Chore::Worker.start(work)
|
164
164
|
end
|
165
165
|
|
166
166
|
it 'should mark the item as completed' do
|
167
|
-
work = Chore::UnitOfWork.new(2,'test',60,job,9,consumer)
|
168
|
-
consumer.should_receive(:complete).with(2)
|
167
|
+
work = Chore::UnitOfWork.new(2,nil,'test',60,job,9,consumer)
|
168
|
+
consumer.should_receive(:complete).with(2, nil)
|
169
169
|
Chore::Worker.start(work)
|
170
170
|
end
|
171
171
|
end
|
@@ -181,7 +181,7 @@ describe Chore::Worker do
|
|
181
181
|
end
|
182
182
|
|
183
183
|
it 'should fail cleanly' do
|
184
|
-
work = Chore::UnitOfWork.new(2,'test',60,encoded_job,0,consumer)
|
184
|
+
work = Chore::UnitOfWork.new(2,nil,'test',60,encoded_job,0,consumer)
|
185
185
|
consumer.should_not_receive(:complete)
|
186
186
|
SimpleJob.should_receive(:run_hooks_for).with(:on_failure, parsed_job, anything())
|
187
187
|
|
@@ -189,7 +189,7 @@ describe Chore::Worker do
|
|
189
189
|
end
|
190
190
|
|
191
191
|
it 'should reject job' do
|
192
|
-
work = Chore::UnitOfWork.new(2,'test',60,encoded_job,0,consumer)
|
192
|
+
work = Chore::UnitOfWork.new(2,nil,'test',60,encoded_job,0,consumer)
|
193
193
|
consumer.should_receive(:reject).with(2)
|
194
194
|
|
195
195
|
Chore::Worker.start(work)
|
@@ -197,14 +197,14 @@ describe Chore::Worker do
|
|
197
197
|
|
198
198
|
context 'more than the maximum allowed times' do
|
199
199
|
it 'should permanently fail' do
|
200
|
-
work = Chore::UnitOfWork.new(2,'test',60,encoded_job,999,consumer)
|
200
|
+
work = Chore::UnitOfWork.new(2,nil,'test',60,encoded_job,999,consumer)
|
201
201
|
SimpleJob.should_receive(:run_hooks_for).with(:on_permanent_failure, 'test', parsed_job, anything())
|
202
202
|
Chore::Worker.start(work)
|
203
203
|
end
|
204
204
|
|
205
205
|
it 'should mark the item as completed' do
|
206
|
-
work = Chore::UnitOfWork.new(2,'test',60,encoded_job,999,consumer)
|
207
|
-
consumer.should_receive(:complete).with(2)
|
206
|
+
work = Chore::UnitOfWork.new(2,nil,'test',60,encoded_job,999,consumer)
|
207
|
+
consumer.should_receive(:complete).with(2, nil)
|
208
208
|
Chore::Worker.start(work)
|
209
209
|
end
|
210
210
|
end
|
@@ -214,7 +214,7 @@ describe Chore::Worker do
|
|
214
214
|
describe 'delaying retries' do
|
215
215
|
let(:encoded_job) { Chore::Encoder::JsonEncoder.encode(job) }
|
216
216
|
let(:parsed_job) { JSON.parse(encoded_job) }
|
217
|
-
let(:work) { Chore::UnitOfWork.new(2, 'test', 60, encoded_job, 0, consumer) }
|
217
|
+
let(:work) { Chore::UnitOfWork.new(2, nil, 'test', 60, encoded_job, 0, consumer) }
|
218
218
|
|
219
219
|
before(:each) do
|
220
220
|
SimpleJob.options[:backoff] = lambda { |work| work.current_attempt }
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
describe Chore::Queues::SQS do
|
2
|
+
RSpec.shared_context 'fake objects' do
|
3
|
+
let(:queue_name) { 'test_queue' }
|
4
|
+
let(:queue_url) { "http://amazon.sqs.url/queues/#{queue_name}" }
|
5
|
+
|
6
|
+
let(:queue) do
|
7
|
+
double(Aws::SQS::Queue,
|
8
|
+
attributes: {'VisibilityTimeout' => rand(10)}
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:sqs) do
|
13
|
+
double(Aws::SQS::Client,
|
14
|
+
get_queue_url: double(Aws::SQS::Types::GetQueueUrlResult, :queue_url => queue_url),
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|