resque-bus 0.3.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +2 -3
- data/README.mdown +50 -64
- data/Rakefile +0 -1
- data/lib/resque-bus.rb +21 -283
- data/lib/resque_bus/adapter.rb +66 -0
- data/lib/resque_bus/compatibility/deprecated.rb +38 -0
- data/lib/resque_bus/compatibility/driver.rb +10 -0
- data/lib/resque_bus/compatibility/heartbeat.rb +10 -0
- data/lib/resque_bus/compatibility/publisher.rb +13 -0
- data/lib/resque_bus/compatibility/rider.rb +32 -0
- data/lib/resque_bus/compatibility/subscriber.rb +8 -0
- data/lib/resque_bus/compatibility/task_manager.rb +8 -0
- data/lib/resque_bus/server.rb +6 -5
- data/lib/resque_bus/server/views/bus.erb +2 -2
- data/lib/resque_bus/tasks.rb +46 -46
- data/lib/resque_bus/version.rb +2 -4
- data/resque-bus.gemspec +5 -12
- data/spec/adapter/compatibility_spec.rb +97 -0
- data/spec/adapter/integration_spec.rb +111 -0
- data/spec/adapter/publish_at_spec.rb +50 -0
- data/spec/adapter/retry_spec.rb +47 -0
- data/spec/adapter/support.rb +23 -0
- data/spec/adapter_spec.rb +14 -0
- data/spec/application_spec.rb +62 -62
- data/spec/config_spec.rb +83 -0
- data/spec/dispatch_spec.rb +6 -6
- data/spec/driver_spec.rb +62 -53
- data/spec/heartbeat_spec.rb +4 -4
- data/spec/integration_spec.rb +2 -2
- data/spec/matcher_spec.rb +29 -29
- data/spec/publish_spec.rb +62 -38
- data/spec/publisher_spec.rb +7 -0
- data/spec/rider_spec.rb +14 -66
- data/spec/spec_helper.rb +25 -28
- data/spec/subscriber_spec.rb +194 -176
- data/spec/subscription_list_spec.rb +1 -1
- data/spec/subscription_spec.rb +1 -1
- data/spec/worker_spec.rb +32 -0
- metadata +75 -91
- data/lib/resque_bus/application.rb +0 -115
- data/lib/resque_bus/dispatch.rb +0 -61
- data/lib/resque_bus/driver.rb +0 -30
- data/lib/resque_bus/heartbeat.rb +0 -106
- data/lib/resque_bus/local.rb +0 -34
- data/lib/resque_bus/matcher.rb +0 -81
- data/lib/resque_bus/publisher.rb +0 -12
- data/lib/resque_bus/rider.rb +0 -54
- data/lib/resque_bus/subscriber.rb +0 -63
- data/lib/resque_bus/subscription.rb +0 -55
- data/lib/resque_bus/subscription_list.rb +0 -53
- data/lib/resque_bus/task_manager.rb +0 -52
- data/lib/resque_bus/util.rb +0 -42
- data/lib/tasks/resquebus.rake +0 -2
- data/spec/publish_at_spec.rb +0 -74
- data/spec/redis_spec.rb +0 -13
data/spec/subscription_spec.rb
CHANGED
data/spec/worker_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module QueueBus
|
4
|
+
describe Worker do
|
5
|
+
it "should proxy to given class" do
|
6
|
+
hash = {"bus_class_proxy" => "QueueBus::Driver", "ok" => true}
|
7
|
+
QueueBus::Driver.should_receive(:perform).with(hash)
|
8
|
+
QueueBus::Worker.perform(JSON.generate(hash))
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should use instance" do
|
12
|
+
hash = {"bus_class_proxy" => "QueueBus::Rider", "ok" => true}
|
13
|
+
QueueBus::Rider.should_receive(:perform).with(hash)
|
14
|
+
QueueBus::Worker.new.perform(JSON.generate(hash))
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should not freak out if class not there anymore" do
|
18
|
+
hash = {"bus_class_proxy" => "QueueBus::BadClass", "ok" => true}
|
19
|
+
lambda {
|
20
|
+
QueueBus::Worker.perform(JSON.generate(hash))
|
21
|
+
}.should_not raise_error
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should raise error if proxy raises error" do
|
25
|
+
hash = {"bus_class_proxy" => "QueueBus::Rider", "ok" => true}
|
26
|
+
QueueBus::Rider.should_receive(:perform).with(hash).and_raise("rider crash")
|
27
|
+
lambda {
|
28
|
+
QueueBus::Worker.perform(JSON.generate(hash))
|
29
|
+
}.should raise_error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,235 +1,219 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-bus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.7.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Brian Leonard
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2019-07-29 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: queue-bus
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
-
- - <
|
19
|
+
version: '0.7'
|
20
|
+
- - "<"
|
23
21
|
- !ruby/object:Gem::Version
|
24
|
-
version: '
|
22
|
+
version: '1'
|
25
23
|
type: :runtime
|
26
24
|
prerelease: false
|
27
25
|
version_requirements: !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
26
|
requirements:
|
30
|
-
- -
|
27
|
+
- - ">="
|
31
28
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
33
|
-
- - <
|
29
|
+
version: '0.7'
|
30
|
+
- - "<"
|
34
31
|
- !ruby/object:Gem::Version
|
35
|
-
version: '
|
32
|
+
version: '1'
|
36
33
|
- !ruby/object:Gem::Dependency
|
37
|
-
name: resque
|
34
|
+
name: resque
|
38
35
|
requirement: !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ! '>='
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: 2.0.1
|
44
|
-
type: :runtime
|
45
|
-
prerelease: false
|
46
|
-
version_requirements: !ruby/object:Gem::Requirement
|
47
|
-
none: false
|
48
36
|
requirements:
|
49
|
-
- -
|
37
|
+
- - ">="
|
50
38
|
- !ruby/object:Gem::Version
|
51
|
-
version:
|
52
|
-
-
|
53
|
-
name: resque-retry
|
54
|
-
requirement: !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
|
-
requirements:
|
57
|
-
- - ! '>='
|
39
|
+
version: 1.10.0
|
40
|
+
- - "<"
|
58
41
|
- !ruby/object:Gem::Version
|
59
|
-
version: '0'
|
42
|
+
version: '2.0'
|
60
43
|
type: :runtime
|
61
44
|
prerelease: false
|
62
45
|
version_requirements: !ruby/object:Gem::Requirement
|
63
|
-
none: false
|
64
46
|
requirements:
|
65
|
-
- -
|
47
|
+
- - ">="
|
66
48
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
49
|
+
version: 1.10.0
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '2.0'
|
68
53
|
- !ruby/object:Gem::Dependency
|
69
|
-
name:
|
54
|
+
name: resque-scheduler
|
70
55
|
requirement: !ruby/object:Gem::Requirement
|
71
|
-
none: false
|
72
56
|
requirements:
|
73
|
-
- -
|
57
|
+
- - ">="
|
74
58
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
59
|
+
version: 2.0.1
|
76
60
|
type: :runtime
|
77
61
|
prerelease: false
|
78
62
|
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
63
|
requirements:
|
81
|
-
- -
|
64
|
+
- - ">="
|
82
65
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
66
|
+
version: 2.0.1
|
84
67
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
68
|
+
name: resque-retry
|
86
69
|
requirement: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
70
|
requirements:
|
89
|
-
- -
|
71
|
+
- - ">="
|
90
72
|
- !ruby/object:Gem::Version
|
91
73
|
version: '0'
|
92
74
|
type: :runtime
|
93
75
|
prerelease: false
|
94
76
|
version_requirements: !ruby/object:Gem::Requirement
|
95
|
-
none: false
|
96
77
|
requirements:
|
97
|
-
- -
|
78
|
+
- - ">="
|
98
79
|
- !ruby/object:Gem::Version
|
99
80
|
version: '0'
|
100
81
|
- !ruby/object:Gem::Dependency
|
101
82
|
name: rspec
|
102
83
|
requirement: !ruby/object:Gem::Requirement
|
103
|
-
none: false
|
104
84
|
requirements:
|
105
|
-
- -
|
85
|
+
- - ">="
|
106
86
|
- !ruby/object:Gem::Version
|
107
87
|
version: '0'
|
108
88
|
type: :development
|
109
89
|
prerelease: false
|
110
90
|
version_requirements: !ruby/object:Gem::Requirement
|
111
|
-
none: false
|
112
91
|
requirements:
|
113
|
-
- -
|
92
|
+
- - ">="
|
114
93
|
- !ruby/object:Gem::Version
|
115
94
|
version: '0'
|
116
95
|
- !ruby/object:Gem::Dependency
|
117
96
|
name: timecop
|
118
97
|
requirement: !ruby/object:Gem::Requirement
|
119
|
-
none: false
|
120
98
|
requirements:
|
121
|
-
- -
|
99
|
+
- - ">="
|
122
100
|
- !ruby/object:Gem::Version
|
123
101
|
version: '0'
|
124
102
|
type: :development
|
125
103
|
prerelease: false
|
126
104
|
version_requirements: !ruby/object:Gem::Requirement
|
127
|
-
none: false
|
128
105
|
requirements:
|
129
|
-
- -
|
106
|
+
- - ">="
|
130
107
|
- !ruby/object:Gem::Version
|
131
108
|
version: '0'
|
132
109
|
- !ruby/object:Gem::Dependency
|
133
110
|
name: json_pure
|
134
111
|
requirement: !ruby/object:Gem::Requirement
|
135
|
-
none: false
|
136
112
|
requirements:
|
137
|
-
- -
|
113
|
+
- - ">="
|
138
114
|
- !ruby/object:Gem::Version
|
139
115
|
version: '0'
|
140
116
|
type: :development
|
141
117
|
prerelease: false
|
142
118
|
version_requirements: !ruby/object:Gem::Requirement
|
143
|
-
none: false
|
144
119
|
requirements:
|
145
|
-
- -
|
120
|
+
- - ">="
|
146
121
|
- !ruby/object:Gem::Version
|
147
122
|
version: '0'
|
148
|
-
description:
|
149
|
-
|
123
|
+
description: A simple event bus on top of Resque. Publish and subscribe to events
|
124
|
+
as they occur through a queue.
|
150
125
|
email:
|
151
126
|
- brian@bleonard.com
|
152
127
|
executables: []
|
153
128
|
extensions: []
|
154
129
|
extra_rdoc_files: []
|
155
130
|
files:
|
156
|
-
- .gitignore
|
157
|
-
- .rbenv-version
|
158
|
-
- .
|
131
|
+
- ".gitignore"
|
132
|
+
- ".rbenv-version"
|
133
|
+
- ".rspec"
|
134
|
+
- ".rvmrc"
|
135
|
+
- CHANGELOG.md
|
159
136
|
- Gemfile
|
160
137
|
- MIT-LICENSE
|
161
138
|
- README.mdown
|
162
139
|
- Rakefile
|
163
140
|
- lib/resque-bus.rb
|
164
|
-
- lib/resque_bus/
|
165
|
-
- lib/resque_bus/
|
166
|
-
- lib/resque_bus/driver.rb
|
167
|
-
- lib/resque_bus/heartbeat.rb
|
168
|
-
- lib/resque_bus/
|
169
|
-
- lib/resque_bus/
|
170
|
-
- lib/resque_bus/
|
171
|
-
- lib/resque_bus/
|
141
|
+
- lib/resque_bus/adapter.rb
|
142
|
+
- lib/resque_bus/compatibility/deprecated.rb
|
143
|
+
- lib/resque_bus/compatibility/driver.rb
|
144
|
+
- lib/resque_bus/compatibility/heartbeat.rb
|
145
|
+
- lib/resque_bus/compatibility/publisher.rb
|
146
|
+
- lib/resque_bus/compatibility/rider.rb
|
147
|
+
- lib/resque_bus/compatibility/subscriber.rb
|
148
|
+
- lib/resque_bus/compatibility/task_manager.rb
|
172
149
|
- lib/resque_bus/server.rb
|
173
150
|
- lib/resque_bus/server/views/bus.erb
|
174
|
-
- lib/resque_bus/subscriber.rb
|
175
|
-
- lib/resque_bus/subscription.rb
|
176
|
-
- lib/resque_bus/subscription_list.rb
|
177
|
-
- lib/resque_bus/task_manager.rb
|
178
151
|
- lib/resque_bus/tasks.rb
|
179
|
-
- lib/resque_bus/util.rb
|
180
152
|
- lib/resque_bus/version.rb
|
181
|
-
- lib/tasks/resquebus.rake
|
182
153
|
- resque-bus.gemspec
|
154
|
+
- spec/adapter/compatibility_spec.rb
|
155
|
+
- spec/adapter/integration_spec.rb
|
156
|
+
- spec/adapter/publish_at_spec.rb
|
157
|
+
- spec/adapter/retry_spec.rb
|
158
|
+
- spec/adapter/support.rb
|
159
|
+
- spec/adapter_spec.rb
|
183
160
|
- spec/application_spec.rb
|
161
|
+
- spec/config_spec.rb
|
184
162
|
- spec/dispatch_spec.rb
|
185
163
|
- spec/driver_spec.rb
|
186
164
|
- spec/heartbeat_spec.rb
|
187
165
|
- spec/integration_spec.rb
|
188
166
|
- spec/matcher_spec.rb
|
189
|
-
- spec/publish_at_spec.rb
|
190
167
|
- spec/publish_spec.rb
|
191
|
-
- spec/
|
168
|
+
- spec/publisher_spec.rb
|
192
169
|
- spec/rider_spec.rb
|
193
170
|
- spec/spec_helper.rb
|
194
171
|
- spec/subscriber_spec.rb
|
195
172
|
- spec/subscription_list_spec.rb
|
196
173
|
- spec/subscription_spec.rb
|
197
|
-
|
174
|
+
- spec/worker_spec.rb
|
175
|
+
homepage: https://github.com/queue-bus/resque-bus
|
198
176
|
licenses: []
|
177
|
+
metadata: {}
|
199
178
|
post_install_message:
|
200
179
|
rdoc_options: []
|
201
180
|
require_paths:
|
202
181
|
- lib
|
203
182
|
required_ruby_version: !ruby/object:Gem::Requirement
|
204
|
-
none: false
|
205
183
|
requirements:
|
206
|
-
- -
|
184
|
+
- - ">="
|
207
185
|
- !ruby/object:Gem::Version
|
208
186
|
version: '0'
|
209
187
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
210
|
-
none: false
|
211
188
|
requirements:
|
212
|
-
- -
|
189
|
+
- - ">="
|
213
190
|
- !ruby/object:Gem::Version
|
214
191
|
version: '0'
|
215
192
|
requirements: []
|
216
|
-
rubyforge_project:
|
217
|
-
rubygems_version:
|
193
|
+
rubyforge_project:
|
194
|
+
rubygems_version: 2.7.6
|
218
195
|
signing_key:
|
219
|
-
specification_version:
|
196
|
+
specification_version: 4
|
220
197
|
summary: A simple event bus on top of Resque
|
221
198
|
test_files:
|
199
|
+
- spec/adapter/compatibility_spec.rb
|
200
|
+
- spec/adapter/integration_spec.rb
|
201
|
+
- spec/adapter/publish_at_spec.rb
|
202
|
+
- spec/adapter/retry_spec.rb
|
203
|
+
- spec/adapter/support.rb
|
204
|
+
- spec/adapter_spec.rb
|
222
205
|
- spec/application_spec.rb
|
206
|
+
- spec/config_spec.rb
|
223
207
|
- spec/dispatch_spec.rb
|
224
208
|
- spec/driver_spec.rb
|
225
209
|
- spec/heartbeat_spec.rb
|
226
210
|
- spec/integration_spec.rb
|
227
211
|
- spec/matcher_spec.rb
|
228
|
-
- spec/publish_at_spec.rb
|
229
212
|
- spec/publish_spec.rb
|
230
|
-
- spec/
|
213
|
+
- spec/publisher_spec.rb
|
231
214
|
- spec/rider_spec.rb
|
232
215
|
- spec/spec_helper.rb
|
233
216
|
- spec/subscriber_spec.rb
|
234
217
|
- spec/subscription_list_spec.rb
|
235
218
|
- spec/subscription_spec.rb
|
219
|
+
- spec/worker_spec.rb
|
@@ -1,115 +0,0 @@
|
|
1
|
-
module ResqueBus
|
2
|
-
class Application
|
3
|
-
|
4
|
-
class << self
|
5
|
-
|
6
|
-
def all
|
7
|
-
# note the names arent the same as we started with
|
8
|
-
ResqueBus.redis.smembers(app_list_key).collect{ |val| new(val) }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
attr_reader :app_key, :redis_key
|
13
|
-
|
14
|
-
|
15
|
-
def initialize(app_key)
|
16
|
-
@app_key = self.class.normalize(app_key)
|
17
|
-
@redis_key = "#{self.class.app_single_key}:#{@app_key}"
|
18
|
-
# raise error if only other chars
|
19
|
-
raise "Invalid application name" if @app_key.gsub("_", "").size == 0
|
20
|
-
end
|
21
|
-
|
22
|
-
def subscribe(subscription_list, log = false)
|
23
|
-
@subscriptions = nil
|
24
|
-
|
25
|
-
if subscription_list == nil || subscription_list.size == 0
|
26
|
-
unsubscribe
|
27
|
-
return true
|
28
|
-
end
|
29
|
-
|
30
|
-
temp_key = "temp_#{redis_key}:#{rand(999999999)}"
|
31
|
-
|
32
|
-
redis_hash = subscription_list.to_redis
|
33
|
-
redis_hash.each do |key, hash|
|
34
|
-
ResqueBus.redis.hset(temp_key, key, Resque.encode(hash))
|
35
|
-
end
|
36
|
-
|
37
|
-
# make it the real one
|
38
|
-
ResqueBus.redis.rename(temp_key, redis_key)
|
39
|
-
ResqueBus.redis.sadd(self.class.app_list_key, app_key)
|
40
|
-
|
41
|
-
if log
|
42
|
-
puts ResqueBus.redis.hgetall(redis_key).inspect
|
43
|
-
end
|
44
|
-
|
45
|
-
true
|
46
|
-
end
|
47
|
-
|
48
|
-
def unsubscribe
|
49
|
-
# TODO: clean up known queues?
|
50
|
-
ResqueBus.redis.srem(self.class.app_list_key, app_key)
|
51
|
-
ResqueBus.redis.del(redis_key)
|
52
|
-
end
|
53
|
-
|
54
|
-
def no_connect_queue_names_for(subscriptions)
|
55
|
-
out = []
|
56
|
-
subscriptions.all.each do |sub|
|
57
|
-
queue = "#{app_key}_#{sub.queue_name}"
|
58
|
-
out << queue
|
59
|
-
end
|
60
|
-
out << "#{app_key}_default"
|
61
|
-
out.uniq
|
62
|
-
end
|
63
|
-
|
64
|
-
def subscription_matches(attributes)
|
65
|
-
out = subscriptions.matches(attributes)
|
66
|
-
out.each do |sub|
|
67
|
-
sub.app_key = self.app_key
|
68
|
-
end
|
69
|
-
out
|
70
|
-
end
|
71
|
-
|
72
|
-
def event_display_tuples
|
73
|
-
out = []
|
74
|
-
subscriptions.all.each do |sub|
|
75
|
-
out << [sub.class_name, sub.queue_name, sub.matcher.filters]
|
76
|
-
end
|
77
|
-
out
|
78
|
-
end
|
79
|
-
|
80
|
-
protected
|
81
|
-
|
82
|
-
def self.normalize(val)
|
83
|
-
val.to_s.gsub(/\W/, "_").downcase
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.app_list_key
|
87
|
-
"resquebus_apps"
|
88
|
-
end
|
89
|
-
|
90
|
-
def self.app_single_key
|
91
|
-
"resquebus_app"
|
92
|
-
end
|
93
|
-
|
94
|
-
def event_queues
|
95
|
-
ResqueBus.redis.hgetall(redis_key)
|
96
|
-
end
|
97
|
-
|
98
|
-
def subscriptions
|
99
|
-
@subscriptions ||= SubscriptionList.from_redis(read_redis_hash)
|
100
|
-
end
|
101
|
-
|
102
|
-
def read_redis_hash
|
103
|
-
out = {}
|
104
|
-
ResqueBus.redis.hgetall(redis_key).each do |key, val|
|
105
|
-
begin
|
106
|
-
out[key] = Resque.decode(val)
|
107
|
-
rescue Resque::Helpers::DecodeException
|
108
|
-
out[key] = val
|
109
|
-
end
|
110
|
-
end
|
111
|
-
out
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
end
|