eco-helpers 3.0.19 → 3.0.21
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +35 -3
- data/lib/eco/api/common/loaders/config/cli.rb +9 -0
- data/lib/eco/api/common/loaders/config/session.rb +12 -0
- data/lib/eco/api/common/loaders/config/workflow/mailer.rb +17 -4
- data/lib/eco/api/common/loaders/config.rb +11 -2
- data/lib/eco/api/common/people/default_parsers/xls_parser.rb +1 -1
- data/lib/eco/api/common/session/logger/cache.rb +10 -4
- data/lib/eco/api/common/session/logger/channels.rb +41 -0
- data/lib/eco/api/common/session/logger.rb +9 -0
- data/lib/eco/api/common/session/sftp.rb +5 -0
- data/lib/eco/api/custom/mailer.rb +1 -0
- data/lib/eco/api/error.rb +4 -0
- data/lib/eco/api/session/batch/job.rb +25 -16
- data/lib/eco/api/session/batch/jobs.rb +6 -8
- data/lib/eco/api/session/batch/launcher/mode_size.rb +5 -2
- data/lib/eco/api/session/batch/launcher/retry.rb +6 -1
- data/lib/eco/api/session/config/api.rb +1 -0
- data/lib/eco/api/session/config/apis/one_off.rb +6 -6
- data/lib/eco/api/session/config/workflow.rb +16 -3
- data/lib/eco/api/session.rb +11 -7
- data/lib/eco/api/usecases/default/locations/tagtree_extract_case.rb +1 -0
- data/lib/eco/api/usecases/default/locations/tagtree_upload_case.rb +2 -0
- data/lib/eco/api/usecases/default_cases/samples/sftp_case.rb +22 -15
- data/lib/eco/api/usecases/ooze_cases/export_register_case.rb +6 -6
- data/lib/eco/api/usecases/ooze_samples/helpers/exportable_register.rb +1 -0
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +1 -1
- data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +8 -5
- data/lib/eco/cli_default/input.rb +49 -29
- data/lib/eco/cli_default/options.rb +4 -1
- data/lib/eco/cli_default/people.rb +102 -47
- data/lib/eco/cli_default/people_filters.rb +4 -1
- data/lib/eco/cli_default/workflow.rb +10 -4
- data/lib/eco/csv/stream.rb +2 -0
- data/lib/eco/csv.rb +3 -2
- data/lib/eco/language/auxiliar_logger.rb +16 -3
- data/lib/eco/language/basic_logger.rb +1 -0
- data/lib/eco/language/methods/delegate_missing.rb +4 -3
- data/lib/eco/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7764e6e3e78228f59b9a5f5baf2aa8602c627882905a23270007b4fe1a09c9f
|
4
|
+
data.tar.gz: aca94b571b1c70c000e0d88f09182f2339a306187c5f9651968e9692981d79d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcef313643bc67ba9d90755e3ce8a3a3a39c1973404b2dcd35292b76c67d158ad3e9c666414e2f6254776eeb800f4d07fc2ab10953a15e9e2b293d2b8f15303e
|
7
|
+
data.tar.gz: 3d12155562df35e9ecadea021a758f922f35ab68d689592e4a319e41232b4865a87e22c0e333b1083e42340418f57388f24139748246d08652142ef52f1a041d
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,41 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
-
## [3.0.
|
5
|
+
## [3.0.21] - 2024-12-16
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- `Eco::API::Common::Session::Logger`
|
10
|
+
- Implement **channels** logging.
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
|
14
|
+
- Moved `input` and `people` **cli_default configurations** to a class definition
|
15
|
+
- `Eco::Language::AuxiliarLogger#log`
|
16
|
+
- Allow for multiple levels
|
17
|
+
- Return `NilClass`
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
|
21
|
+
- `Eco::API::Session::Batch::Job#summary`
|
22
|
+
- Ensure a summary of pending jobs can be handled, even if `#launch` was NOT explicitly called.
|
23
|
+
- As we don't consolidate, it may give more actual updates than pending, yet this is better than providing the `count` of entries in the job's queue.
|
24
|
+
|
25
|
+
## [3.0.20] - 2024-12-07
|
26
|
+
|
27
|
+
### Added
|
28
|
+
|
29
|
+
- Mailer: to specify non-default `space` in the subject, when used.
|
30
|
+
- `Eco::API::Common::Loaders::Config`
|
31
|
+
- Can call config with params
|
32
|
+
- `Eco::API::Common::Loaders::Session`
|
33
|
+
- Which switches the configuration to that of the specific environment
|
34
|
+
|
35
|
+
### Changed
|
36
|
+
|
37
|
+
- On failure, `Eco::API::Session::Job#summary` to give precise estimates on what is pending to be run.
|
38
|
+
|
39
|
+
## [3.0.19] - 2024-11-21
|
6
40
|
|
7
41
|
### Added
|
8
42
|
|
@@ -21,8 +55,6 @@ All notable changes to this project will be documented in this file.
|
|
21
55
|
- `ecoportal-api-v2`
|
22
56
|
- `ecoportal-api-graphql`
|
23
57
|
|
24
|
-
### Fixed
|
25
|
-
|
26
58
|
## [3.0.18] - 2024-10-28
|
27
59
|
|
28
60
|
### Changed
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Eco::API::Common::Loaders::Session < Eco::API::Common::Loaders::Config
|
2
|
+
class << self
|
3
|
+
# This is a config tied to the current environment session.
|
4
|
+
def config
|
5
|
+
return @config if instance_variable_defined?(:@config)
|
6
|
+
|
7
|
+
@config = super(key: super.apis.active_root_name)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
delegate_missing_to :workflow
|
12
|
+
end
|
@@ -18,9 +18,8 @@ class Eco::API::Common::Loaders::Workflow::Mailer < Eco::API::Common::Loaders::W
|
|
18
18
|
next if session.config.dry_run?
|
19
19
|
next unless session.config.run_mode_remote?
|
20
20
|
|
21
|
-
# temporary contingency
|
22
|
-
|
23
|
-
next unless some_update?(io) || maybe_error_pages_or_tree_updates
|
21
|
+
# temporary contingency: maybe_error_or_tree_updates?
|
22
|
+
next unless some_update?(io) || maybe_error_pages_or_tree_updates?(io)
|
24
23
|
|
25
24
|
subject = base_subject
|
26
25
|
|
@@ -47,7 +46,15 @@ class Eco::API::Common::Loaders::Workflow::Mailer < Eco::API::Common::Loaders::W
|
|
47
46
|
end
|
48
47
|
|
49
48
|
def base_subject
|
50
|
-
"#{org_name} (#{
|
49
|
+
"#{org_name} (#{active_enviro_desc}) at #{Time.now.iso8601}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def active_enviro_desc
|
53
|
+
space_desc = config.active_enviro_space.to_s.strip
|
54
|
+
space_desc = '' if space_desc == 'default'
|
55
|
+
space_desc = " - space: '#{space_desc}'" unless space_desc.empty?
|
56
|
+
|
57
|
+
"#{active_enviro}#{space_desc}"
|
51
58
|
end
|
52
59
|
|
53
60
|
def some_update?(io)
|
@@ -66,6 +73,11 @@ class Eco::API::Common::Loaders::Workflow::Mailer < Eco::API::Common::Loaders::W
|
|
66
73
|
!!error
|
67
74
|
end
|
68
75
|
|
76
|
+
# @note at some stage, tree cases should have their own case type
|
77
|
+
def maybe_error_pages_or_tree_updates?(io)
|
78
|
+
other_case?(io) && error?
|
79
|
+
end
|
80
|
+
|
69
81
|
def errors_n_warnings(io)
|
70
82
|
[error_message, log_err_n_warn(io)].join("\n")
|
71
83
|
end
|
@@ -73,6 +85,7 @@ class Eco::API::Common::Loaders::Workflow::Mailer < Eco::API::Common::Loaders::W
|
|
73
85
|
def log_err_n_warn(io)
|
74
86
|
warn_errors = io.logger.cache.logs(level: %i[error warn])
|
75
87
|
return if warn_errors.empty?
|
88
|
+
|
76
89
|
"ALL WARNINGS & ERRORS:\n#{warn_errors.join}\n"
|
77
90
|
end
|
78
91
|
|
@@ -1,17 +1,24 @@
|
|
1
1
|
class Eco::API::Common::Loaders::Config
|
2
2
|
extend Eco::API::Common::ClassHelpers
|
3
3
|
extend Eco::Language::Methods::DelegateMissing
|
4
|
+
|
4
5
|
inheritable_class_vars :delegate_missing_to
|
5
6
|
|
6
7
|
class << self
|
7
8
|
# To create samples of configurations
|
8
9
|
def config_block(&block)
|
9
10
|
return @config_block unless block_given?
|
11
|
+
|
12
|
+
unless @config_block.nil?
|
13
|
+
msg = "Reconfiguring config_block on #{self}"
|
14
|
+
session.log(:warn) { msg }
|
15
|
+
end
|
16
|
+
|
10
17
|
@config_block = block
|
11
18
|
end
|
12
19
|
|
13
|
-
def config
|
14
|
-
ASSETS.config
|
20
|
+
def config(...)
|
21
|
+
ASSETS.config(...)
|
15
22
|
end
|
16
23
|
|
17
24
|
def cli
|
@@ -26,4 +33,6 @@ class Eco::API::Common::Loaders::Config
|
|
26
33
|
delegate_missing_to :config
|
27
34
|
end
|
28
35
|
|
36
|
+
require_relative 'config/cli'
|
29
37
|
require_relative 'config/workflow'
|
38
|
+
require_relative 'config/session'
|
@@ -27,7 +27,7 @@ class Eco::API::Common::People::DefaultParsers::XLSParser < Eco::API::Common::Lo
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def expected_headers
|
30
|
-
log(:
|
30
|
+
log(:info) {
|
31
31
|
"Headers detection is using your fields_map.json file (native behaviour)"
|
32
32
|
}
|
33
33
|
session.fields_mapper.list(:external).uniq
|
@@ -4,7 +4,8 @@ module Eco
|
|
4
4
|
module Session
|
5
5
|
class Logger
|
6
6
|
class Cache
|
7
|
-
LEVELS
|
7
|
+
LEVELS = %w[UNKNOWN FATAL ERROR WARN INFO DEBUG].freeze
|
8
|
+
CHANNELS = Logger::CHANNELS.map(&:to_s).map(&:upcase).freeze
|
8
9
|
|
9
10
|
def initialize
|
10
11
|
reset
|
@@ -56,7 +57,8 @@ module Eco
|
|
56
57
|
end
|
57
58
|
|
58
59
|
def to_datetime(value)
|
59
|
-
return
|
60
|
+
return unless value
|
61
|
+
|
60
62
|
Time.parse(value)
|
61
63
|
end
|
62
64
|
|
@@ -64,7 +66,7 @@ module Eco
|
|
64
66
|
levels = [value].flatten.map {|v| to_level(v)}.compact
|
65
67
|
return levels unless levels.empty?
|
66
68
|
|
67
|
-
|
69
|
+
valid_levels
|
68
70
|
end
|
69
71
|
|
70
72
|
def to_level(value)
|
@@ -75,7 +77,7 @@ module Eco
|
|
75
77
|
|
76
78
|
def valid_level!(str)
|
77
79
|
return true unless str
|
78
|
-
return true if
|
80
|
+
return true if valid_levels.any? {|lev| str == lev}
|
79
81
|
|
80
82
|
msg = "Unknown level #{str}. Should be one of #{LEVELS}"
|
81
83
|
raise ArgumentError, msg
|
@@ -87,6 +89,10 @@ module Eco
|
|
87
89
|
|
88
90
|
value
|
89
91
|
end
|
92
|
+
|
93
|
+
def valid_levels
|
94
|
+
@valid_levels ||= self.class::LEVELS | self.class::CHANNELS
|
95
|
+
end
|
90
96
|
end
|
91
97
|
end
|
92
98
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module Common
|
4
|
+
module Session
|
5
|
+
class Logger
|
6
|
+
module Channels
|
7
|
+
CHANNELS = %i[general].freeze
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def included(base)
|
11
|
+
super
|
12
|
+
base.extend ClassMethods
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
def channels!(&def_block)
|
18
|
+
str = "Block with channel implementation expected. None given."
|
19
|
+
raise ArgumentError, str unless block_given?
|
20
|
+
|
21
|
+
channels.each do |channel|
|
22
|
+
meth = channel.to_s.downcase.to_sym
|
23
|
+
|
24
|
+
define_method(meth) do |msg = nil, &block|
|
25
|
+
def_block.call(meth, msg, &block)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def channels
|
33
|
+
self::CHANNELS
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -5,6 +5,15 @@ module Eco
|
|
5
5
|
class Logger < Eco::Language::BasicLogger
|
6
6
|
TIMESTAMP_PATTERN = '%Y-%m-%dT%H:%M:%S'.freeze
|
7
7
|
|
8
|
+
require_relative 'logger/channels'
|
9
|
+
include Channels
|
10
|
+
|
11
|
+
channels! do |channel, message = nil, &block|
|
12
|
+
format_proc(console: true) do |severity, datetime, msg, formatted_msg|
|
13
|
+
cache.add(severity, datetime, msg, formatted_msg)
|
14
|
+
end.call(channel, Time.now, 'prog_name', message || block.call)
|
15
|
+
end
|
16
|
+
|
8
17
|
attr_reader :cache
|
9
18
|
|
10
19
|
def initialize(file_level: ::Logger::DEBUG, log_file: nil, enviro: nil, **kargs)
|
@@ -8,6 +8,7 @@ module Eco
|
|
8
8
|
def initialize(enviro:)
|
9
9
|
invalid_env = enviro && !enviro.is_a?(Eco::API::Common::Session::Environment)
|
10
10
|
raise "Required Environment object (enviro:). Given: #{enviro}" if invalid_env
|
11
|
+
|
11
12
|
@enviro = enviro
|
12
13
|
end
|
13
14
|
|
@@ -103,6 +104,7 @@ module Eco
|
|
103
104
|
def download(files, local_folder: nil, &block)
|
104
105
|
puts "Creating local files:"
|
105
106
|
created_files = []
|
107
|
+
|
106
108
|
[files].flatten.compact.map do |fullname|
|
107
109
|
basename = windows_basename(fullname)
|
108
110
|
dest_fullname = File.join(local_folder || ".", basename)
|
@@ -110,6 +112,7 @@ module Eco
|
|
110
112
|
created_files << dest_fullname
|
111
113
|
sftp_session.download(fullname, dest_fullname)
|
112
114
|
end.each(&:wait)
|
115
|
+
|
113
116
|
# run SSH event loop while dw.active?
|
114
117
|
created_files.tap { created_files.each(&block) }
|
115
118
|
end
|
@@ -155,9 +158,11 @@ module Eco
|
|
155
158
|
def windows_basename(remote_fullname)
|
156
159
|
dir_sep = /[\\\/]/
|
157
160
|
patr_re = /[<>:\\\/|?*]/
|
161
|
+
|
158
162
|
parts = remote_fullname.split(dir_sep).map do |node|
|
159
163
|
node.gsub(patr_re, '_')
|
160
164
|
end
|
165
|
+
|
161
166
|
local_fullname = File.join(*parts)
|
162
167
|
File.basename(local_fullname)
|
163
168
|
end
|
data/lib/eco/api/error.rb
CHANGED
@@ -96,9 +96,11 @@ module Eco
|
|
96
96
|
end.sort do |k_1, k_2|
|
97
97
|
next -1 if k_2 < k_1
|
98
98
|
next 1 if k_1 < k_2
|
99
|
+
|
99
100
|
0
|
100
101
|
end.tap do |siblings|
|
101
102
|
siblings.delete(Unclassified)
|
103
|
+
|
102
104
|
if direct
|
103
105
|
siblings.reject! do |si|
|
104
106
|
siblings.any? {|s| si < s}
|
@@ -120,8 +122,10 @@ module Eco
|
|
120
122
|
|
121
123
|
descendants(direct: true).reverse.each do |klass|
|
122
124
|
next unless klass.err_match?(err_msg)
|
125
|
+
|
123
126
|
type = klass
|
124
127
|
next unless klass.descendants?(direct: true)
|
128
|
+
|
125
129
|
type = klass.get_type(err_msg, first: false) || type
|
126
130
|
end
|
127
131
|
|
@@ -146,6 +146,16 @@ module Eco
|
|
146
146
|
@pending
|
147
147
|
end
|
148
148
|
|
149
|
+
# @note some times we need a summary of what actually
|
150
|
+
# is going to be run without invoking `launch`
|
151
|
+
# (i.e. when there's a uncompliance with the batch policy)
|
152
|
+
def ensure_requests!
|
153
|
+
return if instance_variable_defined?(:@requests)
|
154
|
+
|
155
|
+
pqueue = processed_queue
|
156
|
+
@requests = as_update(pqueue)
|
157
|
+
end
|
158
|
+
|
149
159
|
# @note it requires launch to be firstly invoked
|
150
160
|
# @raise [Exception] if 'launch' has not firstly invoked
|
151
161
|
# @return [Enumbrable<Hash>] the last requests that the queue will generate
|
@@ -217,6 +227,7 @@ module Eco
|
|
217
227
|
elsif !pqueue.empty?
|
218
228
|
req_backup = as_update(pqueue, add_feedback: false)
|
219
229
|
backup_update(req_backup)
|
230
|
+
|
220
231
|
log(:debug) {
|
221
232
|
"Job ('#{name}':#{type}): going to launch batch against #{pqueue.count} entries"
|
222
233
|
}
|
@@ -246,28 +257,26 @@ module Eco
|
|
246
257
|
# 3. error messages in case they were errors from the server
|
247
258
|
# @note if `launch` was not invoked, it specifies so
|
248
259
|
# @return [String] the summary
|
249
|
-
def summary
|
260
|
+
def summary
|
250
261
|
[].tap do |msg|
|
251
|
-
if pending?
|
252
|
-
|
253
|
-
|
254
|
-
msg << feedback.generate(requests, only_stats: true)
|
262
|
+
msg << "PENDING Job -------->\n" if pending?
|
263
|
+
ensure_requests!
|
264
|
+
msg << feedback.generate(requests, only_stats: true)
|
255
265
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
end
|
260
|
-
|
261
|
-
msg << status.errors.message if status
|
262
|
-
msg << subjobs_summary
|
266
|
+
if batch_policy && !batch_policy.compliant?(request_stats)
|
267
|
+
msg << 'Batch Policy Uncompliance:'
|
268
|
+
msg << batch_policy.uncompliance(request_stats)
|
263
269
|
end
|
270
|
+
|
271
|
+
msg << status.errors.message if status
|
272
|
+
msg << subjobs_summary
|
264
273
|
end.join("\n")
|
265
274
|
end
|
266
275
|
|
267
276
|
private
|
268
277
|
|
269
278
|
def subjobs_summary
|
270
|
-
return
|
279
|
+
return '' unless subjobs.count.positive?
|
271
280
|
|
272
281
|
[].tap do |msg|
|
273
282
|
subjobs.map {|subjob| msg << subjob.summary}
|
@@ -431,7 +440,7 @@ module Eco
|
|
431
440
|
next unless status.success?(entry)
|
432
441
|
|
433
442
|
if type == :create && entry.respond_to?(:id=)
|
434
|
-
entry.id = status[entry].body[
|
443
|
+
entry.id = status[entry].body['id'].tap do |id|
|
435
444
|
next unless id.to_s.strip.empty?
|
436
445
|
|
437
446
|
ref = Eco::API::Session::Batch::Feedback.person_ref(entry)
|
@@ -503,9 +512,9 @@ module Eco
|
|
503
512
|
|
504
513
|
# Keep a copy of the requests for future reference
|
505
514
|
def backup_update(requests, simulate: false)
|
506
|
-
dry_run = simulate ?
|
515
|
+
dry_run = simulate ? '_dry_run' : ''
|
507
516
|
dir = config.people.requests_folder
|
508
|
-
filename = name.split(
|
517
|
+
filename = name.split(' ').join('-').gsub(/[=\\\/><,"-]+/, "_") # rubocop:disable Style/RedundantArgument
|
509
518
|
file = File.join(dir, "#{type}_data_#{filename}#{dry_run}.json")
|
510
519
|
file_manager.save_json(requests, file, :timestamp)
|
511
520
|
end
|
@@ -81,7 +81,7 @@ module Eco
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def pending?
|
84
|
-
any?
|
84
|
+
any?(&:pending?)
|
85
85
|
end
|
86
86
|
|
87
87
|
# Launches every `Batch::Job` in the group.
|
@@ -108,19 +108,17 @@ module Eco
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
def status
|
111
|
+
def status(&block)
|
112
112
|
if block_given?
|
113
|
-
status.each
|
114
|
-
yield(job, job_status)
|
115
|
-
end
|
113
|
+
status.each(&block)
|
116
114
|
self
|
117
|
-
else
|
118
|
-
@jobs_status ||= {}
|
115
|
+
else
|
116
|
+
@jobs_status ||= {} # rubocop:disable Naming/MemoizedInstanceVariableName
|
119
117
|
end
|
120
118
|
end
|
121
119
|
|
122
120
|
def errors?
|
123
|
-
any?
|
121
|
+
any?(&:errors?)
|
124
122
|
end
|
125
123
|
|
126
124
|
def summary
|
@@ -18,14 +18,17 @@ module Eco
|
|
18
18
|
private
|
19
19
|
|
20
20
|
# Swaps to batch endpoint on specific errors
|
21
|
-
def batch_mode_on(*error_types, options: self.options, allow_job_mode: true
|
21
|
+
def batch_mode_on(*error_types, options: self.options, allow_job_mode: true)
|
22
|
+
msg = "Expecting block. Non given"
|
23
|
+
raise ArgumentError, msg unless block_given?
|
24
|
+
|
22
25
|
in_job_mode = allow_job_mode && job_mode?(options)
|
23
26
|
|
24
27
|
yield(in_job_mode, batch_size(options))
|
25
28
|
rescue *error_types
|
26
29
|
raise unless in_job_mode
|
27
30
|
|
28
|
-
yield(false
|
31
|
+
yield(false, batch_mode_size)
|
29
32
|
end
|
30
33
|
|
31
34
|
# MODE
|
@@ -25,7 +25,12 @@ module Eco
|
|
25
25
|
explanation << "You have #{retries_left} retries left."
|
26
26
|
question = " Do you want to retry (y/N)?"
|
27
27
|
|
28
|
-
prompt_user(
|
28
|
+
prompt_user(
|
29
|
+
question,
|
30
|
+
default: "Y",
|
31
|
+
explanation: explanation,
|
32
|
+
timeout: 10
|
33
|
+
) do |response|
|
29
34
|
raise unless response.upcase.start_with?("Y")
|
30
35
|
|
31
36
|
puts "\nOkay... let's retry!"
|
@@ -4,14 +4,14 @@ module Eco
|
|
4
4
|
class Config
|
5
5
|
class Apis
|
6
6
|
module OneOff
|
7
|
-
private
|
8
|
-
|
9
7
|
def one_off?
|
10
|
-
@is_one_off ||=
|
8
|
+
@is_one_off ||= # rubocop:disable Naming/MemoizedInstanceVariableName
|
11
9
|
SCR.get_arg('-api-key') ||
|
12
10
|
SCR.get_arg('-one-off')
|
13
11
|
end
|
14
12
|
|
13
|
+
private
|
14
|
+
|
15
15
|
def one_off_key
|
16
16
|
return @one_off_key if instance_variable_defined?(:@one_off_key)
|
17
17
|
|
@@ -48,10 +48,10 @@ module Eco
|
|
48
48
|
return @one_off_org if instance_variable_defined?(:@one_off_org)
|
49
49
|
|
50
50
|
msg = "You should specify -org NAME when using -api-key or -one-off"
|
51
|
-
raise msg unless org = SCR.get_arg('-org', with_param: true)
|
51
|
+
raise msg unless (org = SCR.get_arg('-org', with_param: true))
|
52
52
|
|
53
53
|
str_org = "#{org.downcase.split(/[^a-z]+/).join('_')}_#{one_off_enviro.gsub('.', '_')}"
|
54
|
-
@one_off_org
|
54
|
+
@one_off_org ||= str_org.to_sym
|
55
55
|
end
|
56
56
|
|
57
57
|
def one_off_enviro
|
@@ -83,7 +83,7 @@ module Eco
|
|
83
83
|
|
84
84
|
true
|
85
85
|
rescue StandardError => err
|
86
|
-
puts
|
86
|
+
puts err.to_s
|
87
87
|
false
|
88
88
|
end
|
89
89
|
end
|
@@ -141,7 +141,8 @@ module Eco
|
|
141
141
|
# @yieldreturn [Eco::API::UseCases::BaseIO] the `io` input/output object carried througout all the _workflow_
|
142
142
|
# @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
|
143
143
|
def rescue(&block)
|
144
|
-
return @rescue unless
|
144
|
+
return @rescue unless block_given?
|
145
|
+
|
145
146
|
@rescue = block
|
146
147
|
self
|
147
148
|
end
|
@@ -150,7 +151,8 @@ module Eco
|
|
150
151
|
|
151
152
|
# Called on `SystemExit` exception
|
152
153
|
def exit_handle(&block)
|
153
|
-
return @exit_handle unless
|
154
|
+
return @exit_handle unless block_given?
|
155
|
+
|
154
156
|
@exit_handle = block
|
155
157
|
self
|
156
158
|
end
|
@@ -171,6 +173,7 @@ module Eco
|
|
171
173
|
# @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
|
172
174
|
def before(key = nil, &block)
|
173
175
|
raise ArgumentError, "A block should be given." unless block_given?
|
176
|
+
|
174
177
|
if key
|
175
178
|
stage(key).before(&block)
|
176
179
|
else
|
@@ -195,6 +198,7 @@ module Eco
|
|
195
198
|
# @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
|
196
199
|
def after(key = nil, &block)
|
197
200
|
raise ArgumentError, "A block should be given." unless block_given?
|
201
|
+
|
198
202
|
if key
|
199
203
|
stage(key).after(&block)
|
200
204
|
else
|
@@ -267,6 +271,7 @@ module Eco
|
|
267
271
|
io.evaluate(self, io, &c)
|
268
272
|
end
|
269
273
|
end
|
274
|
+
|
270
275
|
io
|
271
276
|
end
|
272
277
|
|
@@ -276,6 +281,7 @@ module Eco
|
|
276
281
|
io.evaluate(self, io, &c)
|
277
282
|
end
|
278
283
|
end
|
284
|
+
|
279
285
|
io
|
280
286
|
end
|
281
287
|
|
@@ -305,6 +311,7 @@ module Eco
|
|
305
311
|
io.evaluate(self, io, &@on)
|
306
312
|
end
|
307
313
|
end
|
314
|
+
|
308
315
|
io
|
309
316
|
ensure
|
310
317
|
@pending = false
|
@@ -341,7 +348,11 @@ module Eco
|
|
341
348
|
|
342
349
|
def stage(key)
|
343
350
|
self.class.validate_stage(key)
|
344
|
-
@stages[key] ||= self.class.workflow_class(key).new(
|
351
|
+
@stages[key] ||= self.class.workflow_class(key).new(
|
352
|
+
key,
|
353
|
+
_parent: self,
|
354
|
+
config: config
|
355
|
+
)
|
345
356
|
end
|
346
357
|
|
347
358
|
# helper to treat trigger the exit and rescue handlers
|
@@ -354,6 +365,7 @@ module Eco
|
|
354
365
|
io = io_result(io: io) do
|
355
366
|
io.evaluate(err, io, &exit_handle)
|
356
367
|
end
|
368
|
+
|
357
369
|
exit err.status
|
358
370
|
rescue Interrupt => _int
|
359
371
|
raise
|
@@ -362,6 +374,7 @@ module Eco
|
|
362
374
|
io = io_result(io: io) do
|
363
375
|
io.evaluate(err, io, &self.rescue)
|
364
376
|
end
|
377
|
+
|
365
378
|
raise
|
366
379
|
end
|
367
380
|
end
|