rabbit_jobs 0.10.3 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/build +1 -0
- data/lib/rabbit_jobs.rb +4 -10
- data/lib/rabbit_jobs/configuration.rb +1 -3
- data/lib/rabbit_jobs/consumer/job_consumer.rb +0 -2
- data/lib/rabbit_jobs/job.rb +1 -2
- data/lib/rabbit_jobs/tasks.rb +2 -1
- data/lib/rabbit_jobs/version.rb +1 -1
- data/lib/tasks/rabbit_jobs.rake +0 -1
- data/rabbit_jobs.gemspec +2 -2
- data/spec/integration/publisher_spec.rb +2 -11
- metadata +30 -37
- data/lib/rabbit_jobs/helpers.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e103e5d76bc1c6aa3b69edade6717f009ba607e
|
4
|
+
data.tar.gz: dfc322f356dbc23681affc070d0d1784c8901478
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7c82cd1e03bad53b57eb07b56d3a21e1eae2ac937aa4ae907ffadded8fa4ad6e430a377cae9831daccd138f5626de4e5e1833393fb041a41803b6a70101f3f7
|
7
|
+
data.tar.gz: cfe726f5df67c78192b6b4fb4e04a9fdbc235a80b89fe4bc7c3a585e982ba5df0893748475ca2dc15f14bf4ccbf45028a73b24a268e121a81ba646aaa3886ab4
|
data/build
CHANGED
data/lib/rabbit_jobs.rb
CHANGED
@@ -1,21 +1,15 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'logger'
|
3
|
-
require 'rake'
|
4
3
|
require 'json'
|
5
|
-
require 'digest/md5'
|
6
4
|
require 'bunny'
|
7
|
-
require '
|
8
|
-
require 'rufus/scheduler'
|
9
|
-
require 'thwait'
|
5
|
+
require 'rufus-scheduler'
|
10
6
|
require 'yaml'
|
11
|
-
require 'active_support'
|
12
|
-
require 'active_support/core_ext'
|
7
|
+
require 'active_support/core_ext/object/blank'
|
8
|
+
require 'active_support/core_ext/hash'
|
9
|
+
require 'active_support/core_ext/string/inflections'
|
13
10
|
|
14
11
|
require 'rabbit_jobs/version'
|
15
|
-
|
16
|
-
require 'rabbit_jobs/helpers'
|
17
12
|
require 'rabbit_jobs/configuration'
|
18
|
-
|
19
13
|
require 'rabbit_jobs/consumer/job_consumer'
|
20
14
|
require 'rabbit_jobs/job'
|
21
15
|
require 'rabbit_jobs/publisher'
|
@@ -33,8 +33,6 @@ module RabbitJobs
|
|
33
33
|
end
|
34
34
|
|
35
35
|
class Configuration
|
36
|
-
include Helpers
|
37
|
-
|
38
36
|
DEFAULT_EXCHANGE_PARAMS = {
|
39
37
|
auto_delete: false,
|
40
38
|
durable: true
|
@@ -123,7 +121,7 @@ module RabbitJobs
|
|
123
121
|
self.send(m, yaml[m])
|
124
122
|
end
|
125
123
|
yaml['queues'].each do |name, params|
|
126
|
-
queue name, symbolize_keys
|
124
|
+
queue name, params.symbolize_keys || {}
|
127
125
|
end
|
128
126
|
end
|
129
127
|
|
data/lib/rabbit_jobs/job.rb
CHANGED
@@ -3,7 +3,6 @@ require 'benchmark'
|
|
3
3
|
|
4
4
|
module RabbitJobs
|
5
5
|
module Job
|
6
|
-
include RabbitJobs::Helpers
|
7
6
|
extend self
|
8
7
|
|
9
8
|
def self.included(base)
|
@@ -139,7 +138,7 @@ module RabbitJobs
|
|
139
138
|
def self.parse(payload)
|
140
139
|
begin
|
141
140
|
encoded = JSON.parse(payload)
|
142
|
-
job_klass =
|
141
|
+
job_klass = encoded['class'].to_s.constantize
|
143
142
|
job = job_klass.new(*encoded['params'])
|
144
143
|
job.opts = encoded['opts']
|
145
144
|
job
|
data/lib/rabbit_jobs/tasks.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rabbit_jobs'
|
2
|
+
require 'rake'
|
2
3
|
|
3
4
|
def rails_env
|
4
5
|
$my_rails_env ||= defined?(Rails) ? Rails.env : (ENV['RAILS_ENV'] || 'development')
|
@@ -17,7 +18,7 @@ end
|
|
17
18
|
|
18
19
|
namespace :rj do
|
19
20
|
task :environment do
|
20
|
-
Rails.application.require_environment!
|
21
|
+
Rails.application.require_environment! if defined?(Rails)
|
21
22
|
end
|
22
23
|
|
23
24
|
desc "Start a Rabbit Jobs worker"
|
data/lib/rabbit_jobs/version.rb
CHANGED
data/lib/tasks/rabbit_jobs.rake
CHANGED
data/rabbit_jobs.gemspec
CHANGED
@@ -22,9 +22,9 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_dependency "bunny", "~> 1.0"
|
23
23
|
spec.add_dependency "rake"
|
24
24
|
spec.add_dependency "rufus-scheduler", "~> 3.0"
|
25
|
-
spec.add_dependency "
|
25
|
+
spec.add_dependency "activesupport", "~> 4.0"
|
26
26
|
|
27
|
-
spec.add_development_dependency "bundler"
|
27
|
+
spec.add_development_dependency "bundler"
|
28
28
|
# spec.add_development_dependency "rake"
|
29
29
|
spec.add_development_dependency "timecop"
|
30
30
|
spec.add_development_dependency "rspec"
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
require 'spec_helper'
|
3
2
|
require 'json'
|
4
3
|
require 'benchmark'
|
@@ -18,13 +17,11 @@ describe RabbitJobs::Publisher do
|
|
18
17
|
|
19
18
|
it 'should publish message to queue' do
|
20
19
|
RJ.publish_to(:rspec_queue, TestJob, 'some', 'other', 'params')
|
21
|
-
# sleep 0.1
|
22
20
|
RJ.purge_queue('rspec_queue').should == 1
|
23
21
|
end
|
24
22
|
|
25
23
|
it 'should accept symbol as queue name' do
|
26
24
|
RJ.publish_to(:rspec_queue, TestJob)
|
27
|
-
# sleep 0.1
|
28
25
|
RJ.purge_queue('rspec_queue').should == 1
|
29
26
|
end
|
30
27
|
|
@@ -32,26 +29,20 @@ describe RabbitJobs::Publisher do
|
|
32
29
|
RJ.publish_to(:rspec_queue, TestJob)
|
33
30
|
RJ.publish_to(:rspec_queue2, TestJob)
|
34
31
|
RJ.publish_to(:rspec_queue3, TestJob)
|
35
|
-
# sleep 0.1
|
36
32
|
RJ.purge_queue(:rspec_queue, :rspec_queue2, :rspec_queue3).should == 3
|
37
33
|
end
|
38
34
|
|
39
35
|
it 'should publish job with *params' do
|
40
36
|
RJ.publish_to(:rspec_queue, JobWithArgsArray, 'first value', :some_symbol, 123, 'and string')
|
41
|
-
# sleep 0.1
|
42
37
|
RJ.purge_queue(:rspec_queue).should == 1
|
43
38
|
end
|
44
39
|
|
45
40
|
it 'should publish 1000 messages in one second' do
|
46
41
|
count = 1000
|
47
|
-
published = 0
|
48
42
|
time = Benchmark.measure {
|
49
|
-
count.times {
|
50
|
-
RJ.publish_to(:rspec_queue, TestJob)
|
51
|
-
}
|
52
|
-
# sleep 0.1
|
43
|
+
count.times { RJ.publish_to(:rspec_queue, TestJob) }
|
53
44
|
removed = RJ.purge_queue(:rspec_queue, :rspec_queue2, :rspec_queue3)
|
54
|
-
removed.should ==
|
45
|
+
removed.should == count
|
55
46
|
}
|
56
47
|
puts time
|
57
48
|
end
|
metadata
CHANGED
@@ -1,145 +1,139 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabbit_jobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.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-02-
|
11
|
+
date: 2014-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.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
26
|
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rufus-scheduler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: activesupport
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
- - <
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: '5.0'
|
61
|
+
version: '4.0'
|
65
62
|
type: :runtime
|
66
63
|
prerelease: false
|
67
64
|
version_requirements: !ruby/object:Gem::Requirement
|
68
65
|
requirements:
|
69
|
-
- -
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
version: '3.2'
|
72
|
-
- - <
|
66
|
+
- - "~>"
|
73
67
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
68
|
+
version: '4.0'
|
75
69
|
- !ruby/object:Gem::Dependency
|
76
70
|
name: bundler
|
77
71
|
requirement: !ruby/object:Gem::Requirement
|
78
72
|
requirements:
|
79
|
-
- -
|
73
|
+
- - ">="
|
80
74
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
75
|
+
version: '0'
|
82
76
|
type: :development
|
83
77
|
prerelease: false
|
84
78
|
version_requirements: !ruby/object:Gem::Requirement
|
85
79
|
requirements:
|
86
|
-
- -
|
80
|
+
- - ">="
|
87
81
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
82
|
+
version: '0'
|
89
83
|
- !ruby/object:Gem::Dependency
|
90
84
|
name: timecop
|
91
85
|
requirement: !ruby/object:Gem::Requirement
|
92
86
|
requirements:
|
93
|
-
- -
|
87
|
+
- - ">="
|
94
88
|
- !ruby/object:Gem::Version
|
95
89
|
version: '0'
|
96
90
|
type: :development
|
97
91
|
prerelease: false
|
98
92
|
version_requirements: !ruby/object:Gem::Requirement
|
99
93
|
requirements:
|
100
|
-
- -
|
94
|
+
- - ">="
|
101
95
|
- !ruby/object:Gem::Version
|
102
96
|
version: '0'
|
103
97
|
- !ruby/object:Gem::Dependency
|
104
98
|
name: rspec
|
105
99
|
requirement: !ruby/object:Gem::Requirement
|
106
100
|
requirements:
|
107
|
-
- -
|
101
|
+
- - ">="
|
108
102
|
- !ruby/object:Gem::Version
|
109
103
|
version: '0'
|
110
104
|
type: :development
|
111
105
|
prerelease: false
|
112
106
|
version_requirements: !ruby/object:Gem::Requirement
|
113
107
|
requirements:
|
114
|
-
- -
|
108
|
+
- - ">="
|
115
109
|
- !ruby/object:Gem::Version
|
116
110
|
version: '0'
|
117
111
|
- !ruby/object:Gem::Dependency
|
118
112
|
name: rr
|
119
113
|
requirement: !ruby/object:Gem::Requirement
|
120
114
|
requirements:
|
121
|
-
- -
|
115
|
+
- - ">="
|
122
116
|
- !ruby/object:Gem::Version
|
123
117
|
version: '0'
|
124
118
|
type: :development
|
125
119
|
prerelease: false
|
126
120
|
version_requirements: !ruby/object:Gem::Requirement
|
127
121
|
requirements:
|
128
|
-
- -
|
122
|
+
- - ">="
|
129
123
|
- !ruby/object:Gem::Version
|
130
124
|
version: '0'
|
131
125
|
- !ruby/object:Gem::Dependency
|
132
126
|
name: simplecov
|
133
127
|
requirement: !ruby/object:Gem::Requirement
|
134
128
|
requirements:
|
135
|
-
- -
|
129
|
+
- - ">="
|
136
130
|
- !ruby/object:Gem::Version
|
137
131
|
version: '0'
|
138
132
|
type: :development
|
139
133
|
prerelease: false
|
140
134
|
version_requirements: !ruby/object:Gem::Requirement
|
141
135
|
requirements:
|
142
|
-
- -
|
136
|
+
- - ">="
|
143
137
|
- !ruby/object:Gem::Version
|
144
138
|
version: '0'
|
145
139
|
description: Background jobs on RabbitMQ
|
@@ -149,8 +143,8 @@ executables: []
|
|
149
143
|
extensions: []
|
150
144
|
extra_rdoc_files: []
|
151
145
|
files:
|
152
|
-
- .gitignore
|
153
|
-
- .rspec
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
154
148
|
- Gemfile
|
155
149
|
- LICENSE
|
156
150
|
- LICENSE.txt
|
@@ -165,7 +159,6 @@ files:
|
|
165
159
|
- lib/rabbit_jobs.rb
|
166
160
|
- lib/rabbit_jobs/configuration.rb
|
167
161
|
- lib/rabbit_jobs/consumer/job_consumer.rb
|
168
|
-
- lib/rabbit_jobs/helpers.rb
|
169
162
|
- lib/rabbit_jobs/job.rb
|
170
163
|
- lib/rabbit_jobs/main_loop.rb
|
171
164
|
- lib/rabbit_jobs/publisher.rb
|
@@ -197,17 +190,17 @@ require_paths:
|
|
197
190
|
- lib
|
198
191
|
required_ruby_version: !ruby/object:Gem::Requirement
|
199
192
|
requirements:
|
200
|
-
- -
|
193
|
+
- - ">="
|
201
194
|
- !ruby/object:Gem::Version
|
202
195
|
version: '0'
|
203
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
204
197
|
requirements:
|
205
|
-
- -
|
198
|
+
- - ">="
|
206
199
|
- !ruby/object:Gem::Version
|
207
200
|
version: '0'
|
208
201
|
requirements: []
|
209
202
|
rubyforge_project:
|
210
|
-
rubygems_version: 2.
|
203
|
+
rubygems_version: 2.2.1
|
211
204
|
signing_key:
|
212
205
|
specification_version: 4
|
213
206
|
summary: Background jobs on RabbitMQ
|
data/lib/rabbit_jobs/helpers.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
|
3
|
-
module RabbitJobs
|
4
|
-
module Helpers
|
5
|
-
def symbolize_keys!(hash)
|
6
|
-
hash.inject({}) do |options, (key, value)|
|
7
|
-
options[(key.to_sym rescue key) || key] = value
|
8
|
-
options
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
# Tries to find a constant with the name specified in the argument string:
|
14
|
-
#
|
15
|
-
# constantize("Module") # => Module
|
16
|
-
# constantize("Test::Unit") # => Test::Unit
|
17
|
-
#
|
18
|
-
# The name is assumed to be the one of a top-level constant, no matter
|
19
|
-
# whether it starts with "::" or not. No lexical context is taken into
|
20
|
-
# account:
|
21
|
-
#
|
22
|
-
# C = 'outside'
|
23
|
-
# module M
|
24
|
-
# C = 'inside'
|
25
|
-
# C # => 'inside'
|
26
|
-
# constantize("C") # => 'outside', same as ::C
|
27
|
-
# end
|
28
|
-
#
|
29
|
-
# NameError is raised when the constant is unknown.
|
30
|
-
def constantize(camel_cased_word)
|
31
|
-
camel_cased_word = camel_cased_word.to_s
|
32
|
-
|
33
|
-
if camel_cased_word.include?('-')
|
34
|
-
camel_cased_word = classify(camel_cased_word)
|
35
|
-
end
|
36
|
-
|
37
|
-
names = camel_cased_word.split('::')
|
38
|
-
names.shift if names.empty? || names.first.empty?
|
39
|
-
|
40
|
-
constant = Object
|
41
|
-
names.each do |name|
|
42
|
-
args = Module.method(:const_get).arity != 1 ? [false] : []
|
43
|
-
|
44
|
-
if constant.const_defined?(name, *args)
|
45
|
-
constant = constant.const_get(name)
|
46
|
-
else
|
47
|
-
constant = constant.const_missing(name)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
constant
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|