delayed_job_loner 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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 => [:id]
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, :unique_on => [:id]).do_some_of_the_things
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
@@ -1,3 +1,3 @@
1
1
  module DelayedJobLoner
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_job_loner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: