delayed_job_loner 0.0.4 → 0.1.0
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.
- data/README.md +7 -3
- data/lib/delayed_job_loner/init.rb +1 -1
- data/lib/delayed_job_loner/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -27,7 +27,11 @@ $ rake db:migrate
|
|
27
27
|
|
28
28
|
## Usage
|
29
29
|
|
30
|
-
Pass the option `:unique_on` to any method that you would provide `:priority` or `:run_at`. `:unique_on` should be an array of attributes that you want to check the uniqueness of the job against.
|
30
|
+
Pass the option `:loner` or `:unique_on` to any method that you would provide `:priority` or `:run_at`. `:unique_on` should be an array of attributes that you want to check the uniqueness of the job against.
|
31
|
+
|
32
|
+
* `:loner` just specifies that the job should be unique and will only check against the method name and object id
|
33
|
+
* `:unique_on` allows you to specify the fields that it will check uniqueness against
|
34
|
+
|
31
35
|
Here is an example:
|
32
36
|
```ruby
|
33
37
|
class Foo < ActiveRecord::Base
|
@@ -35,7 +39,7 @@ class Foo < ActiveRecord::Base
|
|
35
39
|
def do_all_the_things
|
36
40
|
# All the things!
|
37
41
|
end
|
38
|
-
handle_asynchronously :do_all_the_things, :unique_on => [:
|
42
|
+
handle_asynchronously :do_all_the_things, :unique_on => [:name, :other]
|
39
43
|
|
40
44
|
def do_some_of_the_things
|
41
45
|
# Some of the things!
|
@@ -54,7 +58,7 @@ foo.do_all_the_things
|
|
54
58
|
|
55
59
|
foo.delay(:priority => 10).do_some_of_the_things
|
56
60
|
# Creates a new job
|
57
|
-
foo.delay(:priority => 10, :
|
61
|
+
foo.delay(:priority => 10, :loner => true).do_some_of_the_things
|
58
62
|
# Doesn't create a new job
|
59
63
|
foo.delay(:priority => 10).do_some_of_the_things
|
60
64
|
# Creates a new job because we didn't specify :unique_on
|
@@ -10,8 +10,8 @@ module Delayed
|
|
10
10
|
validate :check_uniqueness
|
11
11
|
|
12
12
|
def check_uniqueness
|
13
|
-
self.loner_hash = generate_loner_hash
|
14
13
|
if loner || unique_on
|
14
|
+
self.loner_hash = generate_loner_hash
|
15
15
|
self.errors.add(:base, "Job already exists") unless self.class.where(loner_hash: self.loner_hash, locked_by: nil).first.nil?
|
16
16
|
else
|
17
17
|
true
|