activejob-locking 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +4 -0
- data/README.md +7 -5
- data/lib/activejob/locking/base.rb +6 -2
- data/test/jobs/fail_job.rb +1 -1
- data/test/jobs/serial_job.rb +1 -1
- data/test/jobs/unique_job.rb +1 -1
- 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: dc5170f734ea482c37205c31fd82389b4a67225c
|
4
|
+
data.tar.gz: 9a54a53cbd88f1da58824e05b1c51502020787e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7c86564b3c0d43210e7fe90abb524d4a8e7151113ea950edf5625590986e954a46e8be3da0f24118ff43ac81064c9e85929da66a4af9e52d133aa1ab3e912fb
|
7
|
+
data.tar.gz: 2e13fe88cfcb4cba7cc953986d29e076b704fad7400e6b59075f3fd491f7fb785428f6edf9be97fad5ff2b6858f37ffc3367282ff2b0d9e59e8986a6c5052ed1
|
data/HISTORY.md
CHANGED
data/README.md
CHANGED
@@ -34,11 +34,11 @@ class UniqueJob < ActiveJob::Base
|
|
34
34
|
include ActiveJob::Locking::Unique
|
35
35
|
|
36
36
|
# Make sure the lock_key is always the same
|
37
|
-
def lock_key
|
37
|
+
def lock_key(object)
|
38
38
|
self.class.name
|
39
39
|
end
|
40
40
|
|
41
|
-
def perform
|
41
|
+
def perform(object)
|
42
42
|
# do some work
|
43
43
|
end
|
44
44
|
end
|
@@ -102,12 +102,14 @@ and performed.
|
|
102
102
|
By default the key is defined as:
|
103
103
|
|
104
104
|
```ruby
|
105
|
-
def lock_key
|
105
|
+
def lock_key(*args)
|
106
106
|
[self.class.name, serialize_arguments(self.arguments)].join('/')
|
107
107
|
end
|
108
108
|
```
|
109
109
|
Thus it has the format `<job class name>/<serialized_job_arguments>`
|
110
110
|
|
111
|
+
The args passed to the lock key method are the same that are passed to the job's perform method.
|
112
|
+
|
111
113
|
To use this gem, you will want to override this method per job.
|
112
114
|
|
113
115
|
### Examples
|
@@ -115,7 +117,7 @@ To use this gem, you will want to override this method per job.
|
|
115
117
|
Allow only one job per queue to be enqueued or performed:
|
116
118
|
|
117
119
|
```ruby
|
118
|
-
def lock_key
|
120
|
+
def lock_key(*args)
|
119
121
|
self.queue
|
120
122
|
end
|
121
123
|
```
|
@@ -123,7 +125,7 @@ Allow only one job per queue to be enqueued or performed:
|
|
123
125
|
Allow only one instance of a job class to be enqueued of performed:
|
124
126
|
|
125
127
|
```ruby
|
126
|
-
def lock_key
|
128
|
+
def lock_key(*args)
|
127
129
|
self.class.name
|
128
130
|
end
|
129
131
|
```
|
@@ -24,7 +24,7 @@ module ActiveJob
|
|
24
24
|
self.adapter.lock_token = job_data['lock_token']
|
25
25
|
end
|
26
26
|
|
27
|
-
def lock_key
|
27
|
+
def lock_key(*args)
|
28
28
|
[self.class.name, serialize_arguments(self.arguments)].join('/')
|
29
29
|
end
|
30
30
|
|
@@ -36,8 +36,12 @@ module ActiveJob
|
|
36
36
|
# Merge local and global options
|
37
37
|
merged_options = ActiveJob::Locking.options.dup.merge(self.class.lock_options)
|
38
38
|
|
39
|
+
# Get the key
|
40
|
+
base_key = self.lock_key(*self.arguments)
|
41
|
+
key = "activejoblocking:#{base_key}"
|
42
|
+
|
39
43
|
# Remember the lock might be acquired in one process and released in another
|
40
|
-
merged_options.adapter.new(
|
44
|
+
merged_options.adapter.new(key, merged_options)
|
41
45
|
end
|
42
46
|
@adapter
|
43
47
|
end
|
data/test/jobs/fail_job.rb
CHANGED
data/test/jobs/serial_job.rb
CHANGED
data/test/jobs/unique_job.rb
CHANGED