queue-bus 0.5.3 → 0.5.4

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.
data/README.mdown CHANGED
@@ -1,13 +1,18 @@
1
- ## Resque Bus
1
+ ## Queue Bus
2
2
 
3
- This gem uses Redis and Resque to allow simple asynchronous communication between apps.
3
+ This gem uses Redis and background queues that you are already using to allow simple asynchronous communication between apps.
4
4
 
5
5
  ### Install
6
6
 
7
- To install, include the 'resque-bus' gem and add the following to your Rakefile:
7
+ To install, pick one of the adapters and add it to your Gemfile:
8
+
9
+ * [resque-bus](https://github.com/queue-bus/resque-bus)
10
+ * [sidekiq-bus](https://github.com/queue-bus/sidekiq-bus)
11
+
12
+ And add the appropriate tasks to your Rakefile:
8
13
 
9
14
  ```ruby
10
- require "queue_bus/tasks"
15
+ require "resque_bus/tasks" # or sidekiq_bus/tasks
11
16
  ```
12
17
 
13
18
  ### Example
@@ -15,8 +20,8 @@ require "queue_bus/tasks"
15
20
  Application A can publish an event
16
21
 
17
22
  ```ruby
18
- # config
19
- Resque.redis = "192.168.1.1:6379"
23
+ # pick an adapter
24
+ require 'resque-bus' # (or other adapter)
20
25
 
21
26
  # business logic
22
27
  QueueBus.publish("user_created", "id" => 42, "first_name" => "John", "last_name" => "Smith")
@@ -28,8 +33,8 @@ QueueBus.publish_at(1.hour.from_now, "user_created", "id" => 42, "first_name" =>
28
33
  Application B is subscribed to events
29
34
 
30
35
  ```ruby
31
- # config
32
- Resque.redis = "192.168.1.1:6379"
36
+ # pick an adapter
37
+ require 'resque-bus' # (or other adapter)
33
38
 
34
39
  # initializer
35
40
  QueueBus.dispatch("app_b") do
@@ -110,122 +115,9 @@ Note: This subscribes when this class is loaded, so it needs to be in your load
110
115
 
111
116
  Each app needs to tell Redis about its subscriptions:
112
117
 
113
- $ rake resquebus:subscribe
114
-
115
- The subscription block is run inside a Resque worker which needs to be started for each app.
116
-
117
- $ rake resquebus:setup resque:work
118
-
119
- The incoming queue also needs to be processed on a dedicated or all the app servers.
120
-
121
- $ rake resquebus:driver resque:work
122
-
123
- If you want retry to work for subscribing apps, you should run resque-scheduler
124
-
125
- $ rake resque:scheduler
126
-
127
- ### Adapters
128
-
129
- QueueBus now supports multiple adapters! By default QueueBus uses Resque but you can now configure your application to use Sidekiq to drive and subscribe the bus.
130
-
131
- First be sure to configure QueueBus to use Sidekiq early in your applications' initialization cycle:
132
- ```
133
- QueueBus.adapter = 'Sidekiq'
134
- ```
135
- You will be responsible for setting up the queues for your Sidekiq clients however you can get the appropriate queue names with the following tasks:
136
- For driving applications:
137
- ```
138
- $ rake resquebus:driver:sidekiq
139
- ```
140
- For subscribing applications:
141
- ```
142
- $ rake resquebus:setup:sidekiq
143
- ```
144
- These tasks will provide the queue_names and some minimal suggestions for starting the client.
145
-
146
- Your subscribing applications will still need to also use the appropriate rake task:
147
- ```
148
- $ rake resquebus:subscribe:sidekiq
149
- ```
150
-
151
- At the moment you are expected to include the Sidekiq gem in your own applications.
152
-
153
- And yes we are planning on renaming and restructuring the project! Please contact the maintainer if you would like to add a different adapter.
118
+ $ rake queuebus:subscribe
154
119
 
155
- ### Heartbeat
156
-
157
- We've found it useful to have the bus act like `cron`, triggering timed jobs throughout the system. Resque Bus calls this a heartbeat.
158
- It uses resque-scheduler to trigger the events. You can enable it in your Rakefile.
159
-
160
- ```ruby
161
- # resque.rake
162
- namespace :resque do
163
- task :setup => [:environment] do
164
- QueueBus.heartbeat!
165
- end
166
- end
167
- ```
168
-
169
- Or add it to your `schedule.yml` directly
170
-
171
- ```yaml
172
- resquebus_heartbeat:
173
- cron: "* * * * *"
174
- class: "::QueueBus::Heartbeat"
175
- queue: bus_incoming
176
- description: "I publish a heartbeat_minutes event every minute"
177
- ```
178
-
179
- It is the equivalent of doing this every minute
180
-
181
- ```ruby
182
- seconds = minutes * (60)
183
- hours = minutes / (60)
184
- days = minutes / (60*24)
185
-
186
- now = Time.at(seconds)
187
-
188
- attributes = {}
189
-
190
- now = Time.now
191
- seconds = now.to_i
192
- QueueBus.publish("hearbeat_minutes", {
193
- "epoch_seconds" => seconds,
194
- "epoch_minutes" => seconds / 1.minute,
195
- "epoch_hours" => seconds / 1.hour,
196
- "epoch_days" => seconds / 1.day,
197
- "minute" => now.min
198
- "hour" => now.hour
199
- "day" => now.day
200
- "month" => now.month
201
- "year" => now.year
202
- "yday" => now.yday
203
- "wday" => now.wday
204
- })
205
- ```
206
-
207
- This allows you do something like this:
208
-
209
- ```ruby
210
- QueueBus.dispatch("app_c") do
211
- # runs at 10:20, 11:20, etc
212
- subscribe "once_an_hour", 'bus_event_type' => 'heartbeat_minutes', 'minute' => 20 do |attributes|
213
- Sitemap.generate!
214
- end
215
-
216
- # runs every five minutes
217
- subscribe "every_five_minutes", 'bus_event_type' => 'heartbeat_minutes' do |attributes|
218
- next unless attributes["epoch_minutes"] % 5 == 0
219
- HealthCheck.run!
220
- end
221
-
222
- # runs at 8am on the first of every month
223
- subscribe "new_month_morning", 'bus_event_type' => 'heartbeat_minutes', 'day' => 1, hour' => 8, 'minute' => 0, do |attributes|
224
- next unless attributes["epoch_minutes"] % 5 == 0
225
- Token.old.expire!
226
- end
227
- end
228
- ```
120
+ See the adapter project for detils on running the workers.
229
121
 
230
122
  ### Local Mode
231
123
 
@@ -251,14 +143,8 @@ This can be helpful inside some sort of migration, for example.
251
143
 
252
144
  ### TODO
253
145
 
254
- * Sidekiq adapter
255
- * Refactor rake tasks for resque/sidekiq
256
- * Refactor to a storage adapter for Redis, so we can store subscription info in MySQL or something else
257
146
  * Replace local modes with adapters
258
147
  * There are a few spots in the code with TODO notes
259
148
  * Make this not freak out in development without Redis or when Redis is down
260
149
  * We might not actually need to publish in tests
261
150
  * Add some rspec helpers for the apps to use: should_ post an event_publish or something along those lines
262
- * Allow calling resquebus:setup and resquebus:driver together (append to ENV['QUEUES'], don't replace it)
263
-
264
- Copyright (c) 2011 Brian Leonard, released under the MIT license
@@ -0,0 +1,25 @@
1
+ # require 'queue_bus/tasks'
2
+ # will give you these tasks
3
+
4
+ namespace :queuebus do
5
+
6
+ desc "Subscribes this application to QueueBus events"
7
+ task :subscribe => [ :preload ] do
8
+ manager = ::QueueBus::TaskManager.new(true)
9
+ count = manager.subscribe!
10
+ raise "No subscriptions created" if count == 0
11
+ end
12
+
13
+ desc "Unsubscribes this application from QueueBus events"
14
+ task :unsubscribe => [ :preload ] do
15
+ manager = ::QueueBus::TaskManager.new(true)
16
+ count = manager.unsubscribe!
17
+ puts "No subscriptions unsubscribed" if count == 0
18
+ end
19
+
20
+ # Preload app files if this is Rails
21
+ # you can also do this to load the right things
22
+ task :preload do
23
+ require 'queue-bus'
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module QueueBus
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: queue-bus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -125,10 +125,10 @@ files:
125
125
  - lib/queue_bus/subscription.rb
126
126
  - lib/queue_bus/subscription_list.rb
127
127
  - lib/queue_bus/task_manager.rb
128
+ - lib/queue_bus/tasks.rb
128
129
  - lib/queue_bus/util.rb
129
130
  - lib/queue_bus/version.rb
130
131
  - lib/queue_bus/worker.rb
131
- - lib/tasks/resquebus.rake
132
132
  - queue-bus.gemspec
133
133
  - spec/adapter/publish_at_spec.rb
134
134
  - spec/adapter/support.rb
@@ -1,2 +0,0 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
2
- require 'queue_bus/tasks'