resque-bus 0.3.7 → 0.5.7

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.
Files changed (58) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +2 -2
  3. data/README.mdown +42 -64
  4. data/Rakefile +0 -1
  5. data/lib/resque-bus.rb +13 -305
  6. data/lib/resque_bus/adapter.rb +65 -0
  7. data/lib/resque_bus/compatibility/deprecated.rb +38 -0
  8. data/lib/resque_bus/compatibility/driver.rb +10 -0
  9. data/lib/resque_bus/compatibility/heartbeat.rb +10 -0
  10. data/lib/resque_bus/compatibility/publisher.rb +13 -0
  11. data/lib/resque_bus/compatibility/rider.rb +32 -0
  12. data/lib/resque_bus/compatibility/subscriber.rb +8 -0
  13. data/lib/resque_bus/compatibility/task_manager.rb +8 -0
  14. data/lib/resque_bus/server/views/bus.erb +2 -2
  15. data/lib/resque_bus/server.rb +5 -4
  16. data/lib/resque_bus/tasks.rb +46 -46
  17. data/lib/resque_bus/version.rb +2 -4
  18. data/resque-bus.gemspec +5 -10
  19. data/spec/adapter/compatibility_spec.rb +97 -0
  20. data/spec/adapter/integration_spec.rb +111 -0
  21. data/spec/adapter/publish_at_spec.rb +50 -0
  22. data/spec/adapter/retry_spec.rb +47 -0
  23. data/spec/adapter/support.rb +23 -0
  24. data/spec/adapter_spec.rb +14 -0
  25. data/spec/application_spec.rb +62 -62
  26. data/spec/config_spec.rb +83 -0
  27. data/spec/dispatch_spec.rb +6 -6
  28. data/spec/driver_spec.rb +62 -44
  29. data/spec/heartbeat_spec.rb +4 -4
  30. data/spec/integration_spec.rb +2 -2
  31. data/spec/matcher_spec.rb +29 -29
  32. data/spec/publish_spec.rb +46 -43
  33. data/spec/publisher_spec.rb +7 -0
  34. data/spec/rider_spec.rb +14 -66
  35. data/spec/spec_helper.rb +25 -25
  36. data/spec/subscriber_spec.rb +194 -176
  37. data/spec/subscription_list_spec.rb +1 -1
  38. data/spec/subscription_spec.rb +1 -1
  39. data/spec/worker_spec.rb +32 -0
  40. metadata +47 -58
  41. data/lib/resque_bus/application.rb +0 -115
  42. data/lib/resque_bus/compatibility.rb +0 -24
  43. data/lib/resque_bus/dispatch.rb +0 -61
  44. data/lib/resque_bus/driver.rb +0 -30
  45. data/lib/resque_bus/heartbeat.rb +0 -106
  46. data/lib/resque_bus/local.rb +0 -38
  47. data/lib/resque_bus/matcher.rb +0 -81
  48. data/lib/resque_bus/publisher.rb +0 -12
  49. data/lib/resque_bus/rider.rb +0 -54
  50. data/lib/resque_bus/subscriber.rb +0 -63
  51. data/lib/resque_bus/subscription.rb +0 -55
  52. data/lib/resque_bus/subscription_list.rb +0 -53
  53. data/lib/resque_bus/task_manager.rb +0 -52
  54. data/lib/resque_bus/util.rb +0 -42
  55. data/lib/tasks/resquebus.rake +0 -2
  56. data/spec/compatibility_spec.rb +0 -93
  57. data/spec/publish_at_spec.rb +0 -74
  58. data/spec/redis_spec.rb +0 -13
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-bus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.5.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-12 00:00:00.000000000 Z
12
+ date: 2015-03-31 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: queue-bus
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.5.5
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.5.5
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: resque
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -65,38 +81,6 @@ dependencies:
65
81
  - - ! '>='
66
82
  - !ruby/object:Gem::Version
67
83
  version: '0'
68
- - !ruby/object:Gem::Dependency
69
- name: redis-namespace
70
- requirement: !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
73
- - - ! '>='
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- none: false
80
- requirements:
81
- - - ! '>='
82
- - !ruby/object:Gem::Version
83
- version: '0'
84
- - !ruby/object:Gem::Dependency
85
- name: redis
86
- requirement: !ruby/object:Gem::Requirement
87
- none: false
88
- requirements:
89
- - - ! '>='
90
- - !ruby/object:Gem::Version
91
- version: '0'
92
- type: :runtime
93
- prerelease: false
94
- version_requirements: !ruby/object:Gem::Requirement
95
- none: false
96
- requirements:
97
- - - ! '>='
98
- - !ruby/object:Gem::Version
99
- version: '0'
100
84
  - !ruby/object:Gem::Dependency
101
85
  name: rspec
102
86
  requirement: !ruby/object:Gem::Requirement
@@ -145,8 +129,8 @@ dependencies:
145
129
  - - ! '>='
146
130
  - !ruby/object:Gem::Version
147
131
  version: '0'
148
- description: ! "A simple event bus on top of Resque.\n Publish and subscribe to
149
- events as they occur through a queue."
132
+ description: A simple event bus on top of Resque. Publish and subscribe to events
133
+ as they occur through a queue.
150
134
  email:
151
135
  - brian@bleonard.com
152
136
  executables: []
@@ -162,42 +146,41 @@ files:
162
146
  - README.mdown
163
147
  - Rakefile
164
148
  - lib/resque-bus.rb
165
- - lib/resque_bus/application.rb
166
- - lib/resque_bus/compatibility.rb
167
- - lib/resque_bus/dispatch.rb
168
- - lib/resque_bus/driver.rb
169
- - lib/resque_bus/heartbeat.rb
170
- - lib/resque_bus/local.rb
171
- - lib/resque_bus/matcher.rb
172
- - lib/resque_bus/publisher.rb
173
- - lib/resque_bus/rider.rb
149
+ - lib/resque_bus/adapter.rb
150
+ - lib/resque_bus/compatibility/deprecated.rb
151
+ - lib/resque_bus/compatibility/driver.rb
152
+ - lib/resque_bus/compatibility/heartbeat.rb
153
+ - lib/resque_bus/compatibility/publisher.rb
154
+ - lib/resque_bus/compatibility/rider.rb
155
+ - lib/resque_bus/compatibility/subscriber.rb
156
+ - lib/resque_bus/compatibility/task_manager.rb
174
157
  - lib/resque_bus/server.rb
175
158
  - lib/resque_bus/server/views/bus.erb
176
- - lib/resque_bus/subscriber.rb
177
- - lib/resque_bus/subscription.rb
178
- - lib/resque_bus/subscription_list.rb
179
- - lib/resque_bus/task_manager.rb
180
159
  - lib/resque_bus/tasks.rb
181
- - lib/resque_bus/util.rb
182
160
  - lib/resque_bus/version.rb
183
- - lib/tasks/resquebus.rake
184
161
  - resque-bus.gemspec
162
+ - spec/adapter/compatibility_spec.rb
163
+ - spec/adapter/integration_spec.rb
164
+ - spec/adapter/publish_at_spec.rb
165
+ - spec/adapter/retry_spec.rb
166
+ - spec/adapter/support.rb
167
+ - spec/adapter_spec.rb
185
168
  - spec/application_spec.rb
186
- - spec/compatibility_spec.rb
169
+ - spec/config_spec.rb
187
170
  - spec/dispatch_spec.rb
188
171
  - spec/driver_spec.rb
189
172
  - spec/heartbeat_spec.rb
190
173
  - spec/integration_spec.rb
191
174
  - spec/matcher_spec.rb
192
- - spec/publish_at_spec.rb
193
175
  - spec/publish_spec.rb
194
- - spec/redis_spec.rb
176
+ - spec/publisher_spec.rb
195
177
  - spec/rider_spec.rb
196
178
  - spec/spec_helper.rb
197
179
  - spec/subscriber_spec.rb
198
180
  - spec/subscription_list_spec.rb
199
181
  - spec/subscription_spec.rb
200
- homepage: ''
182
+ - spec/worker_spec.rb
183
+ homepage: https://github.com/queue-bus/resque-bus
201
184
  licenses: []
202
185
  post_install_message:
203
186
  rdoc_options: []
@@ -222,19 +205,25 @@ signing_key:
222
205
  specification_version: 3
223
206
  summary: A simple event bus on top of Resque
224
207
  test_files:
208
+ - spec/adapter/compatibility_spec.rb
209
+ - spec/adapter/integration_spec.rb
210
+ - spec/adapter/publish_at_spec.rb
211
+ - spec/adapter/retry_spec.rb
212
+ - spec/adapter/support.rb
213
+ - spec/adapter_spec.rb
225
214
  - spec/application_spec.rb
226
- - spec/compatibility_spec.rb
215
+ - spec/config_spec.rb
227
216
  - spec/dispatch_spec.rb
228
217
  - spec/driver_spec.rb
229
218
  - spec/heartbeat_spec.rb
230
219
  - spec/integration_spec.rb
231
220
  - spec/matcher_spec.rb
232
- - spec/publish_at_spec.rb
233
221
  - spec/publish_spec.rb
234
- - spec/redis_spec.rb
222
+ - spec/publisher_spec.rb
235
223
  - spec/rider_spec.rb
236
224
  - spec/spec_helper.rb
237
225
  - spec/subscriber_spec.rb
238
226
  - spec/subscription_list_spec.rb
239
227
  - spec/subscription_spec.rb
228
+ - spec/worker_spec.rb
240
229
  has_rdoc:
@@ -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
@@ -1,24 +0,0 @@
1
- # these can be in the queue from the new queue-bus version
2
- module QueueBus
3
- class Worker
4
-
5
- def self.perform(json)
6
- attributes = ::Resque.decode(json)
7
- class_name = attributes["bus_class_proxy"]
8
-
9
- case class_name
10
- when "::QueueBus::Driver", "QueueBus::Driver"
11
- ResqueBus::Driver.perform(attributes)
12
- when "::QueueBus::Rider", "QueueBus::Rider"
13
- ResqueBus::Rider.perform(attributes)
14
- when "::QueueBus::Publisher", "QueueBus::Publisher"
15
- ResqueBus::Publisher.perform(attributes["bus_event_type"], attributes)
16
- when "::QueueBus::Heartbeat", "QueueBus::Heartbeat"
17
- ResqueBus::Heartbeat.perform
18
- else
19
- klass = ::ResqueBus::Util.constantize(class_name)
20
- klass.perform(attributes)
21
- end
22
- end
23
- end
24
- end
@@ -1,61 +0,0 @@
1
- # Creates a DSL for apps to define their blocks to run for event_types
2
-
3
- module ResqueBus
4
- class Dispatch
5
-
6
- attr_reader :app_key, :subscriptions
7
-
8
- def initialize(app_key)
9
- @app_key = Application.normalize(app_key)
10
- @subscriptions = SubscriptionList.new
11
- end
12
-
13
- def size
14
- @subscriptions.size
15
- end
16
-
17
- def subscribe(key, matcher_hash = nil, &block)
18
- dispatch_event("default", key, matcher_hash, block)
19
- end
20
-
21
- # allows definitions of other queues
22
- def method_missing(method_name, *args, &block)
23
- if args.size == 1 && block
24
- dispatch_event(method_name, args[0], nil, block)
25
- elsif args.size == 2 && block
26
- dispatch_event(method_name, args[0], args[1], block)
27
- else
28
- super
29
- end
30
- end
31
-
32
- def execute(key, attributes)
33
- sub = subscriptions.key(key)
34
- if sub
35
- sub.execute!(attributes)
36
- else
37
- # TODO: log that it's not there
38
- end
39
- end
40
-
41
- def subscription_matches(attributes)
42
- out = subscriptions.matches(attributes)
43
- out.each do |sub|
44
- sub.app_key = self.app_key
45
- end
46
- out
47
- end
48
-
49
- def dispatch_event(queue, key, matcher_hash, block)
50
- # if not matcher_hash, assume key is a event_type regex
51
- matcher_hash ||= { "bus_event_type" => key }
52
- add_subscription("#{app_key}_#{queue}", key, "::ResqueBus::Rider", matcher_hash, block)
53
- end
54
-
55
- def add_subscription(queue_name, key, class_name, matcher_hash = nil, block)
56
- sub = Subscription.register(queue_name, key, class_name, matcher_hash, block)
57
- subscriptions.add(sub)
58
- sub
59
- end
60
- end
61
- end
@@ -1,30 +0,0 @@
1
- module ResqueBus
2
- # fans out an event to multiple queues
3
- class Driver
4
-
5
- class << self
6
- def subscription_matches(attributes)
7
- out = []
8
- Application.all.each do |app|
9
- subs = app.subscription_matches(attributes)
10
- out.concat(subs)
11
- end
12
- out
13
- end
14
-
15
- def perform(attributes={})
16
- raise "No attributes passed" if attributes.empty?
17
-
18
- ResqueBus.log_worker("Driver running: #{attributes.inspect}")
19
-
20
- subscription_matches(attributes).each do |sub|
21
- ResqueBus.log_worker(" ...sending to #{sub.queue_name} queue with class #{sub.class_name} for app #{sub.app_key} because of subscription: #{sub.key}")
22
-
23
- bus_attr = {"bus_driven_at" => Time.now.to_i, "bus_rider_queue" => sub.queue_name, "bus_rider_app_key" => sub.app_key, "bus_rider_sub_key" => sub.key, "bus_rider_class_name" => sub.class_name}
24
- ResqueBus.enqueue_to(sub.queue_name, sub.class_name, bus_attr.merge(attributes || {}))
25
- end
26
- end
27
- end
28
-
29
- end
30
- end
@@ -1,106 +0,0 @@
1
- module ResqueBus
2
- # publishes event about the current time
3
- class Heartbeat
4
-
5
- class << self
6
-
7
- def lock_key
8
- "resquebus:heartbeat:lock"
9
- end
10
-
11
- def lock_seconds
12
- 60
13
- end
14
-
15
- def lock!
16
- now = Time.now.to_i
17
- timeout = now + lock_seconds + 2
18
-
19
- # return true if we successfully acquired the lock
20
- return timeout if Resque.redis.setnx(lock_key, timeout)
21
-
22
- # see if the existing timeout is still valid and return false if it is
23
- # (we cannot acquire the lock during the timeout period)
24
- return 0 if now <= Resque.redis.get(lock_key).to_i
25
-
26
- # otherwise set the timeout and ensure that no other worker has
27
- # acquired the lock
28
- if now > Resque.redis.getset(lock_key, timeout).to_i
29
- return timeout
30
- else
31
- return 0
32
- end
33
- end
34
-
35
- def unlock!
36
- Resque.redis.del(lock_key)
37
- end
38
-
39
-
40
- def redis_key
41
- "resquebus:heartbeat:timestamp"
42
- end
43
-
44
- def environment_name
45
- ENV["RAILS_ENV"] || ENV["RACK_ENV"] || ENV["RESQUEBUS_ENV"]
46
- end
47
-
48
- def get_saved_minute!
49
- key = ResqueBus.redis.get(redis_key)
50
- return nil if key.nil?
51
- case environment_name
52
- when 'development', 'test'
53
- # only 3 minutes in development; otherwise, TONS of events if not run in a while
54
- three_ago = Time.now.to_i - 3*60*60
55
- key = three_ago if key.to_i < three_ago
56
- end
57
- return key.to_i
58
- end
59
-
60
- def set_saved_minute!(epoch_minute)
61
- ResqueBus.redis.set(redis_key, epoch_minute)
62
- end
63
-
64
- def perform
65
- real_now = Time.now.to_i
66
- run_until = lock! - 2
67
- return if run_until < real_now
68
-
69
- while((real_now = Time.now.to_i) < run_until)
70
- minutes = real_now.to_i / 60
71
- last = get_saved_minute!
72
- if last
73
- break if minutes <= last
74
- minutes = last + 1
75
- end
76
-
77
- seconds = minutes * (60)
78
- hours = minutes / (60)
79
- days = minutes / (60*24)
80
-
81
- now = Time.at(seconds)
82
-
83
- attributes = {}
84
- attributes["epoch_seconds"] = seconds
85
- attributes["epoch_minutes"] = minutes
86
- attributes["epoch_hours"] = hours
87
- attributes["epoch_days"] = days
88
-
89
- attributes["minute"] = now.min
90
- attributes["hour"] = now.hour
91
- attributes["day"] = now.day
92
- attributes["month"] = now.month
93
- attributes["year"] = now.year
94
- attributes["yday"] = now.yday
95
- attributes["wday"] = now.wday
96
-
97
- ResqueBus.publish("heartbeat_minutes", attributes)
98
- set_saved_minute!(minutes)
99
- end
100
-
101
- unlock!
102
- end
103
- end
104
-
105
- end
106
- end
@@ -1,38 +0,0 @@
1
- module ResqueBus
2
- # only process local queues
3
- class Local
4
-
5
- class << self
6
- def perform(attributes = {})
7
- if ResqueBus.local_mode == :suppress
8
- ResqueBus.log_worker("Suppressed: #{attributes.inspect}")
9
- return # not doing anything
10
- end
11
-
12
- ResqueBus.log_worker("Local running: #{attributes.inspect}")
13
-
14
- # looking for subscriptions, not queues
15
- subscription_matches(attributes).each do |sub|
16
- bus_attr = {"bus_driven_at" => Time.now.to_i, "bus_rider_queue" => sub.queue_name, "bus_rider_app_key" => sub.app_key, "bus_rider_sub_key" => sub.key, "bus_rider_class_name" => sub.class_name}
17
- to_publish = bus_attr.merge(attributes || {})
18
- if ResqueBus.local_mode == :standalone
19
- ResqueBus.enqueue_to(sub.queue_name, sub.class_name, bus_attr.merge(attributes || {}))
20
- else # defaults to inline mode
21
- sub.execute!(to_publish)
22
- end
23
- end
24
- end
25
-
26
- # looking directly at subscriptions loaded into dispatcher
27
- # so we don't need redis server up
28
- def subscription_matches(attributes)
29
- out = []
30
- ResqueBus.dispatchers.each do |dispatcher|
31
- out.concat(dispatcher.subscription_matches(attributes))
32
- end
33
- out
34
- end
35
- end
36
-
37
- end
38
- end
@@ -1,81 +0,0 @@
1
- module ResqueBus
2
- class Matcher
3
- SPECIAL_PREPEND = "bus_special_value_"
4
- attr_reader :filters
5
- def initialize(hash)
6
- @filters = encode(hash)
7
- end
8
-
9
- def to_redis
10
- @filters
11
- end
12
-
13
- def match?(attribute_name, attributes)
14
- mine = filters[attribute_name].to_s
15
- return false if mine.size == 0
16
-
17
- given = attributes[attribute_name]
18
- case mine
19
- when "#{SPECIAL_PREPEND}key"
20
- return true if attributes.has_key?(attribute_name)
21
- return false
22
- when "#{SPECIAL_PREPEND}blank"
23
- return true if given.to_s.strip.size == 0
24
- return false
25
- when "#{SPECIAL_PREPEND}empty"
26
- return false if given == nil
27
- return true if given.to_s.size == 0
28
- return false
29
- when "#{SPECIAL_PREPEND}nil"
30
- return true if given == nil
31
- return false
32
- when "#{SPECIAL_PREPEND}value"
33
- return false if given == nil
34
- return true
35
- when "#{SPECIAL_PREPEND}present"
36
- return true if given.to_s.strip.size > 0
37
- return false
38
- end
39
-
40
- given = given.to_s
41
-
42
- return true if mine == given
43
- begin
44
- # if it's already a regex, don't mess with it
45
- # otherwise, it should have start and end line situation
46
- if mine[0..6] == "(?-mix:"
47
- regex = Regexp.new(mine)
48
- else
49
- regex = Regexp.new("^#{mine}$")
50
- end
51
- return !!regex.match(given)
52
- rescue
53
- return false
54
- end
55
- end
56
-
57
- def matches?(attributes)
58
- return false if filters.empty?
59
- return false if attributes == nil
60
-
61
- filters.keys.each do |key|
62
- return false unless match?(key, attributes)
63
- end
64
-
65
- true
66
- end
67
-
68
- def encode(hash)
69
- out = {}
70
- hash.each do |key, value|
71
- case value
72
- when :key, :blank, :nil, :present, :empty, :value
73
- value = "#{SPECIAL_PREPEND}#{value}"
74
- end
75
- out[key.to_s] = value.to_s
76
- end
77
- out
78
- end
79
- end
80
- end
81
-
@@ -1,12 +0,0 @@
1
- module ResqueBus
2
- # publishes on a delay
3
- class Publisher
4
- class << self
5
- def perform(event_type, attributes = {})
6
- ResqueBus.log_worker("Publisher running: #{event_type} - #{attributes.inspect}")
7
- ResqueBus.publish(event_type, attributes)
8
- end
9
- end
10
-
11
- end
12
- end
@@ -1,54 +0,0 @@
1
- require 'resque-retry'
2
-
3
- module ResqueBus
4
- # queue'd in each
5
- class Rider
6
- extend Resque::Plugins::ExponentialBackoff
7
-
8
- class << self
9
- def perform(attributes = {})
10
- sub_key = attributes["bus_rider_sub_key"]
11
- app_key = attributes["bus_rider_app_key"]
12
- raise "No application key passed" if app_key.to_s == ""
13
- raise "No subcription key passed" if sub_key.to_s == ""
14
-
15
- attributes ||= {}
16
-
17
- ResqueBus.log_worker("Rider received: #{app_key} #{sub_key} #{attributes.inspect}")
18
-
19
- # attributes that should be available
20
- # attributes["bus_event_type"]
21
- # attributes["bus_app_key"]
22
- # attributes["bus_published_at"]
23
- # attributes["bus_driven_at"]
24
-
25
- # allow the real Reqsue to be used inside the callback while in a worker
26
- Resque.redis = ResqueBus.original_redis if ResqueBus.original_redis
27
-
28
- # (now running with the real app that subscribed)
29
- ResqueBus.dispatcher_execute(app_key, sub_key, attributes.merge("bus_executed_at" => Time.now.to_i))
30
- ensure
31
- # put this back if running in the thread
32
- Resque.redis = ResqueBus.redis if ResqueBus.original_redis
33
- end
34
-
35
- # @failure_hooks_already_ran on https://github.com/defunkt/resque/tree/1-x-stable
36
- # to prevent running twice
37
- def queue
38
- @my_queue
39
- end
40
-
41
- def on_failure_aaa(exception, *args)
42
- # note: sorted alphabetically
43
- # queue needs to be set for rety to work (know what queue in Requeue.class_to_queue)
44
- @my_queue = args[0]["bus_rider_queue"]
45
- end
46
-
47
- def on_failure_zzz(exception, *args)
48
- # note: sorted alphabetically
49
- @my_queue = nil
50
- end
51
-
52
- end
53
- end
54
- end