sidekiq-apriori 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/README.md +20 -9
- data/lib/sidekiq-apriori/version.rb +1 -1
- data/lib/sidekiq-apriori/worker.rb +29 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afd46659ed78b4be97a6a3a3fb2fa6abce7c1818
|
4
|
+
data.tar.gz: aef21efe430abb2fabafeaef22cf333e2ce1f63c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb4148906994f507b4b7064b0a5a6e3eab2d48305bf9479b08802751cbed4745ee90bab92f2690f3bc32a34ca1c950607385181c55fab50e022e0b500ed249d1
|
7
|
+
data.tar.gz: 4dcdc931bc462cd284e7c8e5a1cf90711546c5e72d062fe3e86490fd5c5b39de35944c9a9dea098278af1d685a7554b38e98e78ca68465d2aceb9a34050dd449
|
data/.travis.yml
CHANGED
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.
|
46
|
-
|
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
|
-
|
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
|
-
|
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
|
111
|
-
|
112
|
-
|
113
|
-
|
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
|
-------
|
@@ -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
|
-
|
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
|
-
|
18
|
-
|
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
|
-
|
24
|
-
|
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
|