sidekiq-apriori 0.0.2 → 0.0.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
  SHA1:
3
- metadata.gz: 3203f8525a25c20fa3a2809bbc431ee64b27ee81
4
- data.tar.gz: 8dc78be48780cf4eb5c9c010d73fae05f0a24f31
3
+ metadata.gz: afd46659ed78b4be97a6a3a3fb2fa6abce7c1818
4
+ data.tar.gz: aef21efe430abb2fabafeaef22cf333e2ce1f63c
5
5
  SHA512:
6
- metadata.gz: 3227506019efd51481e045ebb7fc613a624687b5c64e351d609847445522babf56956add7474f4e017bb042d5750196a335b504001f11ce170b46affa93e65af
7
- data.tar.gz: 4b924a010def90fa31bd661c54366e12aee79c58f67a0a6e747b37913f6164b00aed989155713895f55cc68f6ea3a68148dc644a86bea95239b0735e02c3f385
6
+ metadata.gz: bb4148906994f507b4b7064b0a5a6e3eab2d48305bf9479b08802751cbed4745ee90bab92f2690f3bc32a34ca1c950607385181c55fab50e022e0b500ed249d1
7
+ data.tar.gz: 4dcdc931bc462cd284e7c8e5a1cf90711546c5e72d062fe3e86490fd5c5b39de35944c9a9dea098278af1d685a7554b38e98e78ca68465d2aceb9a34050dd449
data/.travis.yml CHANGED
@@ -2,4 +2,3 @@ language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
4
  - 1.9.3
5
- - 1.8.7
data/README.md CHANGED
@@ -42,8 +42,10 @@ want to disallow unset priorities, leave the nil in.
42
42
  sidekiq-apriori is inspired by (a response to?) [sidekiq-priority](https://github.com/socialpandas/sidekiq-priority), in which the
43
43
  order of the priorities is important. Contrary to the approach taken by
44
44
  sidekiq-priority, sidekiq-apriori uses sidekiq's built in mechanism for
45
- configuring the order of processing. So, for example, if your sidekiq.yml
46
- currently looks like this:
45
+ configuring the order of processing. As such, the ordering of priorities is
46
+ accomplished in the sidekiq.yml.
47
+
48
+ So, for example, if your sidekiq.yml currently looks like this:
47
49
 
48
50
  ```yaml
49
51
  ## sidekiq.yml
@@ -56,7 +58,7 @@ verbose: false
56
58
  - background
57
59
  ```
58
60
 
59
- you might want to change the 'queues' entry to look more like this:
61
+ You might want to change the 'queues' entry to look more like this:
60
62
 
61
63
  ```yaml
62
64
  :queues:
@@ -68,8 +70,14 @@ you might want to change the 'queues' entry to look more like this:
68
70
  - background
69
71
  ```
70
72
 
71
- Use
72
- ---
73
+ To route an item to a prioritized queue, append an options hash of the form
74
+ ```{ :priority => 'wut' }``` to the end of the arguments. If you're using ruby 2
75
+ & have included ```Sidekiq::Apriori::Worker``` in your worker class then this
76
+ should be enough. Otherwise, you'll need to update that method to optionally
77
+ take an additional argument
78
+
79
+ Additional Utility
80
+ ------------------
73
81
 
74
82
  In addition to the use described in the PRIORITIES section, some tooling is
75
83
  provided for active record classes with priority as an attribute:
@@ -107,10 +115,13 @@ end
107
115
 
108
116
  If you're lucky enough to be using ruby 2, you can save yourself some work by
109
117
  including ```Sidekiq::Apriori::Worker``` instead of ```Sidekiq::Worker``` in your
110
- worker classes. This will have the nifty side effect of saving you the effort of
111
- changing the definition of the classes' perform method & its invocation.
112
- ```Sidekiq::Apriori::Worker``` uses ```prepend``` to define a perform which will
113
- take an optional hash containing a priority designation.
118
+ worker classes. This will save you the effort of changing the definition of the
119
+ classes' perform method & all of its invocations. ```Sidekiq::Apriori::Worker```
120
+ uses ```prepend``` to define a perform which will take an optional hash containing
121
+ a priority designation.
122
+
123
+ If you're not using ruby 2, you'll need to redefine your perform method to take an
124
+ additional, optional argument
114
125
 
115
126
  License
116
127
  -------
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Apriori
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -4,6 +4,8 @@ module Sidekiq::Apriori
4
4
  base.class_eval do
5
5
  include Sidekiq::Worker if defined?(Sidekiq::Worker)
6
6
 
7
+ ## Prepend is only available for ruby > 2.0.0
8
+ #
7
9
  version = RUBY_VERSION.split(/\./).map(&:to_i) rescue []
8
10
  prepend ClassMethods if version.first > 1
9
11
  end
@@ -12,17 +14,36 @@ module Sidekiq::Apriori
12
14
 
13
15
  module ClassMethods
14
16
  def perform(*args)
15
- retried = false
17
+ super(*args)
18
+ rescue ArgumentError => err
19
+ raise err unless has_priority?(args.last)
20
+ super(*args[0..-2])
21
+ end
22
+
23
+ def has_priority?(options)
24
+ return false unless hashlike?(options)
25
+ stringify_keys(options).has_key?('priority')
26
+ end
27
+ private :has_priority?
16
28
 
17
- begin
18
- super(*args)
19
- rescue ArgumentError => err
20
- raise err unless
21
- args.last.is_a?(Hash) && args.last.has_key?(:priority)
29
+ def stringify_keys(hashish)
30
+ duplicate = hashish.dup
22
31
 
23
- args = args[0..-2]
24
- (retried = true ) && retry
32
+ if hashlike?(hashish)
33
+ duplicate.keys.each do |key|
34
+ duplicate[key.to_s] = duplicate.delete(key)
35
+ end
25
36
  end
37
+
38
+ duplicate
26
39
  end
40
+ private :stringify_keys
41
+
42
+ def hashlike?(hashish)
43
+ [ :keys, :has_key?, :[] ].
44
+ map { |method| hashish.respond_to?(method) }.all?
45
+ end
46
+ private :hashlike?
47
+
27
48
  end
28
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-apriori
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Thomas