symphony 0.13.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +4 -2
- data/History.rdoc +8 -0
- data/README.md +4 -1
- data/USAGE.rdoc +27 -13
- data/lib/symphony.rb +1 -1
- data/lib/symphony/queue.rb +17 -11
- data/lib/symphony/task.rb +12 -0
- data/spec/symphony/queue_spec.rb +27 -1
- data/spec/symphony/task_spec.rb +17 -0
- metadata +23 -7
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a3df7405c545cb568ef001dd1287e51bc2e2de8184d8b5ef43204b5fca7599b
|
4
|
+
data.tar.gz: 2abfd45b2447a5660feae02c67f9bbd5d856a68ba69cd391c9b7101e9a1a4582
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2bf4f256cb6605cbadfb03e6432a61cd036bf372ce8c97db932e3eafef0d22d9a8bf3e6907c772a271258fee096a5b87fd9a8f285b03302e94d922d65ccbff4
|
7
|
+
data.tar.gz: e384f2e9edbb3dc43e773e8cfa69be3bd316c8cbfa233d7ee93ab3865c67e90110f223671775d7318282cbee3ccbfed7d3a3ab17581f51f17edcee212f519bfb
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
data/History.rdoc
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
---
|
4
4
|
|
5
|
+
== v0.14.0 [2020-07-23] Michael Granger <ged@faeriemud.org>
|
6
|
+
|
7
|
+
Improvements:
|
8
|
+
|
9
|
+
- Allow `x-queue-type` to be specified for a `Task`. Thanks to
|
10
|
+
Alyssa Verkade <averkade@costar.com> for the patch.
|
11
|
+
|
12
|
+
|
5
13
|
== v0.13.0 [2020-03-09] Michael Granger <ged@faeriemud.org>
|
6
14
|
|
7
15
|
Improvements:
|
data/README.md
CHANGED
data/USAGE.rdoc
CHANGED
@@ -79,14 +79,14 @@ calling #run on the class itself.
|
|
79
79
|
== The Simplest Task
|
80
80
|
|
81
81
|
#!/usr/bin/env ruby
|
82
|
-
|
82
|
+
|
83
83
|
require 'symphony'
|
84
|
-
|
84
|
+
|
85
85
|
class Test < Symphony::Task
|
86
|
-
|
86
|
+
|
87
87
|
# Process all events
|
88
88
|
subscribe_to '#'
|
89
|
-
|
89
|
+
|
90
90
|
def work( payload, metadata )
|
91
91
|
puts "I received an event: %p with a payload of %p" % [
|
92
92
|
metadata[ :delivery_info ][ :routing_key ],
|
@@ -95,7 +95,7 @@ calling #run on the class itself.
|
|
95
95
|
return true
|
96
96
|
end
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
Symphony.load_config( 'etc/config.yml' )
|
100
100
|
Test.run
|
101
101
|
|
@@ -239,13 +239,13 @@ By default, Symphony will try and create a queue based on the Class
|
|
239
239
|
name of the task. You can override this per-task.
|
240
240
|
|
241
241
|
class Test < Symphony::Task
|
242
|
-
|
242
|
+
|
243
243
|
# Process all events
|
244
244
|
subscribe_to '#'
|
245
|
-
|
245
|
+
|
246
246
|
# I don't want to connect to a 'test' queue, lets make it interesting:
|
247
247
|
queue_name 'shazzzaaaam'
|
248
|
-
|
248
|
+
|
249
249
|
def work( payload, metadata )
|
250
250
|
...
|
251
251
|
|
@@ -261,14 +261,28 @@ can tell a task to create a persistent queue instead of an auto-delete queue:
|
|
261
261
|
|
262
262
|
== Queue Re-binding
|
263
263
|
|
264
|
-
If you want Symphony to re-bind a worker's queue when it starts up, you call
|
264
|
+
If you want Symphony to re-bind a worker's queue when it starts up, you call
|
265
|
+
tell it to with +always_rebind+:
|
265
266
|
|
266
267
|
always_rebind true
|
267
268
|
|
268
|
-
Note that re-binding doesn't *unbind* from the existing pattern/s, so you'll
|
269
|
+
Note that re-binding doesn't *unbind* from the existing pattern/s, so you'll
|
269
270
|
need to account for this in the Task's +work+ method.
|
270
271
|
|
271
272
|
|
273
|
+
== Queue Type
|
274
|
+
|
275
|
+
If you're running a version of RabbitMQ that supports the `x-queue-type`
|
276
|
+
argument (e.g., for quorum queues), you can specify a value for it using the
|
277
|
+
`queue_type` declaration:
|
278
|
+
|
279
|
+
queue_type 'quorum'
|
280
|
+
|
281
|
+
Note that several other queue settings might not work with some kinds of
|
282
|
+
queues; the validity of the combination of the task's settings are left to
|
283
|
+
the implementor.
|
284
|
+
|
285
|
+
|
272
286
|
= Plugins
|
273
287
|
|
274
288
|
Plugins change or enhance the behavior of a Symphony::Task.
|
@@ -287,7 +301,7 @@ the process name to display a total count and jobs per second rate.
|
|
287
301
|
prepend Symphony::Metrics
|
288
302
|
# ...
|
289
303
|
end
|
290
|
-
|
304
|
+
|
291
305
|
|
292
306
|
== Routing
|
293
307
|
|
@@ -300,13 +314,13 @@ receive multiple message topics much easier to maintain and test.
|
|
300
314
|
|
301
315
|
class Test < Symphony::Task
|
302
316
|
include Symphony::Routing
|
303
|
-
|
317
|
+
|
304
318
|
on 'users.create', 'workstation.create' do |payload, metadata|
|
305
319
|
puts "A user or workstation wants to be created!"
|
306
320
|
# ...
|
307
321
|
return true
|
308
322
|
end
|
309
|
-
|
323
|
+
|
310
324
|
on 'users.delete' do |payload, metadata|
|
311
325
|
puts "A user wants to be deleted!"
|
312
326
|
return true
|
data/lib/symphony.rb
CHANGED
data/lib/symphony/queue.rb
CHANGED
@@ -150,13 +150,14 @@ class Symphony::Queue
|
|
150
150
|
|
151
151
|
### Create a new Queue for the specified +task_class+.
|
152
152
|
def initialize( task_class )
|
153
|
-
@name
|
154
|
-
@acknowledge
|
155
|
-
@consumer_tag
|
156
|
-
@routing_keys
|
157
|
-
@prefetch
|
158
|
-
@persistent
|
159
|
-
@always_rebind
|
153
|
+
@name = task_class.queue_name
|
154
|
+
@acknowledge = task_class.acknowledge
|
155
|
+
@consumer_tag = task_class.consumer_tag
|
156
|
+
@routing_keys = task_class.routing_keys
|
157
|
+
@prefetch = task_class.prefetch
|
158
|
+
@persistent = task_class.persistent
|
159
|
+
@always_rebind = task_class.always_rebind
|
160
|
+
@amqp_queue_type = task_class.queue_type
|
160
161
|
|
161
162
|
@amqp_queue = nil
|
162
163
|
@shutting_down = false
|
@@ -195,6 +196,10 @@ class Symphony::Queue
|
|
195
196
|
# Whether or not to re-bind the queue to the exchange during setup
|
196
197
|
attr_predicate :always_rebind
|
197
198
|
|
199
|
+
##
|
200
|
+
# The -x-queue-type of the queue, if any
|
201
|
+
attr_reader :amqp_queue_type
|
202
|
+
|
198
203
|
##
|
199
204
|
# The underlying Bunny::Queue this object manages
|
200
205
|
attr_reader :amqp_queue
|
@@ -256,19 +261,20 @@ class Symphony::Queue
|
|
256
261
|
exchange = self.class.amqp_exchange
|
257
262
|
channel = self.class.amqp_channel
|
258
263
|
created_queue = false
|
259
|
-
queue = nil
|
260
264
|
|
261
|
-
begin
|
262
|
-
|
265
|
+
queue = begin
|
266
|
+
existing_queue = channel.queue( self.name, passive: true )
|
263
267
|
channel.prefetch( prefetch_count )
|
264
268
|
self.log.info "Using pre-existing queue: %s" % [ self.name ]
|
269
|
+
existing_queue
|
265
270
|
rescue Bunny::NotFound => err
|
266
271
|
self.log.info "%s; creating a new queue instead." % [ err.message ]
|
267
272
|
created_queue = true
|
268
273
|
channel = self.class.reset_amqp_channel
|
269
274
|
channel.prefetch( prefetch_count )
|
270
275
|
|
271
|
-
|
276
|
+
arguments = { 'x-queue-type' => self.amqp_queue_type }.compact
|
277
|
+
channel.queue( self.name, auto_delete: !self.persistent, arguments: arguments )
|
272
278
|
end
|
273
279
|
|
274
280
|
if self.always_rebind? || created_queue
|
data/lib/symphony/task.rb
CHANGED
@@ -53,6 +53,7 @@ class Symphony::Task
|
|
53
53
|
@prefetch = 10
|
54
54
|
@persistent = false
|
55
55
|
@always_rebind = false
|
56
|
+
@queue_type = nil
|
56
57
|
|
57
58
|
|
58
59
|
### Create a new Task object and listen for work. Exits with the code returned
|
@@ -88,6 +89,7 @@ class Symphony::Task
|
|
88
89
|
super
|
89
90
|
|
90
91
|
subclass.instance_variable_set( :@queue, nil )
|
92
|
+
subclass.instance_variable_set( :@queue_type, nil )
|
91
93
|
subclass.instance_variable_set( :@always_rebind, false )
|
92
94
|
subclass.instance_variable_set( :@routing_keys, Set.new )
|
93
95
|
subclass.instance_variable_set( :@acknowledge, true )
|
@@ -143,6 +145,16 @@ class Symphony::Task
|
|
143
145
|
end
|
144
146
|
|
145
147
|
|
148
|
+
### Specify an x-queue-type for the underlying queue
|
149
|
+
def self::queue_type( type=nil )
|
150
|
+
if type
|
151
|
+
@queue_type = type
|
152
|
+
end
|
153
|
+
|
154
|
+
return @queue_type
|
155
|
+
end
|
156
|
+
|
157
|
+
|
146
158
|
### Set up one or more topic key patterns to use when binding the Task's queue
|
147
159
|
### to the exchange.
|
148
160
|
def self::subscribe_to( *routing_keys )
|
data/spec/symphony/queue_spec.rb
CHANGED
@@ -128,7 +128,33 @@ RSpec.describe Symphony::Queue do
|
|
128
128
|
expect( new_channel ).to receive( :prefetch ).
|
129
129
|
with( Symphony::Queue::DEFAULT_PREFETCH )
|
130
130
|
expect( new_channel ).to receive( :queue ).
|
131
|
-
with( queue.name, auto_delete: true ).
|
131
|
+
with( queue.name, auto_delete: true, arguments: {} ).
|
132
|
+
and_return( amqp_queue )
|
133
|
+
expect( amqp_queue ).to receive( :bind ).
|
134
|
+
with( described_class.amqp_exchange, routing_key: 'floppy.rabbit.#' )
|
135
|
+
|
136
|
+
expect( queue.create_amqp_queue ).to be( amqp_queue )
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
it "can declare the queue's x-queue-type" do
|
141
|
+
testing_task_class.subscribe_to( 'floppy.rabbit.#' )
|
142
|
+
testing_task_class.queue_type( 'classic' )
|
143
|
+
expect( described_class.amqp_channel ).to receive( :queue ).
|
144
|
+
with( queue.name, passive: true ).
|
145
|
+
and_raise( Bunny::NotFound.new("no such queue", described_class.amqp_channel, true) )
|
146
|
+
expect( described_class.amqp_channel ).to receive( :open? ).
|
147
|
+
and_return( false )
|
148
|
+
|
149
|
+
# Channel is reset after queue creation fails
|
150
|
+
new_channel = double( "New AMQP channel" )
|
151
|
+
amqp_queue = double( "AMQP queue" )
|
152
|
+
allow( described_class.amqp_session ).to receive( :create_channel ).
|
153
|
+
and_return( new_channel )
|
154
|
+
expect( new_channel ).to receive( :prefetch ).
|
155
|
+
with( Symphony::Queue::DEFAULT_PREFETCH )
|
156
|
+
expect( new_channel ).to receive( :queue ).
|
157
|
+
with( queue.name, auto_delete: true, arguments: { 'x-queue-type' => 'classic' } ).
|
132
158
|
and_return( amqp_queue )
|
133
159
|
expect( amqp_queue ).to receive( :bind ).
|
134
160
|
with( described_class.amqp_exchange, routing_key: 'floppy.rabbit.#' )
|
data/spec/symphony/task_spec.rb
CHANGED
@@ -99,6 +99,23 @@ RSpec.describe Symphony::Task do
|
|
99
99
|
end
|
100
100
|
|
101
101
|
|
102
|
+
it "can set the x-queue-type for the queue" do
|
103
|
+
task = Class.new( described_class ) do
|
104
|
+
queue_name 'wascally.wabbit'
|
105
|
+
queue_type 'classic'
|
106
|
+
end
|
107
|
+
expect( task.queue_type ).to eq( 'classic' )
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
it "has a queue type of nil if unspecified" do
|
112
|
+
task = Class.new( described_class ) do
|
113
|
+
queue_name 'wascally.wabbit'
|
114
|
+
end
|
115
|
+
expect( task.queue_type ).to eq( nil )
|
116
|
+
end
|
117
|
+
|
118
|
+
|
102
119
|
it "can set the number of messages to prefetch" do
|
103
120
|
task_class.prefetch( 10 )
|
104
121
|
expect( task_class.prefetch ).to eq( 10 )
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: symphony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Granger
|
8
8
|
- Mahlon E. Smith
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain:
|
12
12
|
- |
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
jBZSA+N+xUTgUWpXjjwsLZjzJkhWATJWq+krNXcqpwXo6HsjmdUxoFMt63RBb+sI
|
36
36
|
XrxOxp8o0uOkU7FdLSGsyqJ2LzsR4obN
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2020-
|
38
|
+
date: 2020-07-23 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: configurability
|
@@ -169,6 +169,20 @@ dependencies:
|
|
169
169
|
- - "~>"
|
170
170
|
- !ruby/object:Gem::Version
|
171
171
|
version: '0.12'
|
172
|
+
- !ruby/object:Gem::Dependency
|
173
|
+
name: rdoc-generator-fivefish
|
174
|
+
requirement: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - "~>"
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0.4'
|
179
|
+
type: :development
|
180
|
+
prerelease: false
|
181
|
+
version_requirements: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - "~>"
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0.4'
|
172
186
|
- !ruby/object:Gem::Dependency
|
173
187
|
name: simplecov
|
174
188
|
requirement: !ruby/object:Gem::Requirement
|
@@ -246,14 +260,16 @@ files:
|
|
246
260
|
- spec/symphony/task_group_spec.rb
|
247
261
|
- spec/symphony/task_spec.rb
|
248
262
|
- spec/symphony_spec.rb
|
249
|
-
homepage: https://hg.sr.ht/~ged/
|
263
|
+
homepage: https://hg.sr.ht/~ged/Symphony
|
250
264
|
licenses:
|
251
265
|
- BSD-3-Clause
|
252
266
|
metadata:
|
253
|
-
homepage_uri: https://hg.sr.ht/~ged/
|
267
|
+
homepage_uri: https://hg.sr.ht/~ged/Symphony
|
254
268
|
documentation_uri: https://deveiate.org/code/symphony
|
255
269
|
changelog_uri: https://deveiate.org/code/symphony/History_md.html
|
256
|
-
|
270
|
+
source_uri: https://hg.sr.ht/~ged/Symphony/browse
|
271
|
+
bug_tracker_uri: https://todo.sr.ht/~ged/Symphony/browse
|
272
|
+
post_install_message:
|
257
273
|
rdoc_options: []
|
258
274
|
require_paths:
|
259
275
|
- lib
|
@@ -269,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
269
285
|
version: '0'
|
270
286
|
requirements: []
|
271
287
|
rubygems_version: 3.1.2
|
272
|
-
signing_key:
|
288
|
+
signing_key:
|
273
289
|
specification_version: 4
|
274
290
|
summary: Symphony is a subscription-based asynchronous job system.
|
275
291
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|