rabbit_jobs 0.11.5 → 0.12.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 +4 -4
- data/Rakefile +1 -1
- data/build +2 -6
- data/examples/client +1 -2
- data/examples/configuration.rb +3 -3
- data/examples/worker +1 -1
- data/lib/rabbit_jobs.rb +52 -42
- data/lib/rabbit_jobs/amqp_transport.rb +33 -0
- data/lib/rabbit_jobs/configuration.rb +15 -51
- data/lib/rabbit_jobs/consumer/job_consumer.rb +7 -17
- data/lib/rabbit_jobs/job.rb +102 -127
- data/lib/rabbit_jobs/main_loop.rb +25 -24
- data/lib/rabbit_jobs/publisher.rb +19 -17
- data/lib/rabbit_jobs/publisher/amqp.rb +37 -40
- data/lib/rabbit_jobs/publisher/base.rb +26 -8
- data/lib/rabbit_jobs/publisher/sync.rb +11 -4
- data/lib/rabbit_jobs/publisher/test.rb +10 -9
- data/lib/rabbit_jobs/scheduler.rb +25 -39
- data/lib/rabbit_jobs/tasks.rb +8 -8
- data/lib/rabbit_jobs/version.rb +1 -3
- data/lib/rabbit_jobs/worker.rb +26 -45
- data/lib/tasks/rabbit_jobs.rake +1 -1
- data/rabbit_jobs.gemspec +20 -19
- data/spec/fixtures/config.yml +2 -2
- data/spec/fixtures/jobs.rb +1 -3
- data/spec/integration/publisher_spec.rb +30 -9
- data/spec/integration/scheduler_spec.rb +10 -5
- data/spec/integration/worker_spec.rb +10 -3
- data/spec/spec_helper.rb +7 -3
- data/spec/unit/configuration_spec.rb +37 -18
- data/spec/unit/job_consumer_spec.rb +11 -10
- data/spec/unit/job_spec.rb +12 -14
- data/spec/unit/rabbit_jobs_spec.rb +5 -6
- data/spec/unit/worker_spec.rb +6 -7
- metadata +20 -5
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
3
|
describe RabbitJobs::Consumer::JobConsumer do
|
@@ -11,11 +10,13 @@ describe RabbitJobs::Consumer::JobConsumer do
|
|
11
10
|
mock(RJ::Job).parse(payload) { job }
|
12
11
|
consumer.process_message(:delivery_info, :properties, payload)
|
13
12
|
end
|
13
|
+
|
14
14
|
it 'reports parsing errors' do
|
15
|
-
payload =
|
15
|
+
payload = 'some bad json data'
|
16
16
|
mock(consumer).report_error(:parsing_error, payload)
|
17
17
|
consumer.process_message(:delivery_info, :properties, payload).should == true
|
18
18
|
end
|
19
|
+
|
19
20
|
it 'skips expired jobs' do
|
20
21
|
payload = RJ::Job.serialize(TestJob)
|
21
22
|
job
|
@@ -35,22 +36,22 @@ describe RabbitJobs::Consumer::JobConsumer do
|
|
35
36
|
end
|
36
37
|
|
37
38
|
describe '#report_error' do
|
38
|
-
it
|
39
|
-
|
39
|
+
it 'accepts error type :not_found' do
|
40
|
+
-> { consumer.report_error(:not_found, 'klass_name') }.should_not raise_error
|
40
41
|
end
|
41
42
|
|
42
|
-
it
|
43
|
-
|
43
|
+
it 'accepts error type :parsing_error' do
|
44
|
+
-> { consumer.report_error(:parsing_error, 'payload data') }.should_not raise_error
|
44
45
|
end
|
45
46
|
|
46
|
-
it
|
47
|
+
it 'accepts error type :error' do
|
47
48
|
exception = nil
|
48
49
|
begin
|
49
|
-
|
50
|
-
rescue
|
50
|
+
fail 'testing'
|
51
|
+
rescue RuntimeError => e
|
51
52
|
exception = e
|
52
53
|
end
|
53
|
-
|
54
|
+
-> { consumer.report_error(:error, exception, 'payload data') }.should_not raise_error
|
54
55
|
end
|
55
56
|
end
|
56
57
|
end
|
data/spec/unit/job_spec.rb
CHANGED
@@ -1,35 +1,33 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
3
|
describe RabbitJobs::Job do
|
5
4
|
it 'should parse class and params' do
|
6
|
-
job = RabbitJobs::Job.parse({class: 'TestJob', params: [1,2,3]}.to_json)
|
7
|
-
job.
|
5
|
+
job, params = RabbitJobs::Job.parse({ class: 'TestJob', params: [1, 2, 3] }.to_json)
|
6
|
+
job.should be_is_a(TestJob)
|
7
|
+
params.should == [1, 2, 3]
|
8
8
|
end
|
9
9
|
|
10
|
-
it '
|
11
|
-
|
12
|
-
job.expires_in.should == 60*60
|
13
|
-
job.expires?.should == true
|
10
|
+
it 'understands expires_in option' do
|
11
|
+
JobWithExpire.expires_in.should eq 1.hour
|
14
12
|
end
|
15
13
|
|
16
14
|
context 'job expiration' do
|
17
15
|
it 'should expire job by expires_in option' do
|
18
|
-
job =
|
19
|
-
job.
|
16
|
+
job = JobWithExpire.new
|
17
|
+
job.created_at = 2.hours.ago.to_i
|
20
18
|
job.expired?.should == true
|
21
19
|
end
|
22
20
|
|
23
21
|
it 'should expire job by expires_in option in job class and current_time' do
|
24
|
-
job = JobWithExpire.new
|
25
|
-
job.
|
22
|
+
job = JobWithExpire.new
|
23
|
+
job.created_at = (Time.now - JobWithExpire.expires_in - 10).to_i
|
26
24
|
job.expired?.should == true
|
27
25
|
end
|
28
26
|
|
29
27
|
it 'should not be expired with default params' do
|
30
|
-
job = TestJob.new
|
31
|
-
job.
|
28
|
+
job = TestJob.new
|
29
|
+
job.created_at = (Time.now).to_i
|
32
30
|
job.expired?.should == false
|
33
31
|
end
|
34
32
|
end
|
35
|
-
end
|
33
|
+
end
|
@@ -1,12 +1,11 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
3
|
describe RabbitJobs do
|
5
4
|
it 'should pass publish methods to publisher' do
|
6
|
-
mock(RJ::Publisher).publish_to('default_queue', TestJob, nil, 1, 2,
|
7
|
-
RJ.publish_to('default_queue', TestJob, nil, 1, 2,
|
5
|
+
mock(RJ::Publisher).publish_to('default_queue', TestJob, nil, 1, 2, 'string')
|
6
|
+
RJ.publish_to('default_queue', TestJob, nil, 1, 2, 'string')
|
8
7
|
|
9
|
-
mock(RJ::Publisher).direct_publish_to('default_queue', 'hello',
|
10
|
-
RJ.direct_publish_to('default_queue', 'hello',
|
8
|
+
mock(RJ::Publisher).direct_publish_to('default_queue', 'hello', name: 'my_exchange')
|
9
|
+
RJ.direct_publish_to('default_queue', 'hello', name: 'my_exchange')
|
11
10
|
end
|
12
|
-
end
|
11
|
+
end
|
data/spec/unit/worker_spec.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
3
|
describe RabbitJobs::Worker do
|
@@ -6,7 +5,7 @@ describe RabbitJobs::Worker do
|
|
6
5
|
before(:each) do
|
7
6
|
RJ.configure do |c|
|
8
7
|
c.server 'amqp://localhost'
|
9
|
-
c.queue
|
8
|
+
c.queue 'default'
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
@@ -15,12 +14,12 @@ describe RabbitJobs::Worker do
|
|
15
14
|
describe '#consumer' do
|
16
15
|
it 'validates consumer type' do
|
17
16
|
old_consumer = worker.consumer
|
18
|
-
|
19
|
-
worker.consumer.should
|
17
|
+
-> { worker.consumer = 123 }.should raise_error
|
18
|
+
worker.consumer.should eq old_consumer
|
20
19
|
|
21
20
|
new_consumer = TestConsumer.new
|
22
|
-
|
23
|
-
worker.consumer.should
|
21
|
+
-> { worker.consumer = new_consumer }.should_not raise_error
|
22
|
+
worker.consumer.should eq new_consumer
|
24
23
|
end
|
25
24
|
end
|
26
|
-
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabbit_jobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Lazureykis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.6.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.6.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - '>='
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: codeclimate-test-reporter
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
description: Background jobs on RabbitMQ
|
140
154
|
email:
|
141
155
|
- lazureykis@gmail.com
|
@@ -157,6 +171,7 @@ files:
|
|
157
171
|
- examples/configuration.rb
|
158
172
|
- examples/worker
|
159
173
|
- lib/rabbit_jobs.rb
|
174
|
+
- lib/rabbit_jobs/amqp_transport.rb
|
160
175
|
- lib/rabbit_jobs/configuration.rb
|
161
176
|
- lib/rabbit_jobs/consumer/job_consumer.rb
|
162
177
|
- lib/rabbit_jobs/job.rb
|
@@ -204,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
219
|
version: '0'
|
205
220
|
requirements: []
|
206
221
|
rubyforge_project:
|
207
|
-
rubygems_version: 2.0.
|
222
|
+
rubygems_version: 2.0.14
|
208
223
|
signing_key:
|
209
224
|
specification_version: 4
|
210
225
|
summary: Background jobs on RabbitMQ
|