advanced-sneakers-activejob 0.3.3 → 0.3.4

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: 818f3505d0e58ddf098ed2884db036a0e16019e04641e6c8ca457e8c48850910
4
+ data.tar.gz: 374b620fbb9092a3c24547d6c036b6da0973e0059ce910cca559e7dae59eb028
5
5
  SHA512:
6
- metadata.gz: 2b6cc96c1725224e5e3663c221fe080ff6874114ab8a667dbf5ebe8eb935819f613e617efbfb81ab183f2b3a9ee1d7ff07c0bdc613175419d94c1031fdbadb3f
7
- data.tar.gz: 57bfb70bc33895e6b30a30086a607dcdbec2a5b829b2fd95ccae6f5a305a267106833a8e54203858b5dcf37e5e3cabd56facf5e8aba7ca0785032432f9a620ac
6
+ metadata.gz: fc3de6bfbd43c907c242ac65104e7cd91523930f209e216511ad4877dbd0ac836d51d291c71eb776559eb1b5d3667236d36f6641a5255652f7be33dbb07bc820
7
+ data.tar.gz: 6dcc9e3426e5592738c44d3f9feb658ba57e17713ed185bf3f76b9cc6df7d2886064abd031efc8a3913c9b41c5dfff89671f59809af42c42b018e4b5d1d40bfb
@@ -1,3 +1,13 @@
1
+ ## Changes Between 0.3.3 and 0.3.4
2
+
3
+ ### [Support for wildcards to run ActiveJob consumers by queues](https://github.com/veeqo/advanced-sneakers-activejob/pull/10)
4
+
5
+ Works with `sneakers:active_job` task only!
6
+
7
+ ```sh
8
+ QUEUES=mailers,index.*,telemetery.# rake sneakers:active_job
9
+ ```
10
+
1
11
  ## Changes Between 0.3.2 and 0.3.3
2
12
 
3
13
  ### [Add ability to run ActiveJob consumers by queues](https://github.com/veeqo/advanced-sneakers-activejob/pull/9)
@@ -5,7 +15,7 @@
5
15
  Works with `sneakers:active_job` task only!
6
16
 
7
17
  ```sh
8
- rake sneakers:active_job QUEUES=mailers,default
18
+ QUEUES=mailers,default rake sneakers:active_job
9
19
  ```
10
20
 
11
21
  ## Changes Between 0.3.1 and 0.3.2
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
@@ -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.3.4'
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.3.4
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-06-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activejob