delayed_job_prevent_duplicate 0.1.1 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9dddeb211dc3682bcf52ea61c6fbae09b2f53b464dfc77be09d41e802c81451
4
- data.tar.gz: 9235b96c6047126767f6412ad1bf0e216f2f3172e244caecdf22880256a852c6
3
+ metadata.gz: 69b7a99d109637043b9b5fae631f1bc3c308784b65e069b8a047f747df21ac7a
4
+ data.tar.gz: a52a2c8e82930c06edd4af24d807c8d394bfc46e475ad0e101e16994d01d510b
5
5
  SHA512:
6
- metadata.gz: fe9167455f11e23771989414b78731394123d339884bf607acef3d11ab32e4b46f1cdd5e62b7fbac8e3e3443e6f31b8dcbf7f63a9f1c162544856d37f97282b9
7
- data.tar.gz: f35d3fa2c117f58d946180d396e7bb39564def02d09cde27ebe60b107e2de6ab853a205fed52bc446029e2a56c8a0b4efd69758920ea39e1e5d407bdf8abae1f
6
+ metadata.gz: a9cd69b947323438067b1efb1124cf33987e31da085a637b0a3e2229d69c94ac5b4a821eef5ed57b17bb4adbad97295aeb399038b9ffc41b3f7ea417691ab1a2
7
+ data.tar.gz: e3a1ceb195982d9cb0796a0d7b7b2fa68eac6dd775e1ae209c616807fd71eb47186bf5e19324141f0874e064e269f95c28a5f5dc8c7cace99290892a63fcda41
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
@@ -66,6 +99,8 @@ class DelayedDuplicatePreventionPlugin < Delayed::Plugin
66
99
 
67
100
  def args_match?(job1, job2)
68
101
  job1.payload_object.args == job2.payload_object.args
102
+ rescue
103
+ false
69
104
  end
70
105
  end
71
106
  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.3"
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.3
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: []