eco-helpers 3.0.6 → 3.0.7

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: 18d17b73673167619a4e704756a4e59f5d81d61a97e495721e100fe3e10d2374
4
- data.tar.gz: a873e8e8970c5d67aa224ac226bec8194f81e2025bcd434b4f1005b8ddba21a3
3
+ metadata.gz: b0fea8f72b2d0037d801b6150661827607326151c71b93df924d1f1271c17166
4
+ data.tar.gz: d0059328bb938ace9e481a8023a4e5574f1e37e034220418e752c4647de4e382
5
5
  SHA512:
6
- metadata.gz: 362fa919cbbdd98a7d69e99fa793f42a31fd790513d4d0e62db1e5838bf4937526fceb03139f394c069fd376d7a10c2cfcedf7207cda9377838b441022fa1a2f
7
- data.tar.gz: 95064a493e111f68cf5da145f6322e9a30d1c7a2ce48c022b776109fc581ba7c1fd63dbb0a26dae7dcbd0c67086ec5ee0c7c507deae55cf45aa8ed73704ecb4c
6
+ metadata.gz: 01eb1d82295aa464cad0b5898e1fa3a295a7f01953f77b1591a2c1e96a96704f1bf82beb0b41b0ce6b6e0ed6eeea07568e029f2797b62d162dd541d93b37b9ed
7
+ data.tar.gz: 21258ac597601cad5559f847f26defc78a564733b0e4ed4610d4f70b404cbf6977292a462040374f36706eb69cffabafa52179aa24531c23e29e10a53d9c539b
data/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [3.0.7] - 2024-08-xx
5
+ ## [3.0.8] - 2024-08-xx
6
6
 
7
7
  ### Added
8
8
 
@@ -10,6 +10,17 @@ All notable changes to this project will be documented in this file.
10
10
 
11
11
  ### Fixed
12
12
 
13
+ ## [3.0.7] - 2024-08-27
14
+
15
+ ### Added
16
+
17
+ - `Eco::API::UseCases::GraphQL::Helpers::Base::ErrorHandling`
18
+
19
+ ### Fixed
20
+
21
+ - `Service:TreeUpdate`
22
+ - Should NOT call `re_archive` when there was a error that is NOT due to an interrupt (i.e. so when raised **error** or `exit`ed)
23
+
13
24
  ## [3.0.6] - 2024-08-26
14
25
 
15
26
  ### Added
@@ -2,6 +2,7 @@ module Eco::API::UseCases::GraphQL::Helpers::Base
2
2
  # Basic stuff you would need in any use case
3
3
  module CaseEnv
4
4
  include Eco::Language::AuxiliarLogger
5
+ include ErrorHandling
5
6
 
6
7
  private
7
8
 
@@ -0,0 +1,52 @@
1
+ module Eco::API::UseCases::GraphQL::Helpers::Base
2
+ # Basic stuff you would need in any use case
3
+ module ErrorHandling
4
+ include Eco::Language::AuxiliarLogger
5
+
6
+ attr_reader :exception
7
+
8
+ private
9
+
10
+ def interrupted?(err = exception)
11
+ interrupt_errors.any? {|klass| err.is_a?(klass)}
12
+ end
13
+
14
+ def error_raised?
15
+ exception && !interrupted?
16
+ end
17
+
18
+ def rescued
19
+ yield
20
+ rescue StandardError => err
21
+ self.exception ||= err
22
+ log(:error) { err.patch_full_message }
23
+ end
24
+
25
+ def with_error_handling
26
+ @exception = nil
27
+ yield
28
+ rescue SystemExit => sext
29
+ @exception = sext
30
+ exit sext.status
31
+ rescue *interrupt_errors => int
32
+ @exception = int
33
+ raise
34
+ rescue SystemStackError
35
+ puts $! # rubocop:disable Style/SpecialGlobalVars
36
+ puts caller[0..100]
37
+ raise
38
+ rescue StandardError, SignalException => err
39
+ @exception = err
40
+ raise
41
+ end
42
+
43
+ def interrupt_errors
44
+ return @interrupt_errors if @interrupt_errors
45
+
46
+ errs = [Interrupt]
47
+ errs << IRB::Abort if Object.const_defined?(:IRB) && IRB.const_defined?(:Abort)
48
+
49
+ @interrupt_errors = errs
50
+ end
51
+ end
52
+ end
@@ -1,5 +1,6 @@
1
1
  module Eco::API::UseCases::GraphQL::Helpers
2
2
  module Base
3
+ require_relative 'base/error_handling'
3
4
  require_relative 'base/case_env'
4
5
  require_relative 'base/graphql_env'
5
6
 
@@ -24,38 +24,39 @@ class Eco::API::UseCases::GraphQL::Samples::Location
24
24
 
25
25
  # Main processor
26
26
  def process # rubocop:disable Metrics/AbcSize
27
- self.error = false
28
- self.exception = nil
27
+ self.error = false
29
28
 
30
- super if defined?(super)
29
+ with_error_handling do
30
+ super if defined?(super)
31
31
 
32
- # this may trigger a backup of the tagtree
33
- self.current_tree ||= live_tree
32
+ # this may trigger a backup of the tagtree
33
+ self.current_tree ||= live_tree
34
34
 
35
- inputs(force_continue: force_continue?) do |input, stage|
36
- results[stage] ||= []
35
+ inputs(force_continue: force_continue?) do |input, stage|
36
+ results[stage] ||= []
37
37
 
38
- track_mode = batch_tree_track_mode(stage)
38
+ track_mode = batch_tree_track_mode(stage)
39
39
 
40
- # yields the result of each batch
41
- sliced_batches(input, desc: stage, track_tree_mode: track_mode) do |sliced_input, response, page, pages, done, total| # rubocop:disable Metrics/ParameterLists, Layout/LineLength
42
- track_current_tree(response&.structure)
40
+ # yields the result of each batch
41
+ sliced_batches(input, desc: stage, track_tree_mode: track_mode) do |sliced_input, response, page, pages, done, total| # rubocop:disable Metrics/ParameterLists, Layout/LineLength
42
+ track_current_tree(response&.structure)
43
43
 
44
- results[stage] << (page_results = request_results_class.new(sliced_input, response))
45
- update_tags_remap_table(page_results, stage, current_tree)
44
+ results[stage] << (page_results = request_results_class.new(sliced_input, response))
45
+ update_tags_remap_table(page_results, stage, current_tree)
46
+
47
+ self.error = page_errors?(page_results, page, pages, done, total, stage: stage)
48
+ break if error
49
+ end
46
50
 
47
- self.error = page_errors?(page_results, page, pages, done, total, stage: stage)
48
51
  break if error
49
52
  end
50
-
51
- break if error
52
53
  end
53
54
  rescue SystemStackError
54
55
  puts $! # rubocop:disable Style/SpecialGlobalVars
55
56
  puts caller[0..100]
56
57
  raise
57
- rescue StandardError => e
58
- log(:error) { self.exception ||= e.patch_full_message }
58
+ rescue StandardError => err
59
+ log(:error) { err.patch_full_message }
59
60
  raise
60
61
  ensure
61
62
  rescued { self.tags_remap_csv_file = generate_tags_remap_csv }
@@ -3,13 +3,7 @@ class Eco::API::UseCases::GraphQL::Samples::Location
3
3
  module Command::Results
4
4
  include Eco::API::UseCases::GraphQL::Helpers::Base::CaseEnv
5
5
 
6
- attr_accessor :error, :exception
7
-
8
- def rescued
9
- yield
10
- rescue StandardError => e
11
- log(:error) { self.exception ||= e.patch_full_message }
12
- end
6
+ attr_accessor :error
13
7
 
14
8
  def request_results_class
15
9
  Eco::API::UseCases::GraphQL::Helpers::Location::Command::Results
@@ -7,7 +7,7 @@ class Eco::API::UseCases::GraphQL::Samples::Location
7
7
 
8
8
  class << self
9
9
  def included(base)
10
- super(base)
10
+ super
11
11
  base.send :include, Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeDiff
12
12
  base.send :include, Eco::API::UseCases::GraphQL::Samples::Location::Command::DSL
13
13
  base.send :include, Eco::API::UseCases::GraphQL::Utils::Sftp
@@ -17,9 +17,11 @@ class Eco::API::UseCases::GraphQL::Samples::Location
17
17
 
18
18
  module InstanceMethods
19
19
  def process
20
- super
20
+ with_error_handling do
21
+ super
22
+ end
21
23
  ensure
22
- rescued { re_archive }
24
+ rescued { re_archive } unless error_raised?
23
25
  rescued { email_digest('TagTree Update') }
24
26
  end
25
27
 
@@ -28,6 +30,7 @@ class Eco::API::UseCases::GraphQL::Samples::Location
28
30
  # @note this is an additional necessary step
29
31
  def re_archive
30
32
  return if simulate?
33
+ return if error_raised?
31
34
 
32
35
  stage = :rearchive
33
36
 
@@ -85,9 +88,9 @@ class Eco::API::UseCases::GraphQL::Samples::Location
85
88
  return if simulate?
86
89
  return if options.dig(:workflow, :no_email)
87
90
 
88
- digest_msgs = logger.cache.logs(level: %i[info error warn])
89
- exception = exception ? " - Exception!" : ''
90
- subject = "#{config.active_enviro} - #{title}#{exception}"
91
+ digest_msgs = logger.cache.logs(level: %i[info error warn])
92
+ str_exception = exception ? " - Exception!" : ''
93
+ subject = "#{config.active_enviro} - #{title}#{str_exception}"
91
94
  session.mail(subject: subject, body: digest_msgs.join)
92
95
  end
93
96
 
@@ -58,23 +58,17 @@ class Eco::API::UseCases::GraphQL::Samples::Location
58
58
  next if prev_id == new_id
59
59
 
60
60
  tags_remap_table << [[prev_id], [new_id]]
61
-
62
- # next unless ref_tree.is_a?(Eco::API::Organization::TagTree)
63
- # next unless ref_tree.tag?(new_id)
64
-
65
- # msg = "Node '#{prev_id}' was updated to '#{new_id}', "
66
- # msg << "but in current structure '#{new_id}' is not present"
67
- # log(:warn) { msg }
68
61
  end
69
62
  end
70
63
 
71
64
  # Generates the final tags remap file
72
65
  def generate_tags_remap_csv(filename = tags_remap_csv_full_filename)
73
- return nil if tags_remap_table.empty?
66
+ return if tags_remap_table.empty?
74
67
 
75
68
  timestamp_file(filename).tap do |file|
76
69
  CSV.open(file, 'w') do |csv|
77
70
  csv << %w[prev_node_ids new_node_ids]
71
+
78
72
  tags_remap_table.each do |tags_remap|
79
73
  csv << tags_remap.to_csv_row
80
74
  end
@@ -8,7 +8,7 @@ module Eco::API::UseCases::GraphQL::Samples::Location::Service
8
8
  module Convertible
9
9
  class << self
10
10
  def included(base)
11
- super(base)
11
+ super
12
12
  base.send :include, Inputable
13
13
  end
14
14
  end
@@ -24,12 +24,15 @@ module Eco::API::UseCases::GraphQL::Samples::Location::Service
24
24
 
25
25
  csv.transform_headers do |name|
26
26
  next name unless header_maps.key?(name)
27
+
27
28
  header_maps[name]
28
29
  end
29
30
  end.then do |csv|
30
31
  transform_input_csv(csv).tap do |res|
31
32
  next if res.is_a?(Eco::CSV::Table)
32
- raise ArgumentError, "Expecting and Eco::CSV::Table. Given: #{res.class}"
33
+
34
+ msg = "Expecting and Eco::CSV::Table. Given: #{res.class}"
35
+ raise ArgumentError, msg
33
36
  end
34
37
  end
35
38
  end
@@ -46,13 +46,15 @@ module Eco::API::UseCases::GraphQL::Samples
46
46
 
47
47
  class << self
48
48
  def included(base)
49
- super(base)
49
+ super
50
50
  base.send :include, Convertible
51
51
  end
52
52
  end
53
53
 
54
54
  def process
55
- compare
55
+ with_error_handling do
56
+ compare
57
+ end
56
58
  end
57
59
 
58
60
  def compare
@@ -31,10 +31,12 @@ module Eco::API::UseCases::GraphQL::Samples
31
31
  include Converter
32
32
 
33
33
  def process
34
- as_nodes_json(input_tagtree).tap do |list|
35
- next generate_live_nodes_file(list) unless list.empty?
34
+ with_error_handling do
35
+ as_nodes_json(input_tagtree).tap do |list|
36
+ next generate_live_nodes_file(list) unless list.empty?
36
37
 
37
- log(:error) { "There are no location nodes!" }
38
+ log(:error) { "There are no location nodes!" }
39
+ end
38
40
  end
39
41
  end
40
42
  end
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = '3.0.6'.freeze
2
+ VERSION = '3.0.7'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eco-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.6
4
+ version: 3.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -726,6 +726,7 @@ files:
726
726
  - lib/eco/api/usecases/graphql/helpers.rb
727
727
  - lib/eco/api/usecases/graphql/helpers/base.rb
728
728
  - lib/eco/api/usecases/graphql/helpers/base/case_env.rb
729
+ - lib/eco/api/usecases/graphql/helpers/base/error_handling.rb
729
730
  - lib/eco/api/usecases/graphql/helpers/base/graphql_env.rb
730
731
  - lib/eco/api/usecases/graphql/helpers/location.rb
731
732
  - lib/eco/api/usecases/graphql/helpers/location/base.rb