advanced-sneakers-activejob 0.3.2 → 0.3.3

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: b1edfa8193fc63efdc88c97b46bf55dddfe0bf062c81915cc32a0935c4621ac7
4
- data.tar.gz: 474ee8337a89e4546774190c22c77429687b02b81232a033a32a67213753b2e8
3
+ metadata.gz: 144ceb20cac503afd808245bd4da0311a541694bf7c9cc0768a599355c60b001
4
+ data.tar.gz: fe1f7cce63c635af8647b96b0a140653c37cc44c37b0250464689cb895e472eb
5
5
  SHA512:
6
- metadata.gz: a955f43e34ea3128052261fcd03c88d5e20563ab5df37b18bdb5f1ffecdf70c13d659aa70acb382e7d7f4f7e76fd9f1f7a2b1f323e1aadeb107229164258a57c
7
- data.tar.gz: 88bed92d02624c64834f87ae62baaa9e43edde9556bf6082c96f0d4021e35da542132a773ccf9c7ce9102a800f63e2ce510e5a1384fcef6e126fbb79a9d1f811
6
+ metadata.gz: 2b6cc96c1725224e5e3663c221fe080ff6874114ab8a667dbf5ebe8eb935819f613e617efbfb81ab183f2b3a9ee1d7ff07c0bdc613175419d94c1031fdbadb3f
7
+ data.tar.gz: 57bfb70bc33895e6b30a30086a607dcdbec2a5b829b2fd95ccae6f5a305a267106833a8e54203858b5dcf37e5e3cabd56facf5e8aba7ca0785032432f9a620ac
@@ -1,3 +1,13 @@
1
+ ## Changes Between 0.3.2 and 0.3.3
2
+
3
+ ### [Add ability to run ActiveJob consumers by queues](https://github.com/veeqo/advanced-sneakers-activejob/pull/9)
4
+
5
+ Works with `sneakers:active_job` task only!
6
+
7
+ ```sh
8
+ rake sneakers:active_job QUEUES=mailers,default
9
+ ```
10
+
1
11
  ## Changes Between 0.3.1 and 0.3.2
2
12
 
3
13
  ### [Add ability to run specified ActiveJob queues consumers](https://github.com/veeqo/advanced-sneakers-activejob/pull/8)
data/README.md CHANGED
@@ -34,11 +34,16 @@ 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
+ rake sneakers:active_job QUEUES=mailers,foo,bar
45
+ ```
46
+
42
47
  ## Unrouted messages
43
48
 
44
49
  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:
@@ -0,0 +1,44 @@
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
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
+ worker = all_workers.detect { |klass| klass.queue_name == queue }
34
+
35
+ if worker
36
+ @workers << worker
37
+ else
38
+ @queues_without_workers << queue
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ 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 $WORKERS=AdvancedSneakersActiveJob::FooConsumer for processing of :foo queue)'
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AdvancedSneakersActiveJob
4
- VERSION = '0.3.2'
4
+ VERSION = '0.3.3'
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.2
4
+ version: 0.3.3
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-05 00:00:00.000000000 Z
12
+ date: 2020-06-09 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