advanced-sneakers-activejob 0.3.3 → 0.5.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: 144ceb20cac503afd808245bd4da0311a541694bf7c9cc0768a599355c60b001
4
- data.tar.gz: fe1f7cce63c635af8647b96b0a140653c37cc44c37b0250464689cb895e472eb
3
+ metadata.gz: a83b8e71434ad265d08febb7a8c186813c37971b0ce8c83520699a9a0e8bf71d
4
+ data.tar.gz: 53546ff1d7a72231ac909ad8a3e23c10f5606e0ecc1b6eae431f49de8b3c4af7
5
5
  SHA512:
6
- metadata.gz: 2b6cc96c1725224e5e3663c221fe080ff6874114ab8a667dbf5ebe8eb935819f613e617efbfb81ab183f2b3a9ee1d7ff07c0bdc613175419d94c1031fdbadb3f
7
- data.tar.gz: 57bfb70bc33895e6b30a30086a607dcdbec2a5b829b2fd95ccae6f5a305a267106833a8e54203858b5dcf37e5e3cabd56facf5e8aba7ca0785032432f9a620ac
6
+ metadata.gz: af2a68a5be7dedd658e7efc835b2fea1904c1e63ea0dd0b4f083405b62c686d8f160a44eaf3119a90e886a8cab73066a6d839cb1d2152f4b27c759edf382cb94
7
+ data.tar.gz: 4c6365c18cf1aeeb469b6ea2d6df39866149874400a713d2ab785df7d3c09577b9200dcfe0f8a4de336bebc9809933d9bd9ba2ec6f6fb2693f1e76a2f87539fa
data/.gitignore CHANGED
@@ -7,6 +7,7 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /Gemfile.lock
10
+ /gemfiles/*.lock
10
11
  /.ruby-gemset
11
12
  /.ruby-version
12
13
 
@@ -1,8 +1,23 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ Exclude:
4
+ - gemfiles/**/*
5
+
1
6
  Layout/LineLength:
2
7
  Max: 140
3
8
  Exclude:
4
9
  - spec/**/*
5
10
 
11
+ Lint/SuppressedException:
12
+ Exclude:
13
+ - spec/**/*
14
+
15
+ Lint/ConstantDefinitionInBlock:
16
+ Enabled: false
17
+
18
+ Gemspec/RequiredRubyVersion:
19
+ Enabled: false
20
+
6
21
  Metrics/ClassLength:
7
22
  Enabled: false
8
23
 
@@ -11,6 +26,10 @@ Metrics/BlockLength:
11
26
  - advanced-sneakers-activejob.gemspec
12
27
  - spec/**/*
13
28
 
29
+ Metrics/CyclomaticComplexity:
30
+ Exclude:
31
+ - spec/support/log_helpers.rb
32
+
14
33
  Metrics/MethodLength:
15
34
  Exclude:
16
35
  - spec/**/*
@@ -27,9 +46,5 @@ Metrics/AbcSize:
27
46
  Exclude:
28
47
  - spec/**/*
29
48
 
30
- Lint/SuppressedException:
31
- Exclude:
32
- - spec/**/*
33
-
34
49
  Style/Documentation:
35
50
  Enabled: false
@@ -2,20 +2,24 @@
2
2
  dist: xenial
3
3
  language: ruby
4
4
  cache: bundler
5
+
5
6
  rvm:
6
7
  - 2.5.8
7
8
  - 2.6.6
8
9
  - 2.7.1
9
- env:
10
- - RAILS_VERSION="~> 4.2.11"
11
- - RAILS_VERSION="~> 5.2.4"
12
- - RAILS_VERSION="~> 6.0.2"
13
- jobs:
10
+
11
+ gemfile:
12
+ - gemfiles/activejob_4.2.x.gemfile
13
+ - gemfiles/activejob_5.2.x.gemfile
14
+ - gemfiles/activejob_6.0.x.gemfile
15
+
16
+ matrix:
14
17
  exclude:
15
18
  - rvm: 2.7.1
16
- env: RAILS_VERSION="~> 4.2.11"
19
+ gemfile: gemfiles/activejob_4.2.x.gemfile
20
+
21
+ before_install: 'gem install bundler -v "$(ruby -e "puts RUBY_VERSION.to_f >= 2.7 ? \">= 2.0\" : \"< 2\"")"'
22
+
23
+ before_script: .ci/install_rabbitmq
17
24
 
18
- before_install: gem install bundler -v 1.17.3
19
- before_script:
20
- - ".ci/install_rabbitmq"
21
25
  bundler_args: --jobs 3 --retry 3
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise 'activejob-4.2.x' do
4
+ gem 'rails', '~> 4.2.11'
5
+ end
6
+
7
+ appraise 'activejob-5.2.x' do
8
+ gem 'rails', '~> 5.2.4'
9
+ end
10
+
11
+ appraise 'activejob-6.0.x' do
12
+ gem 'rails', '~> 6.0.3'
13
+ end
@@ -1,58 +1,97 @@
1
- ## Changes Between 0.3.2 and 0.3.3
1
+ # Changelog
2
2
 
3
- ### [Add ability to run ActiveJob consumers by queues](https://github.com/veeqo/advanced-sneakers-activejob/pull/9)
3
+ All notable changes to this project will be documented in this file.
4
4
 
5
- Works with `sneakers:active_job` task only!
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
6
 
7
- ```sh
8
- rake sneakers:active_job QUEUES=mailers,default
9
- ```
7
+ ## [Unreleased](https://github.com/veeqo/advanced-sneakers-activejob/compare/v0.5.0...HEAD)
10
8
 
11
- ## Changes Between 0.3.1 and 0.3.2
12
9
 
13
- ### [Add ability to run specified ActiveJob queues consumers](https://github.com/veeqo/advanced-sneakers-activejob/pull/8)
10
+ ## [0.5.0](https://github.com/veeqo/advanced-sneakers-activejob/compare/v0.4.0...v0.5.0) - 2020-11-30
14
11
 
15
- Sneakers allows to specify consumer classes to run:
12
+ ### Changed
13
+ - [#16](https://github.com/veeqo/advanced-sneakers-activejob/pull/16) Switch to bunny-publisher v0.2 (drops republish connection)
16
14
 
17
- ```sh
18
- WORKERS=MyConsumer rake sneakers:run
19
- ```
20
15
 
21
- Now it works for ActiveJob queues consumers as well:
16
+ ## [0.4.0](https://github.com/veeqo/advanced-sneakers-activejob/compare/v0.3.6...v0.4.0) - 2020-11-17
22
17
 
23
- ```sh
24
- WORKERS=AdvancedSneakersActiveJob::MailersConsumer rake sneakers:run
25
- ```
18
+ ### Added
19
+ - [#15](https://github.com/veeqo/advanced-sneakers-activejob/pull/15) Add ability to set AMQP message options per job
26
20
 
27
- ## Changes Between 0.3.0 and 0.3.1
28
21
 
29
- ### [Restore Sneakers::Worker::Classes methods](https://github.com/veeqo/advanced-sneakers-activejob/pull/6)
22
+ ## [0.3.6](https://github.com/veeqo/advanced-sneakers-activejob/compare/v0.3.5...v0.3.6) - 2020-09-18
30
23
 
31
- ## Changes Between 0.2.3 and 0.3.0
24
+ ### Changed
25
+ - [#12](https://github.com/veeqo/advanced-sneakers-activejob/pull/12) Refactor changelog to comply with Keep a Changelog
26
+ - [#13](https://github.com/veeqo/advanced-sneakers-activejob/pull/13) Use appraisals for Travis matrix
32
27
 
33
- This release does not change the observed behavior, but replaces the publisher with completely new implementation.
28
+ ### Fixed
29
+ - [#14](https://github.com/veeqo/advanced-sneakers-activejob/pull/14) Fix deprecation warnings of ruby 2.7
34
30
 
35
- ### Reusable parts of publisher are extracted to [bunny-publisher](https://github.com/veeqo/bunny-publisher)
36
31
 
37
- ## Changes Between 0.2.2 and 0.2.3
32
+ ## [0.3.5](https://github.com/veeqo/advanced-sneakers-activejob/compare/v0.3.4...v0.3.5) - 2020-06-27
38
33
 
39
- ### [Refactored support for ActiveJob prefix](https://github.com/veeqo/advanced-sneakers-activejob/pull/3)
40
- ### [Support for custom adapter per job](https://github.com/veeqo/advanced-sneakers-activejob/pull/4)
34
+ ### Fixed
35
+ - [#11](https://github.com/veeqo/advanced-sneakers-activejob/pull/11) `NoMethodError` on `Rails.application.eager_load!` in Rails initializer
41
36
 
42
- ## Changes Between 0.2.1 and 0.2.2
43
37
 
44
- Cleanup of `puts` and logger mistakenly introduced in previous version
38
+ ## [0.3.4](https://github.com/veeqo/advanced-sneakers-activejob/compare/v0.3.3...v0.3.4) - 2020-06-11
45
39
 
46
- ## Changes Between 0.2.0 and 0.2.1
40
+ ### Added
41
+ - [#10](https://github.com/veeqo/advanced-sneakers-activejob/pull/10) Ability to run ActiveJob consumers by wildcards for queue names
47
42
 
48
- ### [Support for ActiveJob prefix](https://github.com/veeqo/advanced-sneakers-activejob/pull/2)
49
43
 
50
- Fixed worker class name in rake task description
44
+ ## [0.3.3](https://github.com/veeqo/advanced-sneakers-activejob/compare/v0.3.2...v0.3.3) - 2020-06-09
51
45
 
52
- ## Changes Between 0.1.0 and 0.2.0
46
+ ### Added
47
+ - [#9](https://github.com/veeqo/advanced-sneakers-activejob/pull/9) Ability to run ActiveJob consumers by queue names
53
48
 
54
- ### [`message_options`](https://github.com/veeqo/advanced-sneakers-activejob/pull/1)
55
49
 
56
- Customizable options for message publishing (`routing_key`, `headers`, etc)
50
+ ## [0.3.2](https://github.com/veeqo/advanced-sneakers-activejob/compare/v0.3.1...v0.3.2) - 2020-06-05
57
51
 
58
- ## Original Release: 0.1.0
52
+ ### Added
53
+ - [#8](https://github.com/veeqo/advanced-sneakers-activejob/pull/8) Ability to run specified ActiveJob queues consumers
54
+
55
+
56
+ ## [0.3.1](https://github.com/veeqo/advanced-sneakers-activejob/compare/v0.3.0...v0.3.1) - 2020-06-02
57
+
58
+ ### Fixed
59
+ - [#6](https://github.com/veeqo/advanced-sneakers-activejob/pull/6) Restore Sneakers::Worker::Classes methods
60
+
61
+
62
+ ## [0.3.0](https://github.com/veeqo/advanced-sneakers-activejob/compare/v0.2.3...v0.3.0) - 2020-05-21
63
+
64
+ ### Changed
65
+ - [#5](https://github.com/veeqo/advanced-sneakers-activejob/pull/5) Publisher is extracted to [bunny-publisher](https://github.com/veeqo/bunny-publisher)
66
+
67
+
68
+ ## [0.2.3](https://github.com/veeqo/advanced-sneakers-activejob/compare/v0.2.2...v0.2.3) - 2020-04-06
69
+
70
+ ### Added
71
+ - [#4](https://github.com/veeqo/advanced-sneakers-activejob/pull/4) Support for custom adapter per job
72
+
73
+ ### Changed
74
+ - [#3](https://github.com/veeqo/advanced-sneakers-activejob/pull/3) Refactored support for ActiveJob prefix
75
+
76
+
77
+ ## [0.2.2](https://github.com/veeqo/advanced-sneakers-activejob/compare/v0.2.1...v0.2.2) - 2020-04-05
78
+
79
+ ### Fixed
80
+ - Cleanup of `puts` and logger mistakenly introduced in version `0.2.1`
81
+
82
+ ## [0.2.1](https://github.com/veeqo/advanced-sneakers-activejob/compare/v0.2.0...v0.2.1) - 2020-04-05
83
+
84
+ ### Added
85
+ - [#2](https://github.com/veeqo/advanced-sneakers-activejob/pull/2) Support queue name prefixes
86
+
87
+
88
+ ## [0.2.0](https://github.com/veeqo/advanced-sneakers-activejob/compare/v0.1.0...v0.2.0) - 2020-03-23
89
+
90
+ ### Added
91
+ - [#1](https://github.com/veeqo/advanced-sneakers-activejob/pull/1) Customizable options for message publishing (`routing_key`, `headers`, etc)
92
+
93
+
94
+ ## [0.1.0](https://github.com/veeqo/advanced-sneakers-activejob/releases/tag/v0.1.0) - 2020-03-19
95
+
96
+ ### Added
97
+ - `:advanced_sneakers` adapter for ActiveJob
data/Gemfile CHANGED
@@ -2,10 +2,6 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
-
7
- # Specify your gem's dependencies in advanced-sneakers-activejob.gemspec
8
5
  gemspec
9
6
 
10
- gem 'rails', ENV.fetch('RAILS_VERSION', '~> 4.2.11')
11
- gem 'sneakers', ENV.fetch('SNEAKERS_VERSION', '~> 2.11')
7
+ gem 'rails'
data/README.md CHANGED
@@ -41,7 +41,13 @@ rake sneakers:active_job
41
41
 
42
42
  Run worker for picked queues of ActiveJob
43
43
  ```sh
44
- rake sneakers:active_job QUEUES=mailers,foo,bar
44
+ QUEUES=mailers,foo,bar rake sneakers:active_job
45
+ ```
46
+
47
+ Wildcards are supported for queues names with "words" (separator is `.`). Algorithm is similar to the way the [topic exchange matches routing keys](https://www.rabbitmq.com/tutorials/tutorial-five-python.html). `*` (star) substitutes for exactly one word. `#` (hash) substitutes for zero or more words
48
+
49
+ ```sh
50
+ QUEUES=mailers,index.*,telemetery.# rake sneakers:active_job
45
51
  ```
46
52
 
47
53
  ## Unrouted messages
@@ -60,7 +66,7 @@ Take into accout that **this process is asynchronous**. It means that in case of
60
66
 
61
67
  ## Custom message options
62
68
 
63
- Advanced sneakers adapter allows to set custom message options (e.g. [routing keys](https://www.rabbitmq.com/tutorials/tutorial-four-ruby.html)).
69
+ Advanced sneakers adapter allows to set [custom message options](http://reference.rubybunny.info/Bunny/Exchange.html#publish-instance_method) (e.g. [routing keys](https://www.rabbitmq.com/tutorials/tutorial-four-ruby.html)) on class-level.
64
70
 
65
71
  ```ruby
66
72
  class MyJob < ActiveJob::Base
@@ -90,6 +96,14 @@ class MyJob < ActiveJob::Base
90
96
  end
91
97
  ```
92
98
 
99
+ And also supports custom message options per job
100
+ ```ruby
101
+ MyJob.set(priority: 1, headers: { 'foo' => 'bar' }).perform_later('baz')
102
+ ```
103
+
104
+ Read more about message properties:
105
+ - https://www.rabbitmq.com/publishers.html#message-properties
106
+ - http://reference.rubybunny.info/Bunny/Exchange.html#publish-instance_method
93
107
 
94
108
  Take into accout that **custom message options are used for publishing only**.
95
109
 
@@ -167,9 +181,6 @@ AdvancedSneakersActiveJob.configure do |config|
167
181
 
168
182
  # Connection for publisher (fallbacks to connection of consumers)
169
183
  config.publish_connection = Bunny.new('CUSTOM_URL', with: { other: 'options' })
170
-
171
- # Unrouted messages republish requires extra connection and will try to "clone" publish_connection unless it is provided
172
- config.republish_connection = Bunny.new('CUSTOM_URL', with: { other: 'options' })
173
184
  end
174
185
  ```
175
186
 
@@ -27,13 +27,12 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ['lib']
28
28
 
29
29
  spec.add_dependency 'activejob', '>= 4.2'
30
- spec.add_dependency 'bunny-publisher', '~> 0.1'
30
+ spec.add_dependency 'bunny-publisher', '~> 0.2.0'
31
31
  spec.add_dependency 'sneakers', '~> 2.7'
32
32
 
33
+ spec.add_development_dependency 'appraisal', '~> 2.3.0'
33
34
  spec.add_development_dependency 'bundler'
34
35
  spec.add_development_dependency 'pry-byebug'
35
36
  spec.add_development_dependency 'rabbitmq_http_api_client', '~> 1.13'
36
- spec.add_development_dependency 'rails', '>= 4.2'
37
- spec.add_development_dependency 'rake'
38
- spec.add_development_dependency 'rspec'
37
+ spec.add_development_dependency 'rspec', '~> 3.0'
39
38
  end
@@ -0,0 +1,3 @@
1
+ ---
2
+ BUNDLE_RETRY: "3"
3
+ BUNDLE_JOBS: "3"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.2.11"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.2.4"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 6.0.3"
6
+
7
+ gemspec path: "../"
@@ -47,11 +47,7 @@ module ActiveJob
47
47
  end
48
48
 
49
49
  def build_publish_params(job)
50
- params = job.class.publish_options.dup || {}
51
-
52
- params.each do |key, value|
53
- params[key] = value.call(job) if value.respond_to?(:call)
54
- end
50
+ params = merged_publish_options(job)
55
51
 
56
52
  unless params.key?(:routing_key)
57
53
  params[:routing_key] = job.queue_name.respond_to?(:call) ? job.queue_name.call : job.queue_name
@@ -59,6 +55,18 @@ module ActiveJob
59
55
 
60
56
  params
61
57
  end
58
+
59
+ def merged_publish_options(job)
60
+ publish_options = job.class.publish_options.deep_dup || {}
61
+
62
+ publish_options.each do |key, value|
63
+ publish_options[key] = value.call(job) if value.respond_to?(:call)
64
+ end
65
+
66
+ publish_options.deep_merge!(job.publish_options) if job.publish_options.present?
67
+
68
+ publish_options
69
+ end
62
70
  end
63
71
 
64
72
  delegate :enqueue, :enqueue_at, to: :'ActiveJob::QueueAdapters::AdvancedSneakersAdapter' # compatibility with Rails 5+
@@ -21,6 +21,14 @@ require 'advanced_sneakers_activejob/active_job_patch'
21
21
  require 'advanced_sneakers_activejob/railtie' if defined?(::Rails::Railtie)
22
22
  require 'active_job/queue_adapters/advanced_sneakers_adapter'
23
23
 
24
+ ActiveSupport.on_load(:active_job) do
25
+ ActiveJob::Base.include AdvancedSneakersActiveJob::ActiveJobPatch
26
+ end
27
+
28
+ ActiveSupport.on_load(:action_mailer) do
29
+ require 'action_mailer/delivery_job' # Enforce definition of ActionMailer::DeliveryJob::Consumer
30
+ end
31
+
24
32
  # Advanced Sneakers adapter for ActiveJob
25
33
  module AdvancedSneakersActiveJob
26
34
  class << self
@@ -46,11 +54,11 @@ module AdvancedSneakersActiveJob
46
54
  end
47
55
 
48
56
  def publisher
49
- @publisher ||= AdvancedSneakersActiveJob::Publisher.new(config.publisher_config)
57
+ @publisher ||= AdvancedSneakersActiveJob::Publisher.new(**config.publisher_config)
50
58
  end
51
59
 
52
60
  def delayed_publisher
53
- @delayed_publisher ||= AdvancedSneakersActiveJob::DelayedPublisher.new(config.publisher_config)
61
+ @delayed_publisher ||= AdvancedSneakersActiveJob::DelayedPublisher.new(**config.publisher_config)
54
62
  end
55
63
 
56
64
  # Based on ActiveSupport::Inflector#parameterize
@@ -6,7 +6,7 @@ module AdvancedSneakersActiveJob
6
6
 
7
7
  included do
8
8
  # AMQP message contains metadata which might be helpful for consumer (e.g. job.delivery_info.routing_key)
9
- attr_accessor :delivery_info, :headers
9
+ attr_accessor :delivery_info, :headers, :publish_options
10
10
 
11
11
  class_attribute :publish_options, instance_accessor: false
12
12
  end
@@ -25,5 +25,13 @@ module AdvancedSneakersActiveJob
25
25
  self.publish_options = options.symbolize_keys
26
26
  end
27
27
  end
28
+
29
+ def enqueue(options = {})
30
+ # Since ActiveJob v5 :priority option is supported natively https://github.com/rails/rails/pull/19425
31
+ # publish_options holds its own :priority to "backport" priority feature to ActiveJob v4
32
+ self.publish_options = options.except(:wait, :wait_until, :queue)
33
+
34
+ super
35
+ end
28
36
  end
29
37
  end
@@ -18,7 +18,10 @@ module AdvancedSneakersActiveJob
18
18
  config_accessor(:retry_delay_proc) { ->(count) { AdvancedSneakersActiveJob::EXPONENTIAL_BACKOFF[count] } } # seconds
19
19
 
20
20
  config_accessor(:publish_connection)
21
- config_accessor(:republish_connection)
21
+
22
+ def republish_connection=(_)
23
+ ActiveSupport::Deprecation.warn('Republish connection is not used for bunny-publisher v0.2+')
24
+ end
22
25
 
23
26
  def sneakers
24
27
  custom_config = DEFAULT_SNEAKERS_CONFIG.deep_merge(config.sneakers || {})
@@ -35,7 +38,7 @@ module AdvancedSneakersActiveJob
35
38
  end
36
39
 
37
40
  def publisher_config
38
- sneakers.merge(publish_connection: publish_connection, republish_connection: republish_connection)
41
+ sneakers.merge(publish_connection: publish_connection)
39
42
  end
40
43
  end
41
44
  end
@@ -17,24 +17,20 @@ module AdvancedSneakersActiveJob
17
17
  attr_reader :dlx_exchange_name
18
18
 
19
19
  def initialize(exchange:, **options)
20
- super(options.merge(exchange: [exchange, 'delayed'].join('-'), exchange_options: { type: 'headers', durable: true }))
20
+ super(**options.merge(exchange: [exchange, 'delayed'].join('-'), exchange_options: { type: 'headers', durable: true }))
21
21
 
22
22
  @dlx_exchange_name = exchange
23
23
  end
24
24
 
25
25
  private
26
26
 
27
- def log_message(publisher, message, options = {})
27
+ def log_message
28
28
  logger.debug do
29
- delay = options.dig(:headers, 'delay')
30
-
31
- "Publishing <#{message}> to [#{publisher.exchange.name}] with routing_key [#{options[:routing_key]}] and delay [#{delay}]"
29
+ "Publishing <#{message}> to [#{@exchange_name}] with routing_key [#{message_options[:routing_key]}] and delay [#{delay}]"
32
30
  end
33
31
  end
34
32
 
35
- def declare_republish_queue(_return_info, properties, _message)
36
- delay = properties.headers.fetch('delay')
37
-
33
+ def declare_republish_queue
38
34
  queue_name = delayed_queue_name(delay: delay)
39
35
 
40
36
  queue_arguments = {
@@ -45,11 +41,15 @@ module AdvancedSneakersActiveJob
45
41
 
46
42
  logger.debug { "Creating delayed queue [#{queue_name}]" }
47
43
 
48
- republish_channel.queue(queue_name, durable: true, arguments: queue_arguments)
44
+ channel.queue(queue_name, durable: true, arguments: queue_arguments)
45
+ end
46
+
47
+ def delay
48
+ message_options.dig(:headers, 'delay')
49
49
  end
50
50
 
51
- def declare_republish_queue_binding(queue, _return_info, properties, _message)
52
- queue.bind(republish_exchange, arguments: { delay: properties.headers.fetch('delay') })
51
+ def declare_republish_queue_binding(queue)
52
+ queue.bind(exchange, arguments: { delay: delay })
53
53
  end
54
54
 
55
55
  def delayed_queue_name(delay:)
@@ -14,9 +14,9 @@ module AdvancedSneakersActiveJob
14
14
 
15
15
  private
16
16
 
17
- def log_message(publisher, message, options = {})
17
+ def log_message
18
18
  logger.debug do
19
- "Publishing <#{message}> to [#{publisher.exchange.name}] with routing_key [#{options[:routing_key]}]"
19
+ "Publishing <#{message}> to [#{@exchange_name}] with routing_key [#{message_options[:routing_key]}]"
20
20
  end
21
21
  end
22
22
 
@@ -3,18 +3,6 @@
3
3
  module AdvancedSneakersActiveJob
4
4
  # Rails integration
5
5
  class Railtie < ::Rails::Railtie
6
- initializer 'advanced_sneakers_activejob.discover_mailer_job' do
7
- ActiveSupport.on_load(:action_mailer) do
8
- require 'action_mailer/delivery_job' # Enforce definition of ActionMailer::DeliveryJob::Consumer
9
- end
10
- end
11
-
12
- initializer 'advanced_sneakers_activejob.discover_default_job' do
13
- ActiveSupport.on_load(:active_job) do
14
- ActiveJob::Base.include AdvancedSneakersActiveJob::ActiveJobPatch
15
- end
16
- end
17
-
18
6
  rake_tasks do
19
7
  require 'advanced_sneakers_activejob/tasks'
20
8
  end
@@ -13,7 +13,7 @@ module AdvancedSneakersActiveJob
13
13
  detect_workers_for_queues!
14
14
  ensure_all_workers_found!
15
15
 
16
- @workers
16
+ @workers.uniq
17
17
  end
18
18
 
19
19
  private
@@ -30,15 +30,24 @@ module AdvancedSneakersActiveJob
30
30
 
31
31
  def detect_workers_for_queues!
32
32
  @queues.each do |queue|
33
- worker = all_workers.detect { |klass| klass.queue_name == queue }
33
+ matching_workers = all_workers.select { |klass| klass.queue_name.match?(queue_regex(queue)) }
34
34
 
35
- if worker
36
- @workers << worker
35
+ if matching_workers.any?
36
+ @workers += matching_workers
37
37
  else
38
38
  @queues_without_workers << queue
39
39
  end
40
40
  end
41
41
  end
42
+
43
+ # https://www.rabbitmq.com/tutorials/tutorial-five-python.html
44
+ def queue_regex(queue)
45
+ regex = Regexp.escape(queue)
46
+ .gsub(/\A\\\*|(\.)\\\*/, '\1[^\.]+') # "*" (star) substitutes for exactly one word
47
+ .sub('\.\#', '(\.[^\.]+)*') # "#" (hash) substitutes for zero or more words
48
+
49
+ Regexp.new(['\A', regex, '\z'].join)
50
+ end
42
51
  end
43
52
  end
44
53
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AdvancedSneakersActiveJob
4
- VERSION = '0.3.3'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: advanced-sneakers-activejob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Sharshenov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-06-09 00:00:00.000000000 Z
12
+ date: 2020-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activejob
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '0.1'
34
+ version: 0.2.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '0.1'
41
+ version: 0.2.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: sneakers
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -54,21 +54,21 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: '2.7'
56
56
  - !ruby/object:Gem::Dependency
57
- name: bundler
57
+ name: appraisal
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ">="
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '0'
62
+ version: 2.3.0
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ">="
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: 2.3.0
70
70
  - !ruby/object:Gem::Dependency
71
- name: pry-byebug
71
+ name: bundler
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - ">="
@@ -82,61 +82,47 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
- name: rabbitmq_http_api_client
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - "~>"
89
- - !ruby/object:Gem::Version
90
- version: '1.13'
91
- type: :development
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - "~>"
96
- - !ruby/object:Gem::Version
97
- version: '1.13'
98
- - !ruby/object:Gem::Dependency
99
- name: rails
85
+ name: pry-byebug
100
86
  requirement: !ruby/object:Gem::Requirement
101
87
  requirements:
102
88
  - - ">="
103
89
  - !ruby/object:Gem::Version
104
- version: '4.2'
90
+ version: '0'
105
91
  type: :development
106
92
  prerelease: false
107
93
  version_requirements: !ruby/object:Gem::Requirement
108
94
  requirements:
109
95
  - - ">="
110
96
  - !ruby/object:Gem::Version
111
- version: '4.2'
97
+ version: '0'
112
98
  - !ruby/object:Gem::Dependency
113
- name: rake
99
+ name: rabbitmq_http_api_client
114
100
  requirement: !ruby/object:Gem::Requirement
115
101
  requirements:
116
- - - ">="
102
+ - - "~>"
117
103
  - !ruby/object:Gem::Version
118
- version: '0'
104
+ version: '1.13'
119
105
  type: :development
120
106
  prerelease: false
121
107
  version_requirements: !ruby/object:Gem::Requirement
122
108
  requirements:
123
- - - ">="
109
+ - - "~>"
124
110
  - !ruby/object:Gem::Version
125
- version: '0'
111
+ version: '1.13'
126
112
  - !ruby/object:Gem::Dependency
127
113
  name: rspec
128
114
  requirement: !ruby/object:Gem::Requirement
129
115
  requirements:
130
- - - ">="
116
+ - - "~>"
131
117
  - !ruby/object:Gem::Version
132
- version: '0'
118
+ version: '3.0'
133
119
  type: :development
134
120
  prerelease: false
135
121
  version_requirements: !ruby/object:Gem::Requirement
136
122
  requirements:
137
- - - ">="
123
+ - - "~>"
138
124
  - !ruby/object:Gem::Version
139
- version: '0'
125
+ version: '3.0'
140
126
  description: Advanced Sneakers adapter for ActiveJob
141
127
  email:
142
128
  - rustam@sharshenov.com
@@ -149,12 +135,17 @@ files:
149
135
  - ".rspec"
150
136
  - ".rubocop.yml"
151
137
  - ".travis.yml"
138
+ - Appraisals
152
139
  - CHANGELOG.md
153
140
  - Gemfile
154
141
  - LICENSE.txt
155
142
  - README.md
156
143
  - Rakefile
157
144
  - advanced-sneakers-activejob.gemspec
145
+ - gemfiles/.bundle/config
146
+ - gemfiles/activejob_4.2.x.gemfile
147
+ - gemfiles/activejob_5.2.x.gemfile
148
+ - gemfiles/activejob_6.0.x.gemfile
158
149
  - lib/active_job/queue_adapters/advanced_sneakers_adapter.rb
159
150
  - lib/advanced/sneakers/activejob.rb
160
151
  - lib/advanced_sneakers_activejob.rb
@@ -193,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
184
  - !ruby/object:Gem::Version
194
185
  version: '0'
195
186
  requirements: []
196
- rubygems_version: 3.0.6
187
+ rubygems_version: 3.1.4
197
188
  signing_key:
198
189
  specification_version: 4
199
190
  summary: Advanced Sneakers adapter for ActiveJob