delayed_job_prevent_duplicate 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +0 -2
- data/README.md +2 -2
- data/lib/delayed_duplicate_prevention_plugin.rb +48 -17
- data/lib/delayed_job_prevent_duplicate/version.rb +1 -1
- metadata +6 -7
- data/.DS_Store +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8668bbcfafe20c2670059fcb0ff0a53d6d75ce1987fd0ce5246bed70660b8ef
|
4
|
+
data.tar.gz: 39369122bb75be1eaa05f6a21ac4ecc557be61c39cdf03d86c7b1b10dc1f925c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a3865e266d9d65a17194d486aa550ab378aa2a659e2419008fb3168e7928e125b1ea6d07e8edae311da6b252c10d1a35b794caf612abcb777aa5398b2d5876b
|
7
|
+
data.tar.gz: d1359a9ac3416fb4aa628d2cb2b923508911951ccd2eda52cd5821127c060b49ad6f8b168d2f204c15eebc0995fd3ae510945050dcac31a528343d1a8f599895
|
data/CHANGELOG.md
CHANGED
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
|
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,27 +15,60 @@ class DelayedDuplicatePreventionPlugin < Delayed::Plugin
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def add_signature
|
18
|
-
|
19
|
-
self.
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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 = "#{
|
40
|
+
sig = "#{payload_object.object}"
|
29
41
|
end
|
42
|
+
sig += "##{payload_object.method_name}"
|
43
|
+
sig
|
44
|
+
end
|
30
45
|
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
63
|
+
|
64
|
+
def get_args
|
65
|
+
self.payload_object.respond_to?(:args) ? self.payload_object.args : []
|
66
|
+
end
|
34
67
|
|
35
68
|
def prevent_duplicate
|
36
69
|
if DuplicateChecker.duplicate?(self)
|
37
70
|
Rails.logger.warn "Found duplicate job(#{self.signature}), ignoring..."
|
38
|
-
errors.add(:base, "This is a duplicate")
|
71
|
+
errors.add(:base, "This is a duplicate")
|
39
72
|
end
|
40
73
|
end
|
41
74
|
end
|
@@ -61,16 +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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
def normalize_args(args)
|
73
|
-
args.kind_of?(String) ? YAML.load(args) : args
|
102
|
+
job1.payload_object.args == job2.payload_object.args
|
103
|
+
rescue
|
104
|
+
false
|
74
105
|
end
|
75
106
|
end
|
76
107
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delayed_job_prevent_duplicate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.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
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: delayed_job
|
@@ -38,7 +38,6 @@ executables: []
|
|
38
38
|
extensions: []
|
39
39
|
extra_rdoc_files: []
|
40
40
|
files:
|
41
|
-
- ".DS_Store"
|
42
41
|
- CHANGELOG.md
|
43
42
|
- Gemfile
|
44
43
|
- LICENSE.txt
|
@@ -60,7 +59,7 @@ metadata:
|
|
60
59
|
homepage_uri: https://github.com/noesya/delayed_job_prevent_duplicate
|
61
60
|
source_code_uri: https://github.com/noesya/delayed_job_prevent_duplicate
|
62
61
|
changelog_uri: https://github.com/noesya/delayed_job_prevent_duplicate/CHANGELOG.md
|
63
|
-
post_install_message:
|
62
|
+
post_install_message:
|
64
63
|
rdoc_options: []
|
65
64
|
require_paths:
|
66
65
|
- lib
|
@@ -75,8 +74,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
74
|
- !ruby/object:Gem::Version
|
76
75
|
version: '0'
|
77
76
|
requirements: []
|
78
|
-
rubygems_version: 3.
|
79
|
-
signing_key:
|
77
|
+
rubygems_version: 3.4.13
|
78
|
+
signing_key:
|
80
79
|
specification_version: 4
|
81
80
|
summary: Prevent delayed_job to enqueue a task already enqueued
|
82
81
|
test_files: []
|
data/.DS_Store
DELETED
Binary file
|