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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1b1ea7063b5406f553e6d4282892299b6733cf5
4
- data.tar.gz: 4fc8b9e358ec0583dc02eb6e6c069ef079653ad4
3
+ metadata.gz: dc5170f734ea482c37205c31fd82389b4a67225c
4
+ data.tar.gz: 9a54a53cbd88f1da58824e05b1c51502020787e0
5
5
  SHA512:
6
- metadata.gz: e84f37fc29ad783441943835f2157e530522dc52ff2e6953c047d029e2d19ad654c6c2f300ae1df277013c7f9e2cca8cd048002e234fb81f518f4572aff667e8
7
- data.tar.gz: 9f05089c530aa8bcb0db266eda5210126d7d25634462495c448861b9057aa7d9ff037301081b74c1ca90de574fc62b9358bca76d88059c035383903e88a523a2
6
+ metadata.gz: f7c86564b3c0d43210e7fe90abb524d4a8e7151113ea950edf5625590986e954a46e8be3da0f24118ff43ac81064c9e85929da66a4af9e52d133aa1ab3e912fb
7
+ data.tar.gz: 2e13fe88cfcb4cba7cc953986d29e076b704fad7400e6b59075f3fd491f7fb785428f6edf9be97fad5ff2b6858f37ffc3367282ff2b0d9e59e8986a6c5052ed1
data/HISTORY.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.0 (2017-06-21)
2
+
3
+ - Change lock_key signature
4
+
1
5
  ## 0.2.0 (2017-06-20)
2
6
 
3
7
  - Bug fixes
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(self.lock_key, merged_options)
44
+ merged_options.adapter.new(key, merged_options)
41
45
  end
42
46
  @adapter
43
47
  end
@@ -4,7 +4,7 @@ class FailJob < ActiveJob::Base
4
4
  self.lock_acquire_time = 2
5
5
 
6
6
  # We want the job ids to be all the same for testing
7
- def lock_key
7
+ def lock_key(index, sleep_time)
8
8
  self.class.name
9
9
  end
10
10
 
@@ -4,7 +4,7 @@ class SerialJob < ActiveJob::Base
4
4
  self.lock_acquire_time = 2
5
5
 
6
6
  # We want the job ids to be all the same for testing
7
- def lock_key
7
+ def lock_key(index, sleep_time)
8
8
  self.class.name
9
9
  end
10
10
 
@@ -4,7 +4,7 @@ class UniqueJob < ActiveJob::Base
4
4
  self.lock_acquire_time = 2
5
5
 
6
6
  # We want the job ids to be all the same for testing
7
- def lock_key
7
+ def lock_key(index, sleep_time)
8
8
  self.class.name
9
9
  end
10
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activejob-locking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Savage