batch_processor 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa414c8ed1a57723e070fa4e497f204f3e35ca710072053fe81c2e6911fe3a06
4
- data.tar.gz: fab54cef458cfe173082f2d86223bb7ce42471639658a500abe69c5fc9579278
3
+ metadata.gz: f4a9d68e36cd3f56abfaadd71b82a4740c38bb3aed87d97b0ba6f9e651944039
4
+ data.tar.gz: 4a9b585d163ee2bd7f3166658388a6de879ce788d31cb5f7de37cdeba6359f2c
5
5
  SHA512:
6
- metadata.gz: c0f97d5f687336adf312cd3232c731e7557dcc004a0990ab2862abfa13ce6c786951d5359b8b1bd918a1e2c39a46c0ff60311fc1ad1278ed52703699caaffaa8
7
- data.tar.gz: 297022cb0bb636267316576598d362b45d9dd3cf42c948e3912e070c86d15fee71e5378f600405c86969d8fdc4a07c55563ae194efaf946b93448d72e6d49d5f
6
+ metadata.gz: c97251745907fbe425b802b478a996dfefd2f7caaadbb31ef7299727c748ad19116f3cb8e69299df9ca9ec073334dc2eb751d6c7ec3a0895f81063fe3b13f62b
7
+ data.tar.gz: 3aba5c37b18e45a6fc02ce7bdbd335c004e74fd678ba465360487aa3acf2c149177ed4ebb7ee1d578743ac784c2209b01fdaf06acfebe31834412b74ae94f995
@@ -4,6 +4,20 @@ require "active_support"
4
4
  require "active_job"
5
5
 
6
6
  require "spicery"
7
+ require "malfunction"
8
+
9
+ require "batch_processor/malfunction/base"
10
+ require "batch_processor/malfunction/collection_empty"
11
+ require "batch_processor/malfunction/collection_invalid"
12
+ require "batch_processor/malfunction/already_started"
13
+ require "batch_processor/malfunction/already_enqueued"
14
+ require "batch_processor/malfunction/already_finished"
15
+ require "batch_processor/malfunction/already_aborted"
16
+ require "batch_processor/malfunction/already_cleared"
17
+ require "batch_processor/malfunction/still_processing"
18
+ require "batch_processor/malfunction/not_processing"
19
+ require "batch_processor/malfunction/not_aborted"
20
+ require "batch_processor/malfunction/not_started"
7
21
 
8
22
  require "batch_processor/version"
9
23
  require "batch_processor/batch_job"
@@ -15,13 +29,16 @@ require "batch_processor/collection"
15
29
  require "batch_processor/batch_base"
16
30
 
17
31
  module BatchProcessor
18
- class Error < StandardError; end
32
+ class Error < StandardError
33
+ include Conjunction::Junction
34
+ prefixed_with "BatchProcessor::"
35
+ suffixed_with "Error"
36
+ end
19
37
 
20
38
  class NotFoundError < Error; end
21
39
  class ClassMissingError < Error; end
22
40
  class CollectionEmptyError < Error; end
23
41
  class CollectionInvalidError < Error; end
24
- class AlreadyExistsError < Error; end
25
42
  class AlreadyStartedError < Error; end
26
43
  class AlreadyEnqueuedError < Error; end
27
44
  class AlreadyFinishedError < Error; end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BatchProcessor
4
+ module Batch
5
+ module Malfunction
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ attr_reader :malfunction
10
+ end
11
+
12
+ private
13
+
14
+ def build_malfunction(malfunction_class, context = nil)
15
+ @malfunction = malfunction_class.build(context)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -18,6 +18,10 @@ module BatchProcessor
18
18
  started? && !aborted? && !finished?
19
19
  end
20
20
 
21
+ def malfunction?
22
+ malfunction.present?
23
+ end
24
+
21
25
  class_methods do
22
26
  private
23
27
 
@@ -62,10 +62,23 @@ module BatchProcessor
62
62
 
63
63
  def process
64
64
  process!
65
- rescue StandardError => exception
66
- error :process_error, exception: exception
65
+ rescue BatchProcessor::Error => exception
66
+ handle_exception(exception)
67
67
  self
68
68
  end
69
+
70
+ private
71
+
72
+ def handle_exception(exception)
73
+ malfunction_class = exception.try(:conjugate, BatchProcessor::Malfunction::Base)
74
+ error :process_error, exception: exception and return if malfunction_class.nil?
75
+
76
+ if malfunction_class <= BatchProcessor::Malfunction::CollectionInvalid
77
+ build_malfunction malfunction_class, collection
78
+ else
79
+ build_malfunction malfunction_class
80
+ end
81
+ end
69
82
  end
70
83
  end
71
84
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "batch/core"
4
4
  require_relative "batch/job"
5
+ require_relative "batch/malfunction"
5
6
  require_relative "batch/processor"
6
7
  require_relative "batch/predicates"
7
8
  require_relative "batch/controller"
@@ -18,6 +19,7 @@ module BatchProcessor
18
19
 
19
20
  include BatchProcessor::Batch::Core
20
21
  include BatchProcessor::Batch::Job
22
+ include BatchProcessor::Batch::Malfunction
21
23
  include BatchProcessor::Batch::Processor
22
24
  include BatchProcessor::Batch::Predicates
23
25
  include BatchProcessor::Batch::Controller
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BatchProcessor
4
+ module Malfunction
5
+ class AlreadyAborted < Base; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BatchProcessor
4
+ module Malfunction
5
+ class AlreadyCleared < Base; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BatchProcessor
4
+ module Malfunction
5
+ class AlreadyEnqueued < Base; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BatchProcessor
4
+ module Malfunction
5
+ class AlreadyFinished < Base; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BatchProcessor
4
+ module Malfunction
5
+ class AlreadyStarted < Base; end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BatchProcessor
4
+ module Malfunction
5
+ class Base < ::Malfunction::MalfunctionBase
6
+ prefixed_with "BatchProcessor::Malfunction::"
7
+ suffixed_with nil
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BatchProcessor
4
+ module Malfunction
5
+ class CollectionEmpty < Base; end
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BatchProcessor
4
+ module Malfunction
5
+ class CollectionInvalid < Base
6
+ uses_attribute_errors
7
+ contextualize :collection
8
+ delegate :errors, to: :collection, prefix: true
9
+
10
+ on_build do
11
+ collection_errors.details.each do |attribute_name, error_details|
12
+ attribute_messages = collection_errors.messages[attribute_name]
13
+
14
+ error_details.each_with_index do |error_detail, index|
15
+ add_attribute_error(attribute_name, error_detail[:error], attribute_messages[index])
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BatchProcessor
4
+ module Malfunction
5
+ class NotAborted < Base; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BatchProcessor
4
+ module Malfunction
5
+ class NotProcessing < Base; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BatchProcessor
4
+ module Malfunction
5
+ class NotStarted < Base; end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BatchProcessor
4
+ module Malfunction
5
+ class StillProcessing < Base; end
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BatchProcessor
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: batch_processor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Garside
@@ -72,6 +72,26 @@ dependencies:
72
72
  - - "<"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '1.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: malfunction
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 0.1.1
82
+ - - "<"
83
+ - !ruby/object:Gem::Version
84
+ version: '1.0'
85
+ type: :runtime
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 0.1.1
92
+ - - "<"
93
+ - !ruby/object:Gem::Version
94
+ version: '1.0'
75
95
  - !ruby/object:Gem::Dependency
76
96
  name: bundler
77
97
  requirement: !ruby/object:Gem::Requirement
@@ -211,12 +231,25 @@ files:
211
231
  - lib/batch_processor/batch/core.rb
212
232
  - lib/batch_processor/batch/job.rb
213
233
  - lib/batch_processor/batch/job_controller.rb
234
+ - lib/batch_processor/batch/malfunction.rb
214
235
  - lib/batch_processor/batch/predicates.rb
215
236
  - lib/batch_processor/batch/processor.rb
216
237
  - lib/batch_processor/batch_base.rb
217
238
  - lib/batch_processor/batch_details.rb
218
239
  - lib/batch_processor/batch_job.rb
219
240
  - lib/batch_processor/collection.rb
241
+ - lib/batch_processor/malfunction/already_aborted.rb
242
+ - lib/batch_processor/malfunction/already_cleared.rb
243
+ - lib/batch_processor/malfunction/already_enqueued.rb
244
+ - lib/batch_processor/malfunction/already_finished.rb
245
+ - lib/batch_processor/malfunction/already_started.rb
246
+ - lib/batch_processor/malfunction/base.rb
247
+ - lib/batch_processor/malfunction/collection_empty.rb
248
+ - lib/batch_processor/malfunction/collection_invalid.rb
249
+ - lib/batch_processor/malfunction/not_aborted.rb
250
+ - lib/batch_processor/malfunction/not_processing.rb
251
+ - lib/batch_processor/malfunction/not_started.rb
252
+ - lib/batch_processor/malfunction/still_processing.rb
220
253
  - lib/batch_processor/processor/execute.rb
221
254
  - lib/batch_processor/processor/process.rb
222
255
  - lib/batch_processor/processor_base.rb