rabbit_jobs 0.7.4 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rabbit_jobs/publisher.rb +27 -18
- data/lib/rabbit_jobs/scheduler.rb +1 -1
- data/lib/rabbit_jobs/version.rb +1 -1
- metadata +15 -47
@@ -10,14 +10,6 @@ module RabbitJobs
|
|
10
10
|
module Publisher
|
11
11
|
extend self
|
12
12
|
|
13
|
-
def amqp_connection
|
14
|
-
Thread.current[:rj_publisher_connection] ||= AmqpHelper.prepare_connection
|
15
|
-
end
|
16
|
-
|
17
|
-
def amqp_channel
|
18
|
-
Thread.current[:rj_publisher_channel] ||= amqp_connection.create_channel
|
19
|
-
end
|
20
|
-
|
21
13
|
def cleanup
|
22
14
|
conn = Thread.current[:rj_publisher_connection]
|
23
15
|
conn.close if conn && conn.status != :not_connected
|
@@ -38,17 +30,8 @@ module RabbitJobs
|
|
38
30
|
end
|
39
31
|
|
40
32
|
def direct_publish_to(routing_key, payload, ex = {})
|
41
|
-
ex = {name: ex} if ex.is_a?(String)
|
42
|
-
raise ArgumentError.new("Need to pass exchange name") if ex.size > 0 && ex[:name].to_s.empty?
|
43
|
-
|
44
33
|
begin
|
45
|
-
exchange =
|
46
|
-
exchange_opts = Configuration::DEFAULT_EXCHANGE_PARAMS.merge(ex[:params] || {}).merge({type: (ex[:type] || :direct)})
|
47
|
-
amqp_channel.exchange(ex[:name].to_s, exchange_opts)
|
48
|
-
else
|
49
|
-
amqp_channel.default_exchange
|
50
|
-
end
|
51
|
-
|
34
|
+
exchange = get_exchange(ex)
|
52
35
|
exchange.publish(payload, Configuration::DEFAULT_MESSAGE_PARAMS.merge({key: routing_key.to_sym}))
|
53
36
|
rescue
|
54
37
|
RJ.logger.warn $!.message
|
@@ -74,5 +57,31 @@ module RabbitJobs
|
|
74
57
|
|
75
58
|
messages_count
|
76
59
|
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def settings
|
64
|
+
Thread.current[:rj_publisher] ||= {}
|
65
|
+
end
|
66
|
+
|
67
|
+
def connection
|
68
|
+
settings[:connection] ||= AmqpHelper.prepare_connection
|
69
|
+
end
|
70
|
+
|
71
|
+
def exchanges
|
72
|
+
settings[:exchanges] ||= {}
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_exchange(ex = {})
|
76
|
+
ex = {name: ex} if ex.is_a?(String)
|
77
|
+
raise ArgumentError.new("Need to pass exchange name") if ex.size > 0 && ex[:name].to_s.empty?
|
78
|
+
|
79
|
+
if ex.size > 0
|
80
|
+
exchange_opts = Configuration::DEFAULT_EXCHANGE_PARAMS.merge(ex[:params] || {}).merge({type: (ex[:type] || :direct)})
|
81
|
+
exchanges[ex[:name]] ||= connection.channel.exchange(ex[:name].to_s, exchange_opts)
|
82
|
+
else
|
83
|
+
exchanges[ex[:name]] ||= connection.channel.default_exchange
|
84
|
+
end
|
85
|
+
end
|
77
86
|
end
|
78
87
|
end
|
@@ -36,7 +36,7 @@ module RabbitJobs
|
|
36
36
|
interval_types.each do |interval_type|
|
37
37
|
if !config[interval_type].nil? && config[interval_type].length > 0
|
38
38
|
RJ.logger.info "queueing #{config['class']} (#{name})"
|
39
|
-
rufus_scheduler.send(interval_type, config[interval_type]) do
|
39
|
+
rufus_scheduler.send(interval_type, config[interval_type], blocking: true) do
|
40
40
|
publish_from_config(config)
|
41
41
|
end
|
42
42
|
interval_defined = true
|
data/lib/rabbit_jobs/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabbit_jobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,27 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bunny
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &16643800 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - =
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: 0.9.0.pre8
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - '='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 0.9.0.pre8
|
24
|
+
version_requirements: *16643800
|
30
25
|
- !ruby/object:Gem::Dependency
|
31
26
|
name: rake
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &16640820 !ruby/object:Gem::Requirement
|
33
28
|
none: false
|
34
29
|
requirements:
|
35
30
|
- - ! '>='
|
@@ -37,15 +32,10 @@ dependencies:
|
|
37
32
|
version: '0'
|
38
33
|
type: :runtime
|
39
34
|
prerelease: false
|
40
|
-
version_requirements:
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
35
|
+
version_requirements: *16640820
|
46
36
|
- !ruby/object:Gem::Dependency
|
47
37
|
name: rufus-scheduler
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &16639760 !ruby/object:Gem::Requirement
|
49
39
|
none: false
|
50
40
|
requirements:
|
51
41
|
- - ~>
|
@@ -53,15 +43,10 @@ dependencies:
|
|
53
43
|
version: '2.0'
|
54
44
|
type: :runtime
|
55
45
|
prerelease: false
|
56
|
-
version_requirements:
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '2.0'
|
46
|
+
version_requirements: *16639760
|
62
47
|
- !ruby/object:Gem::Dependency
|
63
48
|
name: rails
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirement: &16638180 !ruby/object:Gem::Requirement
|
65
50
|
none: false
|
66
51
|
requirements:
|
67
52
|
- - ! '>='
|
@@ -69,12 +54,7 @@ dependencies:
|
|
69
54
|
version: '3.0'
|
70
55
|
type: :runtime
|
71
56
|
prerelease: false
|
72
|
-
version_requirements:
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '3.0'
|
57
|
+
version_requirements: *16638180
|
78
58
|
description: Background jobs on RabbitMQ
|
79
59
|
email:
|
80
60
|
- lazureykis@gmail.com
|
@@ -133,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
113
|
version: '0'
|
134
114
|
segments:
|
135
115
|
- 0
|
136
|
-
hash:
|
116
|
+
hash: 333706062697991268
|
137
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
118
|
none: false
|
139
119
|
requirements:
|
@@ -142,23 +122,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
122
|
version: '0'
|
143
123
|
segments:
|
144
124
|
- 0
|
145
|
-
hash:
|
125
|
+
hash: 333706062697991268
|
146
126
|
requirements: []
|
147
127
|
rubyforge_project:
|
148
|
-
rubygems_version: 1.8.
|
128
|
+
rubygems_version: 1.8.11
|
149
129
|
signing_key:
|
150
130
|
specification_version: 3
|
151
131
|
summary: Background jobs on RabbitMQ
|
152
|
-
test_files:
|
153
|
-
- spec/fixtures/config.yml
|
154
|
-
- spec/fixtures/jobs.rb
|
155
|
-
- spec/fixtures/schedule.yml
|
156
|
-
- spec/integration/publisher_spec.rb
|
157
|
-
- spec/integration/scheduler_spec.rb
|
158
|
-
- spec/integration/worker_spec.rb
|
159
|
-
- spec/spec_helper.rb
|
160
|
-
- spec/unit/configuration_spec.rb
|
161
|
-
- spec/unit/job_spec.rb
|
162
|
-
- spec/unit/mailer_spec.rb
|
163
|
-
- spec/unit/rabbit_jobs_spec.rb
|
164
|
-
- spec/unit/worker_spec.rb
|
132
|
+
test_files: []
|