delayed_job_prevent_duplicate 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: b9dddeb211dc3682bcf52ea61c6fbae09b2f53b464dfc77be09d41e802c81451
4
- data.tar.gz: 9235b96c6047126767f6412ad1bf0e216f2f3172e244caecdf22880256a852c6
3
+ metadata.gz: f8668bbcfafe20c2670059fcb0ff0a53d6d75ce1987fd0ce5246bed70660b8ef
4
+ data.tar.gz: 39369122bb75be1eaa05f6a21ac4ecc557be61c39cdf03d86c7b1b10dc1f925c
5
5
  SHA512:
6
- metadata.gz: fe9167455f11e23771989414b78731394123d339884bf607acef3d11ab32e4b46f1cdd5e62b7fbac8e3e3443e6f31b8dcbf7f63a9f1c162544856d37f97282b9
7
- data.tar.gz: f35d3fa2c117f58d946180d396e7bb39564def02d09cde27ebe60b107e2de6ab853a205fed52bc446029e2a56c8a0b4efd69758920ea39e1e5d407bdf8abae1f
6
+ metadata.gz: 0a3865e266d9d65a17194d486aa550ab378aa2a659e2419008fb3168e7928e125b1ea6d07e8edae311da6b252c10d1a35b794caf612abcb777aa5398b2d5876b
7
+ data.tar.gz: d1359a9ac3416fb4aa628d2cb2b923508911951ccd2eda52cd5821127c060b49ad6f8b168d2f204c15eebc0995fd3ae510945050dcac31a528343d1a8f599895
data/README.md CHANGED
@@ -6,7 +6,7 @@ And then when creating a new job we look in the "pending" jobs if there is anoth
6
6
 
7
7
  ## Note
8
8
 
9
- This gem is based based on the [synth](https://github.com/synth) work: https://gist.github.com/synth/fba7baeffd083a931184
9
+ This gem is based on the [synth](https://github.com/synth) work: https://gist.github.com/synth/fba7baeffd083a931184
10
10
 
11
11
  ## Installation
12
12
 
@@ -43,4 +43,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
43
43
 
44
44
  https://groups.google.com/g/delayed_job/c/gZ9bFCdZrsk#2a05c39a192e630c
45
45
  https://github.com/collectiveidea/delayed_job/blob/master/lib/delayed/backend/base.rb
46
- https://github.com/ignatiusreza/activejob-trackable
46
+ https://github.com/ignatiusreza/activejob-trackable
@@ -15,21 +15,54 @@ class DelayedDuplicatePreventionPlugin < Delayed::Plugin
15
15
  private
16
16
 
17
17
  def add_signature
18
- self.signature = generate_signature
19
- self.args = self.payload_object.args
18
+ # If signature fails, id will keep everything working (though deduplication will not work)
19
+ self.signature = generate_signature || generate_signature_random
20
+ self.args = get_args
20
21
  end
21
22
 
22
23
  def generate_signature
23
- pobj = payload_object
24
- if pobj.object.respond_to?(:id) and pobj.object.id.present?
25
- sig = "#{pobj.object.class}"
26
- sig += ":#{pobj.object.id}"
24
+ begin
25
+ if payload_object.is_a?(Delayed::PerformableMethod)
26
+ generate_signature_for_performable_method
27
+ else
28
+ generate_signature_random
29
+ end
30
+ rescue
31
+ generate_signature_failed
32
+ end
33
+ end
34
+
35
+ # Methods tagged with handle_asynchronously
36
+ def generate_signature_for_performable_method
37
+ if payload_object.object.respond_to?(:id) and payload_object.object.id.present?
38
+ sig = "#{payload_object.object.class}:#{payload_object.object.id}"
27
39
  else
28
- sig = "#{pobj.object}"
40
+ sig = "#{payload_object.object}"
29
41
  end
42
+ sig += "##{payload_object.method_name}"
43
+ sig
44
+ end
45
+
46
+ # # Regular Job
47
+ # def generate_signature_for_job_wrapper
48
+ # sig = "#{payload_object.job_data["job_class"]}"
49
+ # payload_object.job_data["arguments"].each do |job_arg|
50
+ # string_job_arg = job_arg.is_a?(String) ? job_arg : job_arg.to_json
51
+ # end
52
+ # sig += "#{payload_object.job_data["job_class"]}"
53
+ # sig
54
+ # end
55
+
56
+ def generate_signature_random
57
+ SecureRandom.uuid
58
+ end
59
+
60
+ def generate_signature_failed
61
+ puts "DelayedDuplicatePreventionPlugin could not generate the signature correctly."
62
+ end
30
63
 
31
- sig += "##{pobj.method_name}"
32
- return sig
64
+ def get_args
65
+ self.payload_object.respond_to?(:args) ? self.payload_object.args : []
33
66
  end
34
67
 
35
68
  def prevent_duplicate
@@ -61,11 +94,14 @@ class DelayedDuplicatePreventionPlugin < Delayed::Plugin
61
94
  possible_dupes = Delayed::Job.where(attempts: 0, locked_at: nil) # Only jobs not started, otherwise it would never compute a real change if the job is currently running
62
95
  .where(signature: job.signature) # Same signature
63
96
  possible_dupes = possible_dupes.where.not(id: job.id) if job.id.present?
97
+ byebug
64
98
  possible_dupes
65
99
  end
66
100
 
67
101
  def args_match?(job1, job2)
68
102
  job1.payload_object.args == job2.payload_object.args
103
+ rescue
104
+ false
69
105
  end
70
106
  end
71
107
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DelayedJobPreventDuplicate
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_job_prevent_duplicate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pabois
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
  date: 2023-09-08 00:00:00.000000000 Z
@@ -59,7 +59,7 @@ metadata:
59
59
  homepage_uri: https://github.com/noesya/delayed_job_prevent_duplicate
60
60
  source_code_uri: https://github.com/noesya/delayed_job_prevent_duplicate
61
61
  changelog_uri: https://github.com/noesya/delayed_job_prevent_duplicate/CHANGELOG.md
62
- post_install_message:
62
+ post_install_message:
63
63
  rdoc_options: []
64
64
  require_paths:
65
65
  - lib
@@ -74,8 +74,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  requirements: []
77
- rubygems_version: 3.1.4
78
- signing_key:
77
+ rubygems_version: 3.4.13
78
+ signing_key:
79
79
  specification_version: 4
80
80
  summary: Prevent delayed_job to enqueue a task already enqueued
81
81
  test_files: []