dalliance 0.5.0 → 0.8.1

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.
@@ -1,9 +1,9 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "http://rubygems.org"
3
+ source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
- gem "rails", "~> 4.0.0"
6
+ gem "rails", "~> 6.0.0"
7
7
 
8
8
  group :development, :test do
9
9
  gem "byebug"
@@ -0,0 +1,225 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ dalliance (0.7.0)
5
+ rails (>= 5.0, < 6.1)
6
+ state_machine
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (6.0.2.1)
12
+ actionpack (= 6.0.2.1)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ actionmailbox (6.0.2.1)
16
+ actionpack (= 6.0.2.1)
17
+ activejob (= 6.0.2.1)
18
+ activerecord (= 6.0.2.1)
19
+ activestorage (= 6.0.2.1)
20
+ activesupport (= 6.0.2.1)
21
+ mail (>= 2.7.1)
22
+ actionmailer (6.0.2.1)
23
+ actionpack (= 6.0.2.1)
24
+ actionview (= 6.0.2.1)
25
+ activejob (= 6.0.2.1)
26
+ mail (~> 2.5, >= 2.5.4)
27
+ rails-dom-testing (~> 2.0)
28
+ actionpack (6.0.2.1)
29
+ actionview (= 6.0.2.1)
30
+ activesupport (= 6.0.2.1)
31
+ rack (~> 2.0, >= 2.0.8)
32
+ rack-test (>= 0.6.3)
33
+ rails-dom-testing (~> 2.0)
34
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
35
+ actiontext (6.0.2.1)
36
+ actionpack (= 6.0.2.1)
37
+ activerecord (= 6.0.2.1)
38
+ activestorage (= 6.0.2.1)
39
+ activesupport (= 6.0.2.1)
40
+ nokogiri (>= 1.8.5)
41
+ actionview (6.0.2.1)
42
+ activesupport (= 6.0.2.1)
43
+ builder (~> 3.1)
44
+ erubi (~> 1.4)
45
+ rails-dom-testing (~> 2.0)
46
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
47
+ activejob (6.0.2.1)
48
+ activesupport (= 6.0.2.1)
49
+ globalid (>= 0.3.6)
50
+ activemodel (6.0.2.1)
51
+ activesupport (= 6.0.2.1)
52
+ activerecord (6.0.2.1)
53
+ activemodel (= 6.0.2.1)
54
+ activesupport (= 6.0.2.1)
55
+ activestorage (6.0.2.1)
56
+ actionpack (= 6.0.2.1)
57
+ activejob (= 6.0.2.1)
58
+ activerecord (= 6.0.2.1)
59
+ marcel (~> 0.3.1)
60
+ activesupport (6.0.2.1)
61
+ concurrent-ruby (~> 1.0, >= 1.0.2)
62
+ i18n (>= 0.7, < 2)
63
+ minitest (~> 5.1)
64
+ tzinfo (~> 1.1)
65
+ zeitwerk (~> 2.2)
66
+ appraisal (2.2.0)
67
+ bundler
68
+ rake
69
+ thor (>= 0.14.0)
70
+ ast (2.4.0)
71
+ builder (3.2.4)
72
+ bundler-audit (0.6.1)
73
+ bundler (>= 1.2.0, < 3)
74
+ thor (~> 0.18)
75
+ byebug (11.1.1)
76
+ concurrent-ruby (1.1.6)
77
+ crass (1.0.6)
78
+ delayed_job (4.1.8)
79
+ activesupport (>= 3.0, < 6.1)
80
+ delayed_job_active_record (4.1.4)
81
+ activerecord (>= 3.0, < 6.1)
82
+ delayed_job (>= 3.0, < 5)
83
+ diff-lcs (1.3)
84
+ erubi (1.9.0)
85
+ globalid (0.4.2)
86
+ activesupport (>= 4.2.0)
87
+ i18n (1.8.2)
88
+ concurrent-ruby (~> 1.0)
89
+ jaro_winkler (1.5.4)
90
+ loofah (2.4.0)
91
+ crass (~> 1.0.2)
92
+ nokogiri (>= 1.5.9)
93
+ mail (2.7.1)
94
+ mini_mime (>= 0.1.1)
95
+ marcel (0.3.3)
96
+ mimemagic (~> 0.3.2)
97
+ method_source (0.9.2)
98
+ mimemagic (0.3.4)
99
+ mini_mime (1.0.2)
100
+ mini_portile2 (2.4.0)
101
+ minitest (5.14.0)
102
+ mono_logger (1.1.0)
103
+ multi_json (1.14.1)
104
+ mustermann (1.1.1)
105
+ ruby2_keywords (~> 0.0.1)
106
+ nio4r (2.5.2)
107
+ nokogiri (1.10.8)
108
+ mini_portile2 (~> 2.4.0)
109
+ parallel (1.19.1)
110
+ parser (2.7.0.3)
111
+ ast (~> 2.4.0)
112
+ rack (2.2.2)
113
+ rack-protection (2.0.8.1)
114
+ rack
115
+ rack-test (1.1.0)
116
+ rack (>= 1.0, < 3)
117
+ rails (6.0.2.1)
118
+ actioncable (= 6.0.2.1)
119
+ actionmailbox (= 6.0.2.1)
120
+ actionmailer (= 6.0.2.1)
121
+ actionpack (= 6.0.2.1)
122
+ actiontext (= 6.0.2.1)
123
+ actionview (= 6.0.2.1)
124
+ activejob (= 6.0.2.1)
125
+ activemodel (= 6.0.2.1)
126
+ activerecord (= 6.0.2.1)
127
+ activestorage (= 6.0.2.1)
128
+ activesupport (= 6.0.2.1)
129
+ bundler (>= 1.3.0)
130
+ railties (= 6.0.2.1)
131
+ sprockets-rails (>= 2.0.0)
132
+ rails-dom-testing (2.0.3)
133
+ activesupport (>= 4.2.0)
134
+ nokogiri (>= 1.6)
135
+ rails-html-sanitizer (1.3.0)
136
+ loofah (~> 2.3)
137
+ railties (6.0.2.1)
138
+ actionpack (= 6.0.2.1)
139
+ activesupport (= 6.0.2.1)
140
+ method_source
141
+ rake (>= 0.8.7)
142
+ thor (>= 0.20.3, < 2.0)
143
+ rainbow (3.0.0)
144
+ rake (13.0.1)
145
+ redis (4.1.3)
146
+ redis-namespace (1.7.0)
147
+ redis (>= 3.0.4)
148
+ resque (2.0.0)
149
+ mono_logger (~> 1.0)
150
+ multi_json (~> 1.0)
151
+ redis-namespace (~> 1.6)
152
+ sinatra (>= 0.9.2)
153
+ vegas (~> 0.1.2)
154
+ rexml (3.2.4)
155
+ rspec (3.9.0)
156
+ rspec-core (~> 3.9.0)
157
+ rspec-expectations (~> 3.9.0)
158
+ rspec-mocks (~> 3.9.0)
159
+ rspec-core (3.9.1)
160
+ rspec-support (~> 3.9.1)
161
+ rspec-expectations (3.9.0)
162
+ diff-lcs (>= 1.2.0, < 2.0)
163
+ rspec-support (~> 3.9.0)
164
+ rspec-mocks (3.9.1)
165
+ diff-lcs (>= 1.2.0, < 2.0)
166
+ rspec-support (~> 3.9.0)
167
+ rspec-support (3.9.2)
168
+ rspec_junit_formatter (0.4.1)
169
+ rspec-core (>= 2, < 4, != 2.12.0)
170
+ rubocop (0.80.0)
171
+ jaro_winkler (~> 1.5.1)
172
+ parallel (~> 1.10)
173
+ parser (>= 2.7.0.1)
174
+ rainbow (>= 2.2.2, < 4.0)
175
+ rexml
176
+ ruby-progressbar (~> 1.7)
177
+ unicode-display_width (>= 1.4.0, < 1.7)
178
+ ruby-progressbar (1.10.1)
179
+ ruby2_keywords (0.0.2)
180
+ sinatra (2.0.8.1)
181
+ mustermann (~> 1.0)
182
+ rack (~> 2.0)
183
+ rack-protection (= 2.0.8.1)
184
+ tilt (~> 2.0)
185
+ sprockets (4.0.0)
186
+ concurrent-ruby (~> 1.0)
187
+ rack (> 1, < 3)
188
+ sprockets-rails (3.2.1)
189
+ actionpack (>= 4.0)
190
+ activesupport (>= 4.0)
191
+ sprockets (>= 3.0.0)
192
+ sqlite3 (1.4.2)
193
+ state_machine (1.2.0)
194
+ thor (0.20.3)
195
+ thread_safe (0.3.6)
196
+ tilt (2.0.10)
197
+ tzinfo (1.2.6)
198
+ thread_safe (~> 0.1)
199
+ unicode-display_width (1.6.1)
200
+ vegas (0.1.11)
201
+ rack (>= 1.0.0)
202
+ websocket-driver (0.7.1)
203
+ websocket-extensions (>= 0.1.0)
204
+ websocket-extensions (0.1.4)
205
+ zeitwerk (2.2.2)
206
+
207
+ PLATFORMS
208
+ ruby
209
+
210
+ DEPENDENCIES
211
+ appraisal
212
+ bundler-audit
213
+ byebug
214
+ dalliance!
215
+ delayed_job (>= 3.0.0)
216
+ delayed_job_active_record
217
+ rails (~> 6.0.0)
218
+ resque
219
+ rspec (>= 3.0.0)
220
+ rspec_junit_formatter
221
+ rubocop (~> 0.78)
222
+ sqlite3
223
+
224
+ BUNDLED WITH
225
+ 1.17.3
@@ -118,6 +118,10 @@ module Dalliance
118
118
  event :finish_dalliance do
119
119
  transition :processing => :completed
120
120
  end
121
+
122
+ event :reprocess_dalliance do
123
+ transition [:validation_error, :processing_error, :completed] => :pending
124
+ end
121
125
  end
122
126
  #END state_machine(s)
123
127
 
@@ -175,7 +179,9 @@ module Dalliance
175
179
  else
176
180
  self.class.where(id: self.id).update_all(dalliance_status: dalliance_status, dalliance_error_hash: dalliance_error_hash.to_yaml )
177
181
  end
182
+ # rubocop:disable Lint/SuppressedException
178
183
  rescue
184
+ # rubocop:enable Lint/SuppressedException
179
185
  end
180
186
  end
181
187
  end
@@ -191,7 +197,7 @@ module Dalliance
191
197
  def validate_dalliance_status
192
198
  unless error_or_completed?
193
199
  errors.add(:dalliance_status, :invalid)
194
- if defined?(Rails) && ::Rails::VERSION::MAJOR == 5 && ::Rails::VERSION::MINOR >= 0
200
+ if defined?(Rails)
195
201
  throw(:abort)
196
202
  else
197
203
  return false
@@ -213,17 +219,41 @@ module Dalliance
213
219
  end
214
220
  end
215
221
 
216
- #Force backgound_processing w/ true
217
- def dalliance_background_process(backgound_processing = nil)
218
- if backgound_processing || (backgound_processing.nil? && self.class.dalliance_options[:background_processing])
219
- self.class.dalliance_options[:worker_class].enqueue(self, processing_queue)
222
+ #Force background_processing w/ true
223
+ def dalliance_background_process(background_processing = nil)
224
+ if background_processing || (background_processing.nil? && self.class.dalliance_options[:background_processing])
225
+ self.class.dalliance_options[:worker_class].enqueue(self, processing_queue, :dalliance_process)
220
226
  else
221
227
  dalliance_process(false)
222
228
  end
223
229
  end
224
230
 
225
- #backgound_processing == false will re-raise any exceptions
226
- def dalliance_process(backgound_processing = false)
231
+ def dalliance_process(background_processing = false)
232
+ do_dalliance_process(
233
+ perform_method: self.class.dalliance_options[:dalliance_method],
234
+ background_processing: background_processing
235
+ )
236
+ end
237
+
238
+ def dalliance_background_reprocess(background_processing = nil)
239
+ # Reset state to 'pending' before queueing up
240
+ # Otherwise the model will stay on completed/processing_error until the job
241
+ # is taken by a worker, which could be a long time after this method is
242
+ # called.
243
+ reprocess_dalliance!
244
+ if background_processing || (background_processing.nil? && self.class.dalliance_options[:background_processing])
245
+ self.class.dalliance_options[:worker_class].enqueue(self, processing_queue, :do_dalliance_reprocess)
246
+ else
247
+ do_dalliance_reprocess(false)
248
+ end
249
+ end
250
+
251
+ def dalliance_reprocess(background_processing = false)
252
+ reprocess_dalliance!
253
+ do_dalliance_reprocess(background_processing)
254
+ end
255
+
256
+ def do_dalliance_process(perform_method:, background_processing: false)
227
257
  start_time = Time.now
228
258
 
229
259
  begin
@@ -233,7 +263,7 @@ module Dalliance
233
263
  build_dalliance_progress_meter(:total_count => calculate_dalliance_progress_meter_total_count).save!
234
264
  end
235
265
 
236
- self.send(self.class.dalliance_options[:dalliance_method])
266
+ self.send(perform_method)
237
267
 
238
268
  finish_dalliance! unless validation_error?
239
269
  rescue StandardError => e
@@ -255,14 +285,16 @@ module Dalliance
255
285
  else
256
286
  self.class.where(id: self.id).update_all(dalliance_status: dalliance_status, dalliance_error_hash: dalliance_error_hash.to_yaml )
257
287
  end
288
+ # rubocop:disable Lint/SuppressedException
258
289
  rescue
290
+ # rubocop:enable Lint/SuppressedException
259
291
  end
260
292
  end
261
293
 
262
294
  error_notifier.call(e)
263
295
 
264
- #Don't raise the error if we're backgound_processing...
265
- raise e unless backgound_processing && self.class.dalliance_options[:worker_class].rescue_error?
296
+ # Don't raise the error if we're background processing...
297
+ raise e unless background_processing && self.class.dalliance_options[:worker_class].rescue_error?
266
298
  ensure
267
299
  if self.class.dalliance_options[:dalliance_progress_meter] && dalliance_progress_meter
268
300
  #Works with optimistic locking...
@@ -274,8 +306,11 @@ module Dalliance
274
306
 
275
307
  dalliance_log("[dalliance] #{self.class.name}(#{id}) - #{dalliance_status} #{duration.to_i}")
276
308
 
277
- if self.class.dalliance_options[:duration_column]
278
- self.class.where(id: self.id).update_all(self.class.dalliance_options[:duration_column] => duration.to_i)
309
+ duration_column = self.class.dalliance_options[:duration_column]
310
+ if duration_column.present?
311
+ current_duration = self.send(duration_column) || 0
312
+ self.class.where(id: self.id)
313
+ .update_all(duration_column => current_duration + duration.to_f)
279
314
  end
280
315
  end
281
316
  end
@@ -305,6 +340,19 @@ module Dalliance
305
340
  end
306
341
  end
307
342
 
343
+ private
344
+
345
+ # Executes the reprocessing method defined in the model's dalliance options.
346
+ #
347
+ # @param [Boolean] background_processing
348
+ # flag if this is called from a background worker. Defaults to false.
349
+ def do_dalliance_reprocess(background_processing = false)
350
+ do_dalliance_process(
351
+ perform_method: self.class.dalliance_options[:reprocess_method],
352
+ background_processing: background_processing
353
+ )
354
+ end
355
+
308
356
  module Glue
309
357
  extend ActiveSupport::Concern
310
358
 
@@ -313,15 +361,28 @@ module Dalliance
313
361
  end
314
362
 
315
363
  module ClassMethods
316
- def dalliance(*args)
317
- options = args.last.is_a?(Hash) ? Dalliance.options.merge(args.pop) : Dalliance.options
318
-
319
- case args.length
320
- when 1
321
- options[:dalliance_method] = args[0]
322
- else
323
- raise ArgumentError, "Incorrect number of Arguements provided"
324
- end
364
+ # Enables dalliance processing for this class.
365
+ #
366
+ # @param [Symbol|String] dalliance_method
367
+ # the name of the method to call when processing the model in dalliance
368
+ # @param [Hash] options
369
+ # an optional hash of options for dalliance processing
370
+ # @option options [Symbol] :reprocess_method
371
+ # the name of the method to use to reprocess the model in dalliance
372
+ # @option options [Boolean] :dalliance_process_meter
373
+ # whether or not to display a progress meter
374
+ # @option options [String] :queue
375
+ # the name of the worker queue to use. Default 'dalliance'
376
+ # @option options [String] :duration_column
377
+ # the name of the table column that stores the dalliance processing time. Default 'dalliance_duration'
378
+ # @option options [Object] :logger
379
+ # the logger object to use. Can be nil
380
+ # @option options [Proc] :error_notifier
381
+ # A proc that accepts an error object. Default is a NOP
382
+ def dalliance(dalliance_method, options = {})
383
+ opts = Dalliance.options.merge(options)
384
+
385
+ opts[:dalliance_method] = dalliance_method
325
386
 
326
387
  if dalliance_options.nil?
327
388
  self.dalliance_options = {}
@@ -329,7 +390,7 @@ module Dalliance
329
390
  self.dalliance_options = self.dalliance_options.dup
330
391
  end
331
392
 
332
- self.dalliance_options.merge!(options)
393
+ self.dalliance_options.merge!(opts)
333
394
 
334
395
  include Dalliance
335
396
  end
@@ -7,7 +7,7 @@ module Dalliance
7
7
  ActiveSupport.on_load :active_record do
8
8
  include Dalliance::Glue
9
9
 
10
- ActiveRecord::ConnectionAdapters::TableDefinition.send(:include, Dalliance::Schema)
10
+ ActiveRecord::ConnectionAdapters::TableDefinition.include Dalliance::Schema
11
11
  end
12
12
  end
13
13
  end
@@ -46,20 +46,20 @@ module Dalliance
46
46
  #TODO: This is just a stopgap until I fix increment! to be thread-safe
47
47
  def progress
48
48
  begin
49
- _progress = (current_count.to_f / total_count.to_f * 100).to_i
49
+ current_progress = (current_count.to_f / total_count.to_f * 100).to_i
50
50
 
51
51
  #Handle an incorrect total_count...
52
- _progress = 100 if _progress > 100
52
+ current_progress = 100 if current_progress > 100
53
53
  rescue
54
54
  #what, are you diving by zero?
55
- _progress = 0
55
+ current_progress = 0
56
56
  end
57
57
 
58
- _progress
58
+ current_progress
59
59
  end
60
60
 
61
61
  def increment!
62
62
  Dalliance::ProgressMeter.increment_counter(:current_count, self.id)
63
63
  end
64
64
  end
65
- end
65
+ end