symphony 0.12.5 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b574d82a0376c4f397afddcd8eef820cd089d22e4c2cc09e6374cf0e9227ff5
4
- data.tar.gz: 291e18181eaf8bf4484e8dc438123a28bd5bd07af506adff81235f3a98224861
3
+ metadata.gz: 4a3df7405c545cb568ef001dd1287e51bc2e2de8184d8b5ef43204b5fca7599b
4
+ data.tar.gz: 2abfd45b2447a5660feae02c67f9bbd5d856a68ba69cd391c9b7101e9a1a4582
5
5
  SHA512:
6
- metadata.gz: 20f2a6bf4785239e01b82b05b2ea7c252aeaf8553656a170c738bc32965f9a62c65a8a374969420cb00a3c58ecefa90b0214b828dcdfe95c827f73ba4a3749be
7
- data.tar.gz: 5c162e6316d2f10ce7e5c416c60a2c88275ac38f6186fe90c3e48536f1dc86d8b806699dafa74873be39335a6ccb706d5b2a597a7e252aa1c2560816c12f6e85
6
+ metadata.gz: a2bf4f256cb6605cbadfb03e6432a61cd036bf372ce8c97db932e3eafef0d22d9a8bf3e6907c772a271258fee096a5b87fd9a8f285b03302e94d922d65ccbff4
7
+ data.tar.gz: e384f2e9edbb3dc43e773e8cfa69be3bd316c8cbfa233d7ee93ab3865c67e90110f223671775d7318282cbee3ccbfed7d3a3ab17581f51f17edcee212f519bfb
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,27 @@
1
+ = Release History for symphony
2
+
3
+ ---
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
+
13
+ == v0.13.0 [2020-03-09] Michael Granger <ged@faeriemud.org>
14
+
15
+ Improvements:
16
+
17
+ - Remove Yajl dependency in favor of stdlib json.
18
+ - Update for Ruby 2.7
19
+
20
+ Changes:
21
+
22
+ - Requires Ruby 2.6+
23
+
24
+
1
25
  == v0.12.5 [2019-07-16] Michael Granger <ged@FaerieMUD.org>
2
26
 
3
27
  Improvements:
data/Manifest.txt CHANGED
@@ -1,8 +1,7 @@
1
1
  .simplecov
2
- ChangeLog
3
2
  History.rdoc
4
3
  Manifest.txt
5
- README.rdoc
4
+ README.md
6
5
  Rakefile
7
6
  UPGRADING.md
8
7
  USAGE.rdoc
@@ -1,10 +1,19 @@
1
- = symphony
1
+ # symphony
2
2
 
3
- wiki:: http://bitbucket.org/ged/symphony
4
- docs:: http://deveiate.org/code/symphony
3
+ home
4
+ : https://hg.sr.ht/~ged/Symphony
5
5
 
6
+ code
7
+ : https://hg.sr.ht/~ged/Symphony/browse
6
8
 
7
- == Description
9
+ docs
10
+ : https://deveiate.org/code/symphony
11
+
12
+ github
13
+ : https://github.com/ged/symphony
14
+
15
+
16
+ ## Description
8
17
 
9
18
  Symphony is a subscription-based asynchronous job system. It
10
19
  allows you to define jobs that watch for lightweight events from a
@@ -21,7 +30,7 @@ symphony-task::
21
30
  require the process management that the symphony daemon provides.
22
31
 
23
32
 
24
- == Synopsis
33
+ ## Synopsis
25
34
 
26
35
  class WorkerTask < Symphony::Task
27
36
  # Process all events
@@ -37,28 +46,33 @@ symphony-task::
37
46
  For a more detailed description of usage, please refer to the USAGE document.
38
47
 
39
48
 
40
- == Installation
49
+ ## Installation
41
50
 
42
51
  gem install symphony
43
52
 
44
53
 
45
- == Contributing
54
+ ## Contributing
46
55
 
47
56
  You can check out the current development source with Mercurial via its
48
- {project page}[http://bitbucket.org/ged/symphony]. Or if you prefer Git, via
49
- {its Github mirror}[https://github.com/ged/symphony].
57
+ [project page](https://hg.sr.ht/~ged/symphony). Or if you prefer Git, via
58
+ [its Github mirror](https://github.com/ged/symphony).
50
59
 
51
60
  After checking out the source, run:
52
61
 
53
- $ rake newb
62
+ $ rake setup
63
+
64
+ This task will install dependencies, and do any other necessary developer setup.
65
+
66
+
67
+ ## Authors
54
68
 
55
- This task will install any missing dependencies, run the tests/specs,
56
- and generate the API documentation.
69
+ - Michael Granger <ged@faeriemud.org>
70
+ - Mahlon E. Smith <mahlon@martini.nu>
57
71
 
58
72
 
59
- == License
73
+ ## License
60
74
 
61
- Copyright (c) 2011-2015, Michael Granger and Mahlon E. Smith
75
+ Copyright (c) 2011-2020, Michael Granger and Mahlon E. Smith
62
76
  All rights reserved.
63
77
 
64
78
  Redistribution and use in source and binary forms, with or without
data/Rakefile CHANGED
@@ -1,79 +1,10 @@
1
- #!/usr/bin/env rake
1
+ #!/usr/bin/env ruby -S rake
2
2
 
3
- begin
4
- require 'hoe'
5
- rescue LoadError
6
- abort "This Rakefile requires hoe (gem install hoe)"
7
- end
8
-
9
- GEMSPEC = 'symphony.gemspec'
10
-
11
-
12
- Hoe.plugin :mercurial
13
- Hoe.plugin :signing
14
- Hoe.plugin :deveiate
15
-
16
- Hoe.plugins.delete :rubyforge
17
-
18
- hoespec = Hoe.spec 'symphony' do |spec|
19
- spec.readme_file = 'README.rdoc'
20
- spec.history_file = 'History.rdoc'
21
- spec.extra_rdoc_files = FileList[ '*.rdoc' ]
22
- spec.spec_extras[:rdoc_options] = ['-f', 'fivefish', '-t', 'Symphony']
23
- spec.spec_extras[:required_rubygems_version] = '>= 2.0.3'
24
- spec.license 'BSD'
25
-
26
- spec.developer 'Michael Granger', 'ged@FaerieMUD.org'
27
- spec.developer 'Mahlon E. Smith', 'mahlon@martini.nu'
28
-
29
- spec.dependency 'configurability', '~> 3.1'
30
- spec.dependency 'loggability', '~> 0.11'
31
- spec.dependency 'pluggability', '~> 0.4'
32
- spec.dependency 'bunny', '~> 2.0'
33
- spec.dependency 'sysexits', '~> 1.1'
34
- spec.dependency 'yajl-ruby', '~> 1.3'
35
- spec.dependency 'msgpack', '~> 1.0'
36
- spec.dependency 'metriks', '~> 0.9'
37
- spec.dependency 'rusage', '~> 0.2'
38
-
39
- spec.dependency 'rspec', '~> 3.0', :developer
40
- spec.dependency 'simplecov', '~> 0.8', :developer
41
- spec.dependency 'timecop', '~> 0.8', :developer
42
-
43
- spec.require_ruby_version( '>=2.0.0' )
44
- spec.hg_sign_tags = true if spec.respond_to?( :hg_sign_tags= )
3
+ require 'rake/deveiate'
45
4
 
46
- self.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}"
5
+ Rake::DevEiate.setup( 'symphony' ) do |project|
6
+ project.publish_to = 'deveiate:/usr/local/www/public/code'
7
+ project.required_ruby_version = '~> 2.6'
47
8
  end
48
9
 
49
- # Fix some Hoe retardedness
50
- hoespec.spec.files.delete( '.gemtest' )
51
- ENV['VERSION'] ||= hoespec.spec.version.to_s
52
-
53
- # Run the tests before checking in
54
- task 'hg:precheckin' => [ :check_history, :check_manifest, :gemspec, :spec ]
55
-
56
- # Rebuild the ChangeLog immediately before release
57
- task :prerelease => 'ChangeLog'
58
- CLOBBER.include( 'ChangeLog' )
59
-
60
- desc "Build a coverage report"
61
- task :coverage do
62
- ENV["COVERAGE"] = 'yes'
63
- Rake::Task[:spec].invoke
64
- end
65
-
66
-
67
- task :gemspec => GEMSPEC
68
- file GEMSPEC => hoespec.spec.files do |task|
69
- spec = $hoespec.spec
70
- spec.version = "#{spec.version.bump}.0.pre#{Time.now.strftime("%Y%m%d%H%M%S")}"
71
- File.open( task.name, 'w' ) do |fh|
72
- fh.write( spec.to_ruby )
73
- end
74
- end
75
-
76
- task :default => :gemspec
77
-
78
- CLOBBER.include( GEMSPEC.to_s )
79
10
 
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 tell it to with +always_rebind+:
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
@@ -12,7 +12,7 @@ module Symphony
12
12
  Configurability
13
13
 
14
14
  # Library version constant
15
- VERSION = '0.12.5'
15
+ VERSION = '0.14.0'
16
16
 
17
17
  # Version-control revision constant
18
18
  REVISION = %q$Revision$
@@ -1,5 +1,5 @@
1
1
  # -*- ruby -*-
2
- #encoding: utf-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  require 'configurability'
5
5
  require 'loggability'
@@ -248,7 +248,7 @@ class Symphony::Daemon
248
248
  self.log.info "Restarting task group for %p" % [ task_class ]
249
249
  group.max_workers = max
250
250
  group.restart_workers
251
- end
251
+ end
252
252
 
253
253
 
254
254
  ### Shut down the workers for the specified task group.
@@ -1,5 +1,5 @@
1
1
  # -*- ruby -*-
2
- #encoding: utf-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  require 'rusage'
5
5
  require 'metriks'
@@ -1,5 +1,5 @@
1
1
  # -*- ruby -*-
2
- #encoding: utf-8
2
+ # frozen_string_literal: true
3
3
 
4
4
 
5
5
  module Symphony
@@ -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 = 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
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
- queue = channel.queue( self.name, passive: true )
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
- queue = channel.queue( self.name, auto_delete: !self.persistent )
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
@@ -1,5 +1,5 @@
1
1
  # -*- ruby -*-
2
- #encoding: utf-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  require 'loggability'
5
5
 
@@ -1,5 +1,5 @@
1
1
  # -*- ruby -*-
2
- #encoding: utf-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  require 'symphony'
5
5
 
@@ -1,5 +1,5 @@
1
1
  # -*- ruby -*-
2
- #encoding: utf-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  require 'loggability'
5
5
  require 'symphony' unless defined?( Symphony )
data/lib/symphony/task.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- ruby -*-
2
- #encoding: utf-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  require 'set'
5
5
  require 'sysexits'
@@ -7,7 +7,7 @@ require 'pluggability'
7
7
  require 'loggability'
8
8
 
9
9
  require 'msgpack'
10
- require 'yajl'
10
+ require 'json'
11
11
  require 'yaml'
12
12
 
13
13
  require 'symphony' unless defined?( Symphony )
@@ -47,6 +47,15 @@ class Symphony::Task
47
47
  plugin_prefixes 'symphony/tasks'
48
48
 
49
49
 
50
+ @queue = nil
51
+ @acknowledge = true
52
+ @routing_keys = Set.new
53
+ @prefetch = 10
54
+ @persistent = false
55
+ @always_rebind = false
56
+ @queue_type = nil
57
+
58
+
50
59
  ### Create a new Task object and listen for work. Exits with the code returned
51
60
  ### by #start when it's done.
52
61
  def self::run( exit_on_idle=false )
@@ -79,11 +88,15 @@ class Symphony::Task
79
88
  def self::inherited( subclass )
80
89
  super
81
90
 
91
+ subclass.instance_variable_set( :@queue, nil )
92
+ subclass.instance_variable_set( :@queue_type, nil )
93
+ subclass.instance_variable_set( :@always_rebind, false )
82
94
  subclass.instance_variable_set( :@routing_keys, Set.new )
83
95
  subclass.instance_variable_set( :@acknowledge, true )
84
96
  subclass.instance_variable_set( :@work_model, :longlived )
85
97
  subclass.instance_variable_set( :@prefetch, 10 )
86
98
  subclass.instance_variable_set( :@timeout_action, :reject )
99
+ subclass.instance_variable_set( :@timeout, nil )
87
100
  subclass.instance_variable_set( :@persistent, false )
88
101
  subclass.instance_variable_set( :@idle_timeout, DEFAULT_IDLE_TIMEOUT )
89
102
  end
@@ -132,6 +145,16 @@ class Symphony::Task
132
145
  end
133
146
 
134
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
+
135
158
  ### Set up one or more topic key patterns to use when binding the Task's queue
136
159
  ### to the exchange.
137
160
  def self::subscribe_to( *routing_keys )
@@ -438,7 +461,7 @@ class Symphony::Task
438
461
  when 'application/x-msgpack'
439
462
  MessagePack.unpack( payload )
440
463
  when 'application/json', 'text/javascript'
441
- Yajl::Parser.parse( payload )
464
+ JSON.parse( payload )
442
465
  when 'application/x-yaml', 'text/x-yaml'
443
466
  YAML.load( payload )
444
467
  else