dalliance 0.8.1 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +4 -8
- data/config/locales/en.yml +2 -0
- data/dalliance.gemspec +4 -4
- data/gemfiles/rails_5.2.gemfile.lock +9 -6
- data/gemfiles/rails_6.0.gemfile.lock +9 -6
- data/gemfiles/{rails_5.0.gemfile → rails_6.1.gemfile} +1 -1
- data/gemfiles/rails_6.1.gemfile.lock +236 -0
- data/lib/dalliance/version.rb +2 -2
- data/lib/dalliance/workers/delayed_job.rb +32 -0
- data/lib/dalliance/workers/resque.rb +70 -0
- data/lib/dalliance.rb +102 -35
- data/spec/dalliance/asynchronous_delayed_job_spec.rb +8 -0
- data/spec/dalliance/asynchronous_resque_spec.rb +74 -0
- data/spec/dalliance/dalliance_spec.rb +12 -3
- data/spec/dalliance/synchronous_spec.rb +6 -4
- data/spec/spec_helper.rb +1 -1
- data/spec/support/active_record.rb +7 -0
- metadata +14 -14
- data/gemfiles/rails_5.0.gemfile.lock +0 -201
- data/gemfiles/rails_5.1.gemfile +0 -12
- data/gemfiles/rails_5.1.gemfile.lock +0 -201
- data/lib/dalliance/state_machine.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35460471fcbc38a777b1c2c1fc85fcaf125c43011cd43a619cde99c35b2344fe
|
4
|
+
data.tar.gz: 76e1ce25a3c16717b13b8c077706d66338c6cd5af2012e513fe0a16777f0d3b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aec679732b1385ef1ed52b2affbc098ea350cdf5cc348b454bbaddaa0161c1ba8589fd54924494082dedae324c5a9bc8783cb672c9df2de830aac7a9b2067d2c
|
7
|
+
data.tar.gz: 4ed750521ad5b32f0adbc69da26ef5c2e6a58871140e0f10a2e19d4d8cddd0c4562d91040ddeef2845e610734c110c7a17222bf10970869f3b7a6c7a91b12573
|
data/Appraisals
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
-
appraise "rails-5.0" do
|
2
|
-
gem "rails", "~> 5.0.0"
|
3
|
-
end
|
4
|
-
|
5
|
-
appraise "rails-5.1" do
|
6
|
-
gem "rails", "~> 5.1.0"
|
7
|
-
end
|
8
|
-
|
9
1
|
appraise "rails-5.2" do
|
10
2
|
gem "rails", "~> 5.2.2"
|
11
3
|
end
|
12
4
|
|
13
5
|
appraise "rails-6.0" do
|
14
6
|
gem "rails", "~> 6.0.0"
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise "rails-6.1" do
|
10
|
+
gem "rails", "~> 6.1.0"
|
15
11
|
end
|
data/config/locales/en.yml
CHANGED
data/dalliance.gemspec
CHANGED
@@ -5,8 +5,8 @@ require "dalliance/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "dalliance"
|
7
7
|
s.version = Dalliance::VERSION::STRING
|
8
|
-
s.authors = ["Eric Sullivan"]
|
9
|
-
s.email = ["eric.sullivan@annkissam.com"]
|
8
|
+
s.authors = ["Eric Sullivan", "Nick Clifford", "Sam Carlberg"]
|
9
|
+
s.email = ["eric.sullivan@annkissam.com", "nicholas.clifford@annkissam.com", "sam.carlberg@annkissam.com"]
|
10
10
|
s.homepage = "https://github.com/annkissam/dalliance"
|
11
11
|
s.summary = %q{ Wrapper for an ActiveRecord model with a single ascynhronous method }
|
12
12
|
s.description = %q{ Background processing for ActiveRecord using a 'delayable' worker and a state_machine }
|
@@ -16,9 +16,9 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
-
s.add_dependency('rails', '>= 5.
|
19
|
+
s.add_dependency('rails', '>= 5.2', "< 6.2")
|
20
20
|
|
21
|
-
s.add_dependency('
|
21
|
+
s.add_dependency('aasm')
|
22
22
|
|
23
23
|
s.add_development_dependency('rspec', '>= 3.0.0')
|
24
24
|
s.add_development_dependency('delayed_job', '>= 3.0.0')
|
@@ -1,13 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
dalliance (0.
|
5
|
-
|
6
|
-
|
4
|
+
dalliance (0.11.0)
|
5
|
+
aasm
|
6
|
+
rails (>= 5.2, < 6.2)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
+
aasm (5.2.0)
|
12
|
+
concurrent-ruby (~> 1.0)
|
11
13
|
actioncable (5.2.4.1)
|
12
14
|
actionpack (= 5.2.4.1)
|
13
15
|
nio4r (~> 2.0)
|
@@ -82,7 +84,9 @@ GEM
|
|
82
84
|
marcel (0.3.3)
|
83
85
|
mimemagic (~> 0.3.2)
|
84
86
|
method_source (0.9.2)
|
85
|
-
mimemagic (0.3.
|
87
|
+
mimemagic (0.3.10)
|
88
|
+
nokogiri (~> 1)
|
89
|
+
rake
|
86
90
|
mini_mime (1.0.2)
|
87
91
|
mini_portile2 (2.4.0)
|
88
92
|
minitest (5.14.0)
|
@@ -175,7 +179,6 @@ GEM
|
|
175
179
|
activesupport (>= 4.0)
|
176
180
|
sprockets (>= 3.0.0)
|
177
181
|
sqlite3 (1.4.2)
|
178
|
-
state_machine (1.2.0)
|
179
182
|
thor (0.20.3)
|
180
183
|
thread_safe (0.3.6)
|
181
184
|
tilt (2.0.10)
|
@@ -206,4 +209,4 @@ DEPENDENCIES
|
|
206
209
|
sqlite3
|
207
210
|
|
208
211
|
BUNDLED WITH
|
209
|
-
|
212
|
+
2.3.3
|
@@ -1,13 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
dalliance (0.
|
5
|
-
|
6
|
-
|
4
|
+
dalliance (0.11.0)
|
5
|
+
aasm
|
6
|
+
rails (>= 5.2, < 6.2)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
+
aasm (5.2.0)
|
12
|
+
concurrent-ruby (~> 1.0)
|
11
13
|
actioncable (6.0.2.1)
|
12
14
|
actionpack (= 6.0.2.1)
|
13
15
|
nio4r (~> 2.0)
|
@@ -95,7 +97,9 @@ GEM
|
|
95
97
|
marcel (0.3.3)
|
96
98
|
mimemagic (~> 0.3.2)
|
97
99
|
method_source (0.9.2)
|
98
|
-
mimemagic (0.3.
|
100
|
+
mimemagic (0.3.10)
|
101
|
+
nokogiri (~> 1)
|
102
|
+
rake
|
99
103
|
mini_mime (1.0.2)
|
100
104
|
mini_portile2 (2.4.0)
|
101
105
|
minitest (5.14.0)
|
@@ -190,7 +194,6 @@ GEM
|
|
190
194
|
activesupport (>= 4.0)
|
191
195
|
sprockets (>= 3.0.0)
|
192
196
|
sqlite3 (1.4.2)
|
193
|
-
state_machine (1.2.0)
|
194
197
|
thor (0.20.3)
|
195
198
|
thread_safe (0.3.6)
|
196
199
|
tilt (2.0.10)
|
@@ -222,4 +225,4 @@ DEPENDENCIES
|
|
222
225
|
sqlite3
|
223
226
|
|
224
227
|
BUNDLED WITH
|
225
|
-
|
228
|
+
2.3.3
|
@@ -0,0 +1,236 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
dalliance (0.11.0)
|
5
|
+
aasm
|
6
|
+
rails (>= 5.2, < 6.2)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
aasm (5.2.0)
|
12
|
+
concurrent-ruby (~> 1.0)
|
13
|
+
actioncable (6.1.2.1)
|
14
|
+
actionpack (= 6.1.2.1)
|
15
|
+
activesupport (= 6.1.2.1)
|
16
|
+
nio4r (~> 2.0)
|
17
|
+
websocket-driver (>= 0.6.1)
|
18
|
+
actionmailbox (6.1.2.1)
|
19
|
+
actionpack (= 6.1.2.1)
|
20
|
+
activejob (= 6.1.2.1)
|
21
|
+
activerecord (= 6.1.2.1)
|
22
|
+
activestorage (= 6.1.2.1)
|
23
|
+
activesupport (= 6.1.2.1)
|
24
|
+
mail (>= 2.7.1)
|
25
|
+
actionmailer (6.1.2.1)
|
26
|
+
actionpack (= 6.1.2.1)
|
27
|
+
actionview (= 6.1.2.1)
|
28
|
+
activejob (= 6.1.2.1)
|
29
|
+
activesupport (= 6.1.2.1)
|
30
|
+
mail (~> 2.5, >= 2.5.4)
|
31
|
+
rails-dom-testing (~> 2.0)
|
32
|
+
actionpack (6.1.2.1)
|
33
|
+
actionview (= 6.1.2.1)
|
34
|
+
activesupport (= 6.1.2.1)
|
35
|
+
rack (~> 2.0, >= 2.0.9)
|
36
|
+
rack-test (>= 0.6.3)
|
37
|
+
rails-dom-testing (~> 2.0)
|
38
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
39
|
+
actiontext (6.1.2.1)
|
40
|
+
actionpack (= 6.1.2.1)
|
41
|
+
activerecord (= 6.1.2.1)
|
42
|
+
activestorage (= 6.1.2.1)
|
43
|
+
activesupport (= 6.1.2.1)
|
44
|
+
nokogiri (>= 1.8.5)
|
45
|
+
actionview (6.1.2.1)
|
46
|
+
activesupport (= 6.1.2.1)
|
47
|
+
builder (~> 3.1)
|
48
|
+
erubi (~> 1.4)
|
49
|
+
rails-dom-testing (~> 2.0)
|
50
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
51
|
+
activejob (6.1.2.1)
|
52
|
+
activesupport (= 6.1.2.1)
|
53
|
+
globalid (>= 0.3.6)
|
54
|
+
activemodel (6.1.2.1)
|
55
|
+
activesupport (= 6.1.2.1)
|
56
|
+
activerecord (6.1.2.1)
|
57
|
+
activemodel (= 6.1.2.1)
|
58
|
+
activesupport (= 6.1.2.1)
|
59
|
+
activestorage (6.1.2.1)
|
60
|
+
actionpack (= 6.1.2.1)
|
61
|
+
activejob (= 6.1.2.1)
|
62
|
+
activerecord (= 6.1.2.1)
|
63
|
+
activesupport (= 6.1.2.1)
|
64
|
+
marcel (~> 0.3.1)
|
65
|
+
mimemagic (~> 0.3.2)
|
66
|
+
activesupport (6.1.2.1)
|
67
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
68
|
+
i18n (>= 1.6, < 2)
|
69
|
+
minitest (>= 5.1)
|
70
|
+
tzinfo (~> 2.0)
|
71
|
+
zeitwerk (~> 2.3)
|
72
|
+
appraisal (2.3.0)
|
73
|
+
bundler
|
74
|
+
rake
|
75
|
+
thor (>= 0.14.0)
|
76
|
+
ast (2.4.2)
|
77
|
+
builder (3.2.4)
|
78
|
+
bundler-audit (0.7.0.1)
|
79
|
+
bundler (>= 1.2.0, < 3)
|
80
|
+
thor (>= 0.18, < 2)
|
81
|
+
byebug (11.1.3)
|
82
|
+
concurrent-ruby (1.1.8)
|
83
|
+
crass (1.0.6)
|
84
|
+
delayed_job (4.1.9)
|
85
|
+
activesupport (>= 3.0, < 6.2)
|
86
|
+
delayed_job_active_record (4.1.5)
|
87
|
+
activerecord (>= 3.0, < 6.2)
|
88
|
+
delayed_job (>= 3.0, < 5)
|
89
|
+
diff-lcs (1.4.4)
|
90
|
+
erubi (1.10.0)
|
91
|
+
globalid (0.4.2)
|
92
|
+
activesupport (>= 4.2.0)
|
93
|
+
i18n (1.8.8)
|
94
|
+
concurrent-ruby (~> 1.0)
|
95
|
+
loofah (2.9.0)
|
96
|
+
crass (~> 1.0.2)
|
97
|
+
nokogiri (>= 1.5.9)
|
98
|
+
mail (2.7.1)
|
99
|
+
mini_mime (>= 0.1.1)
|
100
|
+
marcel (0.3.3)
|
101
|
+
mimemagic (~> 0.3.2)
|
102
|
+
method_source (1.0.0)
|
103
|
+
mimemagic (0.3.10)
|
104
|
+
nokogiri (~> 1)
|
105
|
+
rake
|
106
|
+
mini_mime (1.0.2)
|
107
|
+
mini_portile2 (2.5.0)
|
108
|
+
minitest (5.14.3)
|
109
|
+
mono_logger (1.1.0)
|
110
|
+
multi_json (1.15.0)
|
111
|
+
mustermann (1.1.1)
|
112
|
+
ruby2_keywords (~> 0.0.1)
|
113
|
+
nio4r (2.5.5)
|
114
|
+
nokogiri (1.11.1)
|
115
|
+
mini_portile2 (~> 2.5.0)
|
116
|
+
racc (~> 1.4)
|
117
|
+
parallel (1.20.1)
|
118
|
+
parser (3.0.0.0)
|
119
|
+
ast (~> 2.4.1)
|
120
|
+
racc (1.5.2)
|
121
|
+
rack (2.2.3)
|
122
|
+
rack-protection (2.1.0)
|
123
|
+
rack
|
124
|
+
rack-test (1.1.0)
|
125
|
+
rack (>= 1.0, < 3)
|
126
|
+
rails (6.1.2.1)
|
127
|
+
actioncable (= 6.1.2.1)
|
128
|
+
actionmailbox (= 6.1.2.1)
|
129
|
+
actionmailer (= 6.1.2.1)
|
130
|
+
actionpack (= 6.1.2.1)
|
131
|
+
actiontext (= 6.1.2.1)
|
132
|
+
actionview (= 6.1.2.1)
|
133
|
+
activejob (= 6.1.2.1)
|
134
|
+
activemodel (= 6.1.2.1)
|
135
|
+
activerecord (= 6.1.2.1)
|
136
|
+
activestorage (= 6.1.2.1)
|
137
|
+
activesupport (= 6.1.2.1)
|
138
|
+
bundler (>= 1.15.0)
|
139
|
+
railties (= 6.1.2.1)
|
140
|
+
sprockets-rails (>= 2.0.0)
|
141
|
+
rails-dom-testing (2.0.3)
|
142
|
+
activesupport (>= 4.2.0)
|
143
|
+
nokogiri (>= 1.6)
|
144
|
+
rails-html-sanitizer (1.3.0)
|
145
|
+
loofah (~> 2.3)
|
146
|
+
railties (6.1.2.1)
|
147
|
+
actionpack (= 6.1.2.1)
|
148
|
+
activesupport (= 6.1.2.1)
|
149
|
+
method_source
|
150
|
+
rake (>= 0.8.7)
|
151
|
+
thor (~> 1.0)
|
152
|
+
rainbow (3.0.0)
|
153
|
+
rake (13.0.3)
|
154
|
+
redis (4.2.5)
|
155
|
+
redis-namespace (1.8.1)
|
156
|
+
redis (>= 3.0.4)
|
157
|
+
regexp_parser (2.0.3)
|
158
|
+
resque (2.0.0)
|
159
|
+
mono_logger (~> 1.0)
|
160
|
+
multi_json (~> 1.0)
|
161
|
+
redis-namespace (~> 1.6)
|
162
|
+
sinatra (>= 0.9.2)
|
163
|
+
vegas (~> 0.1.2)
|
164
|
+
rexml (3.2.4)
|
165
|
+
rspec (3.10.0)
|
166
|
+
rspec-core (~> 3.10.0)
|
167
|
+
rspec-expectations (~> 3.10.0)
|
168
|
+
rspec-mocks (~> 3.10.0)
|
169
|
+
rspec-core (3.10.1)
|
170
|
+
rspec-support (~> 3.10.0)
|
171
|
+
rspec-expectations (3.10.1)
|
172
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
173
|
+
rspec-support (~> 3.10.0)
|
174
|
+
rspec-mocks (3.10.2)
|
175
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
176
|
+
rspec-support (~> 3.10.0)
|
177
|
+
rspec-support (3.10.2)
|
178
|
+
rspec_junit_formatter (0.4.1)
|
179
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
180
|
+
rubocop (0.93.1)
|
181
|
+
parallel (~> 1.10)
|
182
|
+
parser (>= 2.7.1.5)
|
183
|
+
rainbow (>= 2.2.2, < 4.0)
|
184
|
+
regexp_parser (>= 1.8)
|
185
|
+
rexml
|
186
|
+
rubocop-ast (>= 0.6.0)
|
187
|
+
ruby-progressbar (~> 1.7)
|
188
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
189
|
+
rubocop-ast (1.4.1)
|
190
|
+
parser (>= 2.7.1.5)
|
191
|
+
ruby-progressbar (1.11.0)
|
192
|
+
ruby2_keywords (0.0.4)
|
193
|
+
sinatra (2.1.0)
|
194
|
+
mustermann (~> 1.0)
|
195
|
+
rack (~> 2.2)
|
196
|
+
rack-protection (= 2.1.0)
|
197
|
+
tilt (~> 2.0)
|
198
|
+
sprockets (4.0.2)
|
199
|
+
concurrent-ruby (~> 1.0)
|
200
|
+
rack (> 1, < 3)
|
201
|
+
sprockets-rails (3.2.2)
|
202
|
+
actionpack (>= 4.0)
|
203
|
+
activesupport (>= 4.0)
|
204
|
+
sprockets (>= 3.0.0)
|
205
|
+
sqlite3 (1.4.2)
|
206
|
+
thor (1.1.0)
|
207
|
+
tilt (2.0.10)
|
208
|
+
tzinfo (2.0.4)
|
209
|
+
concurrent-ruby (~> 1.0)
|
210
|
+
unicode-display_width (1.7.0)
|
211
|
+
vegas (0.1.11)
|
212
|
+
rack (>= 1.0.0)
|
213
|
+
websocket-driver (0.7.3)
|
214
|
+
websocket-extensions (>= 0.1.0)
|
215
|
+
websocket-extensions (0.1.5)
|
216
|
+
zeitwerk (2.4.2)
|
217
|
+
|
218
|
+
PLATFORMS
|
219
|
+
ruby
|
220
|
+
|
221
|
+
DEPENDENCIES
|
222
|
+
appraisal
|
223
|
+
bundler-audit
|
224
|
+
byebug
|
225
|
+
dalliance!
|
226
|
+
delayed_job (>= 3.0.0)
|
227
|
+
delayed_job_active_record
|
228
|
+
rails (~> 6.1.0)
|
229
|
+
resque
|
230
|
+
rspec (>= 3.0.0)
|
231
|
+
rspec_junit_formatter
|
232
|
+
rubocop (~> 0.78)
|
233
|
+
sqlite3
|
234
|
+
|
235
|
+
BUNDLED WITH
|
236
|
+
2.3.3
|
data/lib/dalliance/version.rb
CHANGED
@@ -10,6 +10,22 @@ module Dalliance
|
|
10
10
|
.perform_later(instance.class.name, instance.id, perform_method.to_s)
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.dequeue(_instance)
|
14
|
+
# NOP
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.queued?(instance, queue)
|
18
|
+
queued_jobs =
|
19
|
+
Delayed::Job.where(queue: queue)
|
20
|
+
.pluck(:handler)
|
21
|
+
.map(&YAML.method(:load))
|
22
|
+
|
23
|
+
queued_jobs.any? do |job_wrapper|
|
24
|
+
job_wrapper.job_data['arguments'].first(2) ==
|
25
|
+
[instance.class.name, instance.id]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
13
29
|
def perform(instance_klass, instance_id, perform_method)
|
14
30
|
instance_klass
|
15
31
|
.constantize
|
@@ -31,6 +47,22 @@ module Dalliance
|
|
31
47
|
)
|
32
48
|
end
|
33
49
|
|
50
|
+
def self.dequeue(_instance)
|
51
|
+
# NOP
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.queued?(instance, queue)
|
55
|
+
queued_jobs =
|
56
|
+
Delayed::Job.where(queue: queue)
|
57
|
+
.pluck(:handler)
|
58
|
+
.map(&YAML.method(:load))
|
59
|
+
|
60
|
+
queued_jobs.any? do |job_wrapper|
|
61
|
+
job_wrapper.job_data['arguments'].first(2) ==
|
62
|
+
[instance.class.name, instance.id]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
34
66
|
def perform
|
35
67
|
instance_klass
|
36
68
|
.constantize
|
@@ -10,6 +10,41 @@ module Dalliance
|
|
10
10
|
.perform_later(instance.class.name, instance.id, perform_method.to_s)
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.dequeue(instance)
|
14
|
+
redis = ::Resque.redis
|
15
|
+
queue = instance.processing_queue
|
16
|
+
|
17
|
+
redis.everything_in_queue(queue).each do |string|
|
18
|
+
# Structure looks like, e.g.
|
19
|
+
# { 'class' => 'ActiveJob::...', 'args' => [{ 'arguments' => ['SomeClass', 123, 'dalliance_process'] }] }
|
20
|
+
data = ::Resque.decode(string)
|
21
|
+
dalliance_args = data['args'][0]['arguments']
|
22
|
+
|
23
|
+
if dalliance_args == [instance.class.name, instance.id, 'dalliance_process'] ||
|
24
|
+
dalliance_args == [instance.class.name, instance.id, 'dalliance_reprocess']
|
25
|
+
redis.remove_from_queue(queue, string)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.queued?(instance, queue_name)
|
31
|
+
# All current jobs in the queue
|
32
|
+
queued_jobs =
|
33
|
+
::Resque.redis.everything_in_queue(queue_name)
|
34
|
+
.map(&::Resque.method(:decode))
|
35
|
+
|
36
|
+
queued_jobs.any? do |job_info_hash|
|
37
|
+
args = job_info_hash['args']
|
38
|
+
next unless args.is_a?(Array)
|
39
|
+
|
40
|
+
arg = args[0]
|
41
|
+
next unless arg.is_a?(Hash)
|
42
|
+
|
43
|
+
arg.fetch('arguments', []).first(2) ==
|
44
|
+
[instance.class.name, instance.id]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
13
48
|
def perform(instance_klass, instance_id, perform_method)
|
14
49
|
instance_klass
|
15
50
|
.constantize
|
@@ -28,6 +63,41 @@ module Dalliance
|
|
28
63
|
::Resque.enqueue_to(queue, self, instance.class.name, instance.id, perform_method.to_s)
|
29
64
|
end
|
30
65
|
|
66
|
+
def self.dequeue(instance)
|
67
|
+
redis = ::Resque.redis
|
68
|
+
queue = instance.processing_queue
|
69
|
+
|
70
|
+
redis.everything_in_queue(queue).each do |string|
|
71
|
+
# Structure looks like, e.g.
|
72
|
+
# { 'class' => 'ActiveJob::...', 'args' => [{ 'arguments' => ['SomeClass', 123, 'dalliance_process'] }] }
|
73
|
+
data = ::Resque.decode(string)
|
74
|
+
dalliance_args = data['args'][0]['arguments']
|
75
|
+
|
76
|
+
if dalliance_args == [instance.class.name, instance.id, 'dalliance_process'] ||
|
77
|
+
dalliance_args == [instance.class.name, instance.id, 'dalliance_reprocess']
|
78
|
+
redis.remove_from_queue(queue, string)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.queued?(instance, queue_name)
|
84
|
+
# All current jobs in the queue
|
85
|
+
queued_jobs =
|
86
|
+
::Resque.redis.everything_in_queue(queue_name)
|
87
|
+
.map(&::Resque.method(:decode))
|
88
|
+
|
89
|
+
queued_jobs.any? do |job_info_hash|
|
90
|
+
args = job_info_hash['args']
|
91
|
+
next unless args.is_a?(Array)
|
92
|
+
|
93
|
+
arg = args[0]
|
94
|
+
next unless arg.is_a?(Hash)
|
95
|
+
|
96
|
+
arg.fetch('arguments', []).first(2) ==
|
97
|
+
[instance.class.name, instance.id]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
31
101
|
def self.perform(instance_klass, instance_id, perform_method)
|
32
102
|
instance_klass
|
33
103
|
.constantize
|