resque-better_unique 1.0.1 → 1.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 +57 -2
- data/lib/resque/plugins/better_unique.rb +1 -1
- data/lib/resque/plugins/better_unique/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 926c1f77a991608f8cb0d9ccd69fb90fa467962b
|
4
|
+
data.tar.gz: b485017b4d607b88aad87861278df221f77a63ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67b86180d9dda8dcb39bb5d3b86f6ad9050da7bc1d8885132bec37489103c213fe7978f5384ee2551e398d94ac271a85c856f48f5e50ebfaf062469b538f7164
|
7
|
+
data.tar.gz: 2d006f9a4ab41ba6910e003eef4d5a20398a62f0ba07ff7394e20734c2ba139bb8eff4be890d1d6f9464efa96bc1f7255bbf8ef6dd0bb9450eecd49339d23fec
|
data/README.md
CHANGED
@@ -25,11 +25,11 @@ Include this plugin into your job class and call the `unique` method
|
|
25
25
|
```ruby
|
26
26
|
class MyWorker
|
27
27
|
include Resque::Plugins::BetterUnique
|
28
|
-
|
28
|
+
unique_job :while_executing, timeout: 5.minutes
|
29
29
|
end
|
30
30
|
```
|
31
31
|
|
32
|
-
The
|
32
|
+
The unique_job method takes up to two arguments:
|
33
33
|
- mode: (default=:until_executed)
|
34
34
|
* while_executing: only one distinct job can be processed at a time
|
35
35
|
* until_executing: only one job can be queued at a time
|
@@ -39,6 +39,61 @@ The unique method takes up to two arguments:
|
|
39
39
|
* timeout - integer or object that responds to to_i - How long should a lock live
|
40
40
|
* unique_args - a proc or a symbol which takes the arguments of perform and returns the arguments that should be used to determine uniqueness
|
41
41
|
|
42
|
+
### Examples:
|
43
|
+
Specify method to define unique args:
|
44
|
+
```ruby
|
45
|
+
class MyWorker
|
46
|
+
include Resque::Plugins::BetterUnique
|
47
|
+
unique_job :while_executing, timeout: 5.minutes, unique_args: unique_job_arguments
|
48
|
+
|
49
|
+
def self.unique_job_arguments(*args)
|
50
|
+
[args[0], args[3]]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
Specify Proc to define unique args:
|
56
|
+
```ruby
|
57
|
+
class MyWorker
|
58
|
+
include Resque::Plugins::BetterUnique
|
59
|
+
unique_job :while_executing, timeout: 5.minutes, unique_args: ->(*args) { [args[0], args[3]] }
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
Override lock_key method:
|
64
|
+
```ruby
|
65
|
+
class MyWorker
|
66
|
+
include Resque::Plugins::BetterUnique
|
67
|
+
unique_job :while_executing, timeout: 5.minutes
|
68
|
+
|
69
|
+
def self.lock_key(*args)
|
70
|
+
"lock:my_lock:#{args.to_s}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
Clear lock for a single job:
|
76
|
+
```ruby
|
77
|
+
class MyWorker
|
78
|
+
include Resque::Plugins::BetterUnique
|
79
|
+
unique_job :until_executed, timeout: 5.minutes
|
80
|
+
end
|
81
|
+
|
82
|
+
Resque.enqueue(MyWorker, {some: :args})
|
83
|
+
MyWorker.release_lock({some: :args})
|
84
|
+
```
|
85
|
+
|
86
|
+
Clear all locks for a worker class:
|
87
|
+
```ruby
|
88
|
+
class MyWorker
|
89
|
+
include Resque::Plugins::BetterUnique
|
90
|
+
unique_job :while_executing, timeout: 5.minutes
|
91
|
+
end
|
92
|
+
100.times { Resque.enqueue(MyWorker, rand(1000))}
|
93
|
+
MyWorker.release_all_locks
|
94
|
+
```
|
95
|
+
NOTE: `release_all_locks` requires redis-server >= 2.8. Only removes locks for the class on which it was called.
|
96
|
+
|
42
97
|
## Development
|
43
98
|
|
44
99
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-better_unique
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Will Bryant
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
133
|
version: '0'
|
134
134
|
requirements: []
|
135
135
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.6.
|
136
|
+
rubygems_version: 2.6.14
|
137
137
|
signing_key:
|
138
138
|
specification_version: 4
|
139
139
|
summary: A resque plugin for better control over unique jobs
|