advanced-sneakers-activejob 0.3.0 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +11 -4
- data/CHANGELOG.md +53 -5
- data/README.md +12 -1
- data/lib/advanced_sneakers_activejob.rb +14 -0
- data/lib/advanced_sneakers_activejob/railtie.rb +0 -12
- data/lib/advanced_sneakers_activejob/support/locate_workers_by_queues.rb +53 -0
- data/lib/advanced_sneakers_activejob/tasks.rb +13 -1
- data/lib/advanced_sneakers_activejob/version.rb +1 -1
- data/lib/advanced_sneakers_activejob/workers_registry.rb +13 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1aaae2951e9e941f00eaf9ef8c51a0c56d04cc9c562feed490a245c1d918ba07
|
4
|
+
data.tar.gz: 6489ed0097e980a21f10183422835ebc937d89cce253f5dc7a9074672747d83d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d5694a6f435e4fdb73be0f6966a5167b10b1c58075a6f52a8022a7954f4d40fe50d4b17de24cdd5d8141936a4c6b7235e93c69d14a4ba3eefd5483d1f6f63b8
|
7
|
+
data.tar.gz: 228835587b2413b91d6ac65e1a1aa5b4275e4feb8506b283a2622aa7798a768b352ab84d2ab0fa8355be25fa25e5362eaa017ed7bf190d7898e14dcdd018e866
|
data/.rubocop.yml
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
|
1
4
|
Layout/LineLength:
|
2
5
|
Max: 140
|
3
6
|
Exclude:
|
4
7
|
- spec/**/*
|
5
8
|
|
9
|
+
Lint/SuppressedException:
|
10
|
+
Exclude:
|
11
|
+
- spec/**/*
|
12
|
+
|
6
13
|
Metrics/ClassLength:
|
7
14
|
Enabled: false
|
8
15
|
|
@@ -11,6 +18,10 @@ Metrics/BlockLength:
|
|
11
18
|
- advanced-sneakers-activejob.gemspec
|
12
19
|
- spec/**/*
|
13
20
|
|
21
|
+
Metrics/CyclomaticComplexity:
|
22
|
+
Exclude:
|
23
|
+
- spec/support/log_helpers.rb
|
24
|
+
|
14
25
|
Metrics/MethodLength:
|
15
26
|
Exclude:
|
16
27
|
- spec/**/*
|
@@ -27,9 +38,5 @@ Metrics/AbcSize:
|
|
27
38
|
Exclude:
|
28
39
|
- spec/**/*
|
29
40
|
|
30
|
-
Lint/SuppressedException:
|
31
|
-
Exclude:
|
32
|
-
- spec/**/*
|
33
|
-
|
34
41
|
Style/Documentation:
|
35
42
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,52 @@
|
|
1
|
-
## Changes Between 0.
|
1
|
+
## Changes Between 0.3.4 and 0.3.5
|
2
|
+
|
3
|
+
[Fixed NoMethodError on Rails.application.eager_load! in Rails initializer](https://github.com/veeqo/advanced-sneakers-activejob/pull/11)
|
4
|
+
|
5
|
+
```
|
6
|
+
NoMethodError: undefined method `message_options' for MyJob:Class
|
7
|
+
```
|
8
|
+
|
9
|
+
## Changes Between 0.3.3 and 0.3.4
|
10
|
+
|
11
|
+
### [Support for wildcards to run ActiveJob consumers by queues](https://github.com/veeqo/advanced-sneakers-activejob/pull/10)
|
12
|
+
|
13
|
+
Works with `sneakers:active_job` task only!
|
14
|
+
|
15
|
+
```sh
|
16
|
+
QUEUES=mailers,index.*,telemetery.# rake sneakers:active_job
|
17
|
+
```
|
18
|
+
|
19
|
+
## Changes Between 0.3.2 and 0.3.3
|
20
|
+
|
21
|
+
### [Add ability to run ActiveJob consumers by queues](https://github.com/veeqo/advanced-sneakers-activejob/pull/9)
|
22
|
+
|
23
|
+
Works with `sneakers:active_job` task only!
|
24
|
+
|
25
|
+
```sh
|
26
|
+
QUEUES=mailers,default rake sneakers:active_job
|
27
|
+
```
|
28
|
+
|
29
|
+
## Changes Between 0.3.1 and 0.3.2
|
30
|
+
|
31
|
+
### [Add ability to run specified ActiveJob queues consumers](https://github.com/veeqo/advanced-sneakers-activejob/pull/8)
|
32
|
+
|
33
|
+
Sneakers allows to specify consumer classes to run:
|
34
|
+
|
35
|
+
```sh
|
36
|
+
WORKERS=MyConsumer rake sneakers:run
|
37
|
+
```
|
38
|
+
|
39
|
+
Now it works for ActiveJob queues consumers as well:
|
40
|
+
|
41
|
+
```sh
|
42
|
+
WORKERS=AdvancedSneakersActiveJob::MailersConsumer rake sneakers:run
|
43
|
+
```
|
44
|
+
|
45
|
+
## Changes Between 0.3.0 and 0.3.1
|
46
|
+
|
47
|
+
### [Restore Sneakers::Worker::Classes methods](https://github.com/veeqo/advanced-sneakers-activejob/pull/6)
|
48
|
+
|
49
|
+
## Changes Between 0.2.3 and 0.3.0
|
2
50
|
|
3
51
|
This release does not change the observed behavior, but replaces the publisher with completely new implementation.
|
4
52
|
|
@@ -6,8 +54,8 @@ This release does not change the observed behavior, but replaces the publisher w
|
|
6
54
|
|
7
55
|
## Changes Between 0.2.2 and 0.2.3
|
8
56
|
|
9
|
-
### Refactored support for ActiveJob prefix
|
10
|
-
### Support for custom adapter per job
|
57
|
+
### [Refactored support for ActiveJob prefix](https://github.com/veeqo/advanced-sneakers-activejob/pull/3)
|
58
|
+
### [Support for custom adapter per job](https://github.com/veeqo/advanced-sneakers-activejob/pull/4)
|
11
59
|
|
12
60
|
## Changes Between 0.2.1 and 0.2.2
|
13
61
|
|
@@ -15,13 +63,13 @@ Cleanup of `puts` and logger mistakenly introduced in previous version
|
|
15
63
|
|
16
64
|
## Changes Between 0.2.0 and 0.2.1
|
17
65
|
|
18
|
-
### Support for ActiveJob prefix
|
66
|
+
### [Support for ActiveJob prefix](https://github.com/veeqo/advanced-sneakers-activejob/pull/2)
|
19
67
|
|
20
68
|
Fixed worker class name in rake task description
|
21
69
|
|
22
70
|
## Changes Between 0.1.0 and 0.2.0
|
23
71
|
|
24
|
-
### `message_options`
|
72
|
+
### [`message_options`](https://github.com/veeqo/advanced-sneakers-activejob/pull/1)
|
25
73
|
|
26
74
|
Customizable options for message publishing (`routing_key`, `headers`, etc)
|
27
75
|
|
data/README.md
CHANGED
@@ -34,11 +34,22 @@ Or install it yourself as:
|
|
34
34
|
config.active_job.queue_adapter = :advanced_sneakers
|
35
35
|
```
|
36
36
|
|
37
|
-
Run worker
|
37
|
+
Run worker for all queues of ActiveJob
|
38
38
|
```sh
|
39
39
|
rake sneakers:active_job
|
40
40
|
```
|
41
41
|
|
42
|
+
Run worker for picked queues of ActiveJob
|
43
|
+
```sh
|
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
|
51
|
+
```
|
52
|
+
|
42
53
|
## Unrouted messages
|
43
54
|
|
44
55
|
If message is published before routing has been configured (e.g. by consumer), it might be lost. To mitigate this problem the adapter uses [:mandatory](http://rubybunny.info/articles/exchanges.html#publishing_messages_as_mandatory) option for publishing messages. RabbitMQ returns unrouted messages back and the publisher is able to handle them:
|
@@ -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
|
@@ -68,5 +76,11 @@ module AdvancedSneakersActiveJob
|
|
68
76
|
|
69
77
|
[parameterized_string, 'consumer'].join('_').classify
|
70
78
|
end
|
79
|
+
|
80
|
+
def const_missing(name)
|
81
|
+
Sneakers::Worker::Classes.define_active_job_consumers
|
82
|
+
|
83
|
+
constants.include?(name) ? const_get(name) : super
|
84
|
+
end
|
71
85
|
end
|
72
86
|
end
|
@@ -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
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AdvancedSneakersActiveJob
|
4
|
+
module Support
|
5
|
+
class LocateWorkersByQueues
|
6
|
+
def initialize(queues)
|
7
|
+
@queues = queues.uniq.reject(&:blank?)
|
8
|
+
@queues_without_workers = []
|
9
|
+
@workers = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
detect_workers_for_queues!
|
14
|
+
ensure_all_workers_found!
|
15
|
+
|
16
|
+
@workers.uniq
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def ensure_all_workers_found!
|
22
|
+
return if @queues_without_workers.empty?
|
23
|
+
|
24
|
+
raise("Missing workers for queues: #{@queues_without_workers.join(', ')}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def all_workers
|
28
|
+
@all_workers ||= Sneakers::Worker::Classes.activejob_workers
|
29
|
+
end
|
30
|
+
|
31
|
+
def detect_workers_for_queues!
|
32
|
+
@queues.each do |queue|
|
33
|
+
matching_workers = all_workers.select { |klass| klass.queue_name.match?(queue_regex(queue)) }
|
34
|
+
|
35
|
+
if matching_workers.any?
|
36
|
+
@workers += matching_workers
|
37
|
+
else
|
38
|
+
@queues_without_workers << queue
|
39
|
+
end
|
40
|
+
end
|
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
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -5,10 +5,12 @@ require 'sneakers/tasks'
|
|
5
5
|
task :environment
|
6
6
|
|
7
7
|
namespace :sneakers do
|
8
|
-
desc 'Start work for ActiveJob only (set $
|
8
|
+
desc 'Start work for ActiveJob only (set $QUEUES=foo,bar.baz for processing of "foo" and "bar.baz" queues)'
|
9
9
|
task :active_job do
|
10
10
|
Rake::Task['environment'].invoke
|
11
11
|
|
12
|
+
populate_workers_by_queues if ENV['WORKERS'].blank? && ENV['QUEUES'].present?
|
13
|
+
|
12
14
|
# Enforsing ActiveJob-only workers
|
13
15
|
AdvancedSneakersActiveJob.configure { |c| c.activejob_workers_strategy = :only }
|
14
16
|
|
@@ -18,4 +20,14 @@ namespace :sneakers do
|
|
18
20
|
|
19
21
|
Rake::Task['sneakers:run'].invoke
|
20
22
|
end
|
23
|
+
|
24
|
+
def populate_workers_by_queues
|
25
|
+
require 'advanced_sneakers_activejob/support/locate_workers_by_queues'
|
26
|
+
::Rails.application.eager_load!
|
27
|
+
|
28
|
+
queues = ENV['QUEUES'].split(',')
|
29
|
+
workers = AdvancedSneakersActiveJob::Support::LocateWorkersByQueues.new(queues).call
|
30
|
+
|
31
|
+
ENV['WORKERS'] = workers.map(&:name).join(',')
|
32
|
+
end
|
21
33
|
end
|
@@ -54,7 +54,17 @@ module AdvancedSneakersActiveJob
|
|
54
54
|
@activejob_workers
|
55
55
|
end
|
56
56
|
|
57
|
-
|
57
|
+
def method_missing(method_name, *args, &block)
|
58
|
+
if call.respond_to?(method_name)
|
59
|
+
call.send(method_name, *args, &block)
|
60
|
+
else
|
61
|
+
super
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def respond_to_missing?(method_name, include_private = false)
|
66
|
+
call.respond_to?(method_name) || super
|
67
|
+
end
|
58
68
|
|
59
69
|
def define_active_job_consumers
|
60
70
|
active_job_classes_with_matching_adapter.each do |worker|
|
@@ -62,6 +72,8 @@ module AdvancedSneakersActiveJob
|
|
62
72
|
end
|
63
73
|
end
|
64
74
|
|
75
|
+
private
|
76
|
+
|
65
77
|
def active_job_classes_with_matching_adapter
|
66
78
|
([ActiveJob::Base] + ActiveJob::Base.descendants).select do |klass|
|
67
79
|
klass.queue_adapter == ::ActiveJob::QueueAdapters::AdvancedSneakersAdapter ||
|
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.
|
4
|
+
version: 0.3.5
|
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-
|
12
|
+
date: 2020-07-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activejob
|
@@ -167,6 +167,7 @@ files:
|
|
167
167
|
- lib/advanced_sneakers_activejob/handler.rb
|
168
168
|
- lib/advanced_sneakers_activejob/publisher.rb
|
169
169
|
- lib/advanced_sneakers_activejob/railtie.rb
|
170
|
+
- lib/advanced_sneakers_activejob/support/locate_workers_by_queues.rb
|
170
171
|
- lib/advanced_sneakers_activejob/tasks.rb
|
171
172
|
- lib/advanced_sneakers_activejob/version.rb
|
172
173
|
- lib/advanced_sneakers_activejob/workers_registry.rb
|