resque-unique_by_arity 3.0.1 → 3.0.2
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/README.md +46 -16
- data/lib/resque/unique_by_arity.rb +1 -0
- data/lib/resque/unique_by_arity/global_configuration.rb +10 -10
- data/lib/resque/unique_by_arity/modulizer.rb +1 -1
- data/lib/resque/unique_by_arity/unique_job.rb +0 -2
- data/lib/resque/unique_by_arity/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ab7e18a0ccb64d7ed0045aa0047e0ffc7594c1688ccbdae986e098a9e53c7ec
|
4
|
+
data.tar.gz: d699f5cbb3caf4364fe6160227c64d920827ed597417ac40dce745d337f9fecf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2888fff88866a0a5c51c20b842571c7b664681bba2b978229b2e1bc088a673b1d68a7a28765868f66f10aebe6e0cf18b3a401863899073d609a0c841442a7572
|
7
|
+
data.tar.gz: 990f6432863e2c847919cc96025cd7f56b27844b1dee41839352d312950eae6331fc7b3ee433515229f0fb5dc11bf3647cbb2abdd666dd8274998bd0b95f2fec
|
data/README.md
CHANGED
@@ -74,6 +74,36 @@ Or install it yourself as:
|
|
74
74
|
|
75
75
|
## Usage
|
76
76
|
|
77
|
+
### Global Configuration
|
78
|
+
|
79
|
+
The following is showing the default values. These global configs are copied into each per-class config unless they are overridden by the class config.
|
80
|
+
|
81
|
+
|
82
|
+
Create an initializer (e.g. `config/initializers/resque-unique_by_arity.rb` for rails) and customize the following:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
Resque::UniqueByArity.configure do |config|
|
86
|
+
config.logger = nil
|
87
|
+
config.log_level = :debug
|
88
|
+
config.arity_for_uniqueness = 0
|
89
|
+
config.unique_at_runtime = false
|
90
|
+
config.unique_in_queue = false
|
91
|
+
# No need to do the following if keeping default values
|
92
|
+
config.runtime_lock_timeout = 60 * 60 * 24 * 5
|
93
|
+
config.runtime_requeue_interval = 1
|
94
|
+
config.unique_at_runtime_key_base = 'r-uar'.freeze
|
95
|
+
config.lock_after_execution_period = 0
|
96
|
+
config.ttl = -1
|
97
|
+
config.unique_in_queue_key_base = 'r-uiq'.freeze
|
98
|
+
# Debug Mode is preferably set via an environment variable:
|
99
|
+
# to one of 'true', 'arity', or 'arity,queue,runtime' for all three tools:
|
100
|
+
# ENV['RESQUE_DEBUG'] = 'true'
|
101
|
+
# config.debug_mode = true
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
### Per Job Class Configuration
|
106
|
+
|
77
107
|
This gem will take care to set the class instance variables (similar to the
|
78
108
|
familiar `@queue` class instance variable) that are utilized by
|
79
109
|
`resque-unique_in_queue` and `resque-unique_at_runtime` (default values shown):
|
@@ -93,16 +123,19 @@ This gem will take care to set the class instance variables (similar to the
|
|
93
123
|
All you need to do is configure this gem accordingly:
|
94
124
|
```ruby
|
95
125
|
include Resque::Plugins::UniqueByArity.new(
|
96
|
-
arity_for_uniqueness:
|
97
|
-
|
98
|
-
|
126
|
+
arity_for_uniqueness: 1,
|
127
|
+
# Turn on one or both of the following:
|
128
|
+
unique_at_runtime: false,
|
129
|
+
unique_in_queue: false,
|
99
130
|
# No need to do the following if keeping default values
|
100
131
|
runtime_lock_timeout: 60 * 60 * 24 * 5,
|
101
132
|
runtime_requeue_interval: 1,
|
102
|
-
|
133
|
+
# would override the global setting, probably a bad idea.
|
134
|
+
# unique_at_runtime_key_base: 'r-uar'.freeze,
|
103
135
|
lock_after_execution_period: 0,
|
104
|
-
ttl:
|
105
|
-
|
136
|
+
ttl: -1,
|
137
|
+
# would override the global setting, probably a bad idea.
|
138
|
+
# unique_in_queue_key_base: 'r-uiq'.freeze
|
106
139
|
)
|
107
140
|
```
|
108
141
|
|
@@ -328,30 +361,27 @@ class MyJob
|
|
328
361
|
# Core hashing algorithm for a job used for *all 3 types* of uniqueness
|
329
362
|
# @return [Array<String, arguments>], where the string is the unique digest, and arguments are the specific args that were used to calculate the digest
|
330
363
|
def self.redis_unique_hash(payload)
|
331
|
-
modulizer.rb
|
332
364
|
# for how the built-in version works
|
333
365
|
# uniqueness_args = payload["args"] # over simplified & ignoring arity
|
334
366
|
# args = { class: job, args: uniqueness_args }
|
335
367
|
# return [Digest::MD5.hexdigest(Resque.encode(args)), uniqueness_args]
|
336
368
|
end
|
337
369
|
|
338
|
-
|
339
|
-
def self.unique_at_runtime_redis_key_prefix
|
370
|
+
def self.unique_in_queue_redis_key_prefix
|
340
371
|
# "unique_job:#{self}" # <= default value
|
341
372
|
end
|
373
|
+
|
374
|
+
def self.unique_in_queue_redis_key(queue, payload)
|
375
|
+
# unique_hash, _args_for_uniqueness = redis_unique_hash(payload)
|
376
|
+
# "#{unique_in_queue_key_namespace(queue)}:#{unique_in_queue_redis_key_prefix}:#{unique_hash}"
|
377
|
+
end
|
342
378
|
|
343
|
-
|
344
|
-
def self.unique_at_runtime_key_namespace(queue = nil)
|
379
|
+
def self.unique_in_queue_key_namespace(queue = nil)
|
345
380
|
# definition depends on which type of uniqueness is chosen, be careful if you customize
|
346
381
|
# "r-uiq:queue:#{queue}:job" # <= is for unique within queue at queue time
|
347
382
|
# "r-uiq:across_queues:job" # <= is for unique across all queues at queue time
|
348
383
|
end
|
349
384
|
|
350
|
-
def self.unique_in_queue_redis_key(queue, payload)
|
351
|
-
# unique_hash, _args_for_uniqueness = redis_unique_hash(payload)
|
352
|
-
# "#{unique_at_runtime_key_namespace(queue)}:#{unique_at_runtime_redis_key_prefix}:#{unique_hash}"
|
353
|
-
end
|
354
|
-
|
355
385
|
def self.runtime_key_namespace
|
356
386
|
# "unique_at_runtime:#{self}"
|
357
387
|
end
|
@@ -6,22 +6,28 @@ module Resque
|
|
6
6
|
# Will be used as the default settings for the per-job configs.
|
7
7
|
class GlobalConfiguration < Configuration
|
8
8
|
DEFAULT_LOG_LEVEL = :debug
|
9
|
-
DEFAULT_AT_RUNTIME_KEY_BASE = 'r-uar'.freeze
|
10
|
-
DEFAULT_IN_QUEUE_KEY_BASE = 'r-uiq'.freeze
|
11
9
|
|
12
10
|
# For resque-unique_at_runtime
|
13
11
|
DEFAULT_LOCK_TIMEOUT = 60 * 60 * 24 * 5
|
14
12
|
DEFAULT_REQUEUE_INTERVAL = 1
|
15
|
-
|
13
|
+
DEFAULT_AT_RUNTIME_KEY_BASE = 'r-uar'.freeze
|
16
14
|
|
17
15
|
# For resque-unique_in_queue
|
18
16
|
DEFAULT_LOCK_AFTER_EXECUTION_PERIOD = 0
|
19
17
|
DEFAULT_TTL = -1
|
20
|
-
|
18
|
+
DEFAULT_IN_QUEUE_KEY_BASE = 'r-uiq'.freeze
|
21
19
|
|
22
20
|
include Singleton
|
23
21
|
|
24
22
|
def initialize
|
23
|
+
reset
|
24
|
+
end
|
25
|
+
|
26
|
+
def defcon(sym)
|
27
|
+
self.send(sym)
|
28
|
+
end
|
29
|
+
|
30
|
+
def reset
|
25
31
|
debug_mode_from_env
|
26
32
|
@logger = nil
|
27
33
|
@log_level = DEFAULT_LOG_LEVEL
|
@@ -33,8 +39,6 @@ module Resque
|
|
33
39
|
@unique_at_runtime_key_base = DEFAULT_AT_RUNTIME_KEY_BASE
|
34
40
|
@unique_in_queue_key_base = DEFAULT_IN_QUEUE_KEY_BASE
|
35
41
|
@unique_at_runtime = false
|
36
|
-
@unique_at_runtime_key_base = DEFAULT_UNIQUE_AT_RUNTIME_KEY_BASE
|
37
|
-
@unique_in_queue_key_base = DEFAULT_UNIQUE_IN_QUEUE_KEY_BASE
|
38
42
|
@unique_in_queue = false
|
39
43
|
@unique_across_queues = false
|
40
44
|
@ttl = DEFAULT_TTL
|
@@ -43,10 +47,6 @@ module Resque
|
|
43
47
|
@logger ||= Logger.new(STDOUT)
|
44
48
|
end
|
45
49
|
end
|
46
|
-
|
47
|
-
def defcon(sym)
|
48
|
-
self.send(sym)
|
49
|
-
end
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -53,7 +53,7 @@ module Resque
|
|
53
53
|
#
|
54
54
|
# @return [Fixnum] number of keys that were deleted
|
55
55
|
define_method(:purge_unique_queued_redis_keys) do
|
56
|
-
#
|
56
|
+
# unique_in_queue_key_namespace may or may not ignore the queue passed in, depending on config.
|
57
57
|
key_match = "#{unique_in_queue_key_namespace(instance_variable_get(:@queue))}:#{unique_in_queue_redis_key_prefix}:*"
|
58
58
|
keys = Resque.redis.keys(key_match)
|
59
59
|
Resque::UniqueByArity.log("#{Resque::UniqueByArity::PLUGIN_TAG}#{Resque::UniqueInQueue::PLUGIN_TAG} #{ColorizedString['Purging'].red} #{keys.length} keys from #{ColorizedString[key_match].red}")
|
@@ -17,8 +17,6 @@
|
|
17
17
|
module Resque
|
18
18
|
module UniqueByArity
|
19
19
|
module UniqueJob
|
20
|
-
PLUGIN_TAG = (ColorizedString['[R-UBA] '].green).freeze
|
21
|
-
|
22
20
|
def uniq_log(message, config_proxy = nil)
|
23
21
|
config_proxy ||= uniq_config
|
24
22
|
config_proxy.logger&.send(config_proxy.log_level, message) if config_proxy.logger
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-unique_by_arity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter H. Boling
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|