delayed_job_prevent_duplicate 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/delayed_duplicate_prevention_plugin.rb +44 -9
- data/lib/delayed_job_prevent_duplicate/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69b7a99d109637043b9b5fae631f1bc3c308784b65e069b8a047f747df21ac7a
|
4
|
+
data.tar.gz: a52a2c8e82930c06edd4af24d807c8d394bfc46e475ad0e101e16994d01d510b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
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
|
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
|
-
|
32
|
-
|
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
|
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.
|
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.
|
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: []
|