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
data/lib/eco/api/session.rb
CHANGED
@@ -70,6 +70,7 @@ module Eco
|
|
70
70
|
)
|
71
71
|
if live && api?(version: :graphql)
|
72
72
|
return live_tree(include_archived: include_archived, **kargs, &block) unless merge
|
73
|
+
|
73
74
|
live_trees(include_archived: include_archived, **kargs, &block).inject(&:merge)
|
74
75
|
else
|
75
76
|
config.tagtree(recache: recache)
|
@@ -118,10 +119,12 @@ module Eco
|
|
118
119
|
# @return [Eco::Data::Mapper] the mappings between the internal and external attribute/property names.
|
119
120
|
def fields_mapper
|
120
121
|
return @fields_mapper if instance_variable_defined?(:@fields_mapper)
|
122
|
+
|
121
123
|
mappings = []
|
122
124
|
if (map_file = config.people.fields_mapper)
|
123
125
|
mappings = map_file ? file_manager.load_json(map_file) : []
|
124
126
|
end
|
127
|
+
|
125
128
|
@fields_mapper = Eco::Data::Mapper.new(mappings)
|
126
129
|
end
|
127
130
|
|
@@ -166,9 +169,9 @@ module Eco
|
|
166
169
|
# @param phase [Symbol] the phase when this parser should be active.
|
167
170
|
# @return [Object] the parsed attribute.
|
168
171
|
def parse_attribute(attr, source, phase = :internal, deps: {})
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
+
msg = "There are no parsers defined"
|
173
|
+
raise msg unless (parsers = entry_factory.person_parser)
|
174
|
+
|
172
175
|
parsers.parse(attr, source, phase, deps: deps)
|
173
176
|
end
|
174
177
|
|
@@ -390,18 +393,19 @@ module Eco
|
|
390
393
|
|
391
394
|
# from schema `id` or `name` to a PersonSchema object
|
392
395
|
def to_schema(value)
|
393
|
-
return nil unless value
|
394
396
|
sch = nil
|
397
|
+
return unless value
|
398
|
+
|
395
399
|
case value
|
396
400
|
when String
|
397
|
-
|
398
|
-
|
399
|
-
end
|
401
|
+
msg = "The schema with id or name '#{value}' does not exist."
|
402
|
+
fatal msg unless (sch = schemas.schema(value))
|
400
403
|
when Ecoportal::API::V1::PersonSchema
|
401
404
|
sch = value
|
402
405
|
else
|
403
406
|
fatal "Required String or Ecoportal::API::V1::PersonSchema. Given: #{value}"
|
404
407
|
end
|
408
|
+
|
405
409
|
sch
|
406
410
|
end
|
407
411
|
end
|
@@ -27,6 +27,7 @@ class Eco::API::UseCases::Default::Locations::TagtreeUpload < Eco::API::UseCases
|
|
27
27
|
comms << insert_command(tree, pid: pid) unless top_id?(tree.id)
|
28
28
|
pid = tree.id
|
29
29
|
end
|
30
|
+
|
30
31
|
tree.nodes.map do |node|
|
31
32
|
insert_commands(node, pid: pid)
|
32
33
|
end.flatten(1).tap do |subs|
|
@@ -54,6 +55,7 @@ class Eco::API::UseCases::Default::Locations::TagtreeUpload < Eco::API::UseCases
|
|
54
55
|
|
55
56
|
def top_id?(node_id = nil)
|
56
57
|
return top_id.is_a?(String) if node_id.nil?
|
58
|
+
|
57
59
|
node_id == top_id
|
58
60
|
end
|
59
61
|
|
@@ -7,7 +7,7 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
|
|
7
7
|
name "sftp"
|
8
8
|
type :other
|
9
9
|
|
10
|
-
CONST_REFERRAL = /^(?:::)?(?:[A-Z][a-zA-Z0-9_]*(?:::[A-Z][a-zA-Z0-9_]*)*)
|
10
|
+
CONST_REFERRAL = /^(?:::)?(?:[A-Z][a-zA-Z0-9_]*(?:::[A-Z][a-zA-Z0-9_]*)*)$/
|
11
11
|
|
12
12
|
def main(session, options, _usecase)
|
13
13
|
options[:end_get] = false
|
@@ -31,7 +31,7 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
|
|
31
31
|
def file_pattern(require: true)
|
32
32
|
fpc = file_pattern_const
|
33
33
|
return fpc if fpc
|
34
|
-
return
|
34
|
+
return unless require
|
35
35
|
|
36
36
|
msg = "(#{self.class}) You should redefine the file_pattern function "
|
37
37
|
msg << "as a RegEx expression that matches the target remote file"
|
@@ -41,6 +41,7 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
|
|
41
41
|
def file_pattern_const
|
42
42
|
if (fpc = options.dig(:sftp, :file_pattern_const))
|
43
43
|
raise WrongConst, "(#{self.class}) Invalid file pattern const referral: #{fpc}" unless fpc.match(CONST_REFERRAL)
|
44
|
+
|
44
45
|
begin
|
45
46
|
self.eval(fpc)
|
46
47
|
rescue NameError
|
@@ -54,6 +55,7 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
|
|
54
55
|
# Ex: "/IN/Personnel"
|
55
56
|
def remote_subfolder(require: true)
|
56
57
|
rm_sf = options.dig(:sftp, :remote_subfolder)
|
58
|
+
|
57
59
|
return rm_sf if rm_sf
|
58
60
|
return unless require
|
59
61
|
|
@@ -78,7 +80,7 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
|
|
78
80
|
options.dig(:sftp, :local_folder) || "."
|
79
81
|
end
|
80
82
|
|
81
|
-
def with_remote_files(folder:
|
83
|
+
def with_remote_files(folder: remote_folder, pattern: file_pattern)
|
82
84
|
sftp.files(folder, pattern: pattern).each do |remote_file|
|
83
85
|
yield(remote_file) if block_given?
|
84
86
|
end
|
@@ -100,22 +102,25 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
|
|
100
102
|
|
101
103
|
def get_files
|
102
104
|
with_remote_files.tap do |files|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
105
|
+
next if files.empty?
|
106
|
+
|
107
|
+
file_names = files.map {|file| to_remote_path(file.name)}
|
108
|
+
|
109
|
+
puts "Getting the following files into the local folder '#{local_folder}':"
|
110
|
+
puts file_names
|
111
|
+
|
112
|
+
sftp.download(file_names, local_folder: local_folder)
|
109
113
|
end
|
110
114
|
end
|
111
115
|
|
112
116
|
def get_last
|
113
117
|
with_remote_files.last.tap do |file|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
118
|
+
next unless file
|
119
|
+
|
120
|
+
file_name = to_remote_path(file.name)
|
121
|
+
puts "Getting the following file: #{file_name}"
|
122
|
+
|
123
|
+
sftp.download(file_name, local_folder: local_folder)
|
119
124
|
end
|
120
125
|
end
|
121
126
|
|
@@ -125,7 +130,9 @@ class Eco::API::UseCases::DefaultCases::Samples::Sftp < Eco::API::Common::Loader
|
|
125
130
|
dest = to_remote_path("#{archive_subfolder}/#{file.name}")
|
126
131
|
move_file(source, dest)
|
127
132
|
end.tap do |files|
|
128
|
-
|
133
|
+
next if files.empty?
|
134
|
+
|
135
|
+
puts "Moved the file(s) to the #{archive_subfolder} folder"
|
129
136
|
end
|
130
137
|
end
|
131
138
|
|
@@ -40,7 +40,7 @@ class Eco::API::UseCases::OozeCases::ExportRegisterCase < Eco::API::UseCases::Oo
|
|
40
40
|
|
41
41
|
def build_tags_filter(mode = :any)
|
42
42
|
tags = option_tags(mode)
|
43
|
-
return
|
43
|
+
return if !tags || tags.empty?
|
44
44
|
|
45
45
|
tags_filter(tags, any: mode == :any)
|
46
46
|
end
|
@@ -48,7 +48,7 @@ class Eco::API::UseCases::OozeCases::ExportRegisterCase < Eco::API::UseCases::Oo
|
|
48
48
|
def build_range_filter(key = :update_at)
|
49
49
|
from = from_date(key)
|
50
50
|
to = to_date(key)
|
51
|
-
return
|
51
|
+
return unless from || to
|
52
52
|
|
53
53
|
date_range_filter(from: from, to: to, key: key)
|
54
54
|
end
|
@@ -92,10 +92,10 @@ class Eco::API::UseCases::OozeCases::ExportRegisterCase < Eco::API::UseCases::Oo
|
|
92
92
|
|
93
93
|
def filename
|
94
94
|
@filename ||= (options[:file] || options.dig(:export, :file, :name)).tap do |filename|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
95
|
+
next if filename
|
96
|
+
|
97
|
+
log(:error) { "Destination file not specified" }
|
98
|
+
return false
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
@@ -3,17 +3,19 @@ class Eco::API::UseCases::OozeSamples::OozeRunBaseCase < Eco::API::UseCases::Ooz
|
|
3
3
|
name "ooze-run-base"
|
4
4
|
type :other
|
5
5
|
|
6
|
-
SAVE_PATCH = "ooze_patch_update.json"
|
6
|
+
SAVE_PATCH = "ooze_patch_update.json".freeze
|
7
7
|
|
8
8
|
def main(session, options, usecase)
|
9
9
|
super(session, options, usecase) do
|
10
|
-
if method(:process_ooze).parameters.count
|
10
|
+
if method(:process_ooze).parameters.count.zero?
|
11
11
|
ooze # retrieve ooze
|
12
12
|
process_ooze
|
13
13
|
else
|
14
14
|
process_ooze(ooze)
|
15
15
|
end
|
16
|
+
|
16
17
|
yield(target) if block_given?
|
18
|
+
|
17
19
|
exit_if_no_changes!
|
18
20
|
update_ooze(target)
|
19
21
|
end
|
@@ -30,7 +32,7 @@ class Eco::API::UseCases::OozeSamples::OozeRunBaseCase < Eco::API::UseCases::Ooz
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def stage(stage_id_name = stage_id, ooze: target)
|
33
|
-
super
|
35
|
+
super
|
34
36
|
end
|
35
37
|
|
36
38
|
def ooze_id
|
@@ -43,11 +45,12 @@ class Eco::API::UseCases::OozeSamples::OozeRunBaseCase < Eco::API::UseCases::Ooz
|
|
43
45
|
|
44
46
|
def update_ooze(ooz = target)
|
45
47
|
prompt_to_confirm!
|
46
|
-
|
48
|
+
|
49
|
+
super
|
47
50
|
end
|
48
51
|
|
49
52
|
def exit_if_no_changes!
|
50
|
-
return if
|
53
|
+
return if !!patch_doc["page"]
|
51
54
|
|
52
55
|
log(:info) { "No Changes!!" }
|
53
56
|
exit(0)
|
@@ -1,6 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
formats = {
|
1
|
+
class Eco::CliDefault::Input < Eco::API::Common::Loaders::CliConfig
|
2
|
+
FORMATS = {
|
4
3
|
csv: {
|
5
4
|
option: ["-csv"],
|
6
5
|
extname: [".csv", ".txt"]
|
@@ -17,51 +16,74 @@ ASSETS.cli.config do |cnf|
|
|
17
16
|
option: ["-json"],
|
18
17
|
extname: [".json"]
|
19
18
|
}
|
20
|
-
}
|
19
|
+
}.freeze
|
21
20
|
|
22
|
-
|
23
|
-
|
21
|
+
class << self
|
22
|
+
attr_reader :options, :session
|
24
23
|
|
24
|
+
def encoding
|
25
|
+
options.dig(:input, :file, :encoding)
|
26
|
+
end
|
27
|
+
|
28
|
+
def format_by_cli
|
29
|
+
FORMATS.reduce(nil) do |matched, (frm, selectors)|
|
30
|
+
next matched if matched
|
31
|
+
|
32
|
+
used = selectors[:option].reduce(false) do |us, option|
|
33
|
+
SCR.get_arg(option) || us
|
34
|
+
end
|
35
|
+
|
36
|
+
next frm if used
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def format_by_ext(ext)
|
41
|
+
FORMATS.reduce(nil) do |matched, (frm, selectors)|
|
42
|
+
next matched if matched
|
43
|
+
next frm if selectors[:extname].any? {|e| ext == e}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
input(default_option: "-entries-from") do |session, str_opt, options|
|
49
|
+
@options = options
|
50
|
+
@session = session
|
51
|
+
input = []
|
25
52
|
next input unless SCR.get_arg(str_opt)
|
26
53
|
|
27
54
|
file = SCR.get_file(str_opt, required: true)
|
28
55
|
|
29
56
|
# Command line check
|
30
|
-
format =
|
31
|
-
used = selectors[:option].reduce(false) {|us, option| SCR.get_arg(option) || us}
|
32
|
-
next matched if matched
|
33
|
-
next frm if used
|
34
|
-
end
|
57
|
+
format = format_by_cli
|
35
58
|
|
36
59
|
# File/Folder check
|
37
60
|
file = File.expand_path(file)
|
61
|
+
|
38
62
|
if File.directory?(file)
|
39
63
|
folder = file
|
40
64
|
file = Dir.glob("#{file}/*").reject {|f| File.directory?(f)}
|
41
|
-
ext = (format
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
65
|
+
ext = FORMATS.dig(format, :extname)
|
66
|
+
ext ||= [File.extname(file.first)]
|
67
|
+
file = file.select do |f|
|
68
|
+
ext.any? {|e| File.extname(f) == e}
|
69
|
+
end.tap do |files|
|
70
|
+
next unless files.empty?
|
71
|
+
|
72
|
+
session.log(:error) {
|
73
|
+
"Could not find any file with extension: #{ext} in folder '#{folder}'"
|
74
|
+
}
|
75
|
+
exit(1)
|
49
76
|
end
|
50
77
|
else
|
51
|
-
ext = File.extname(file)
|
78
|
+
ext = [File.extname(file)]
|
52
79
|
end
|
53
80
|
|
54
|
-
format ||=
|
55
|
-
next matched if matched
|
56
|
-
next frm if selectors[:extname].any? {|e| ext == e}
|
57
|
-
end
|
81
|
+
format ||= format_by_ext(ext.first)
|
58
82
|
format ||= :csv
|
59
83
|
|
60
|
-
options.deep_merge!(input: {file: {name:
|
84
|
+
options.deep_merge!(input: {file: {name: file}})
|
61
85
|
options.deep_merge!(input: {file: {format: format}})
|
62
86
|
|
63
|
-
encoding = options.dig(:input, :file, :encoding)
|
64
|
-
|
65
87
|
case format
|
66
88
|
when :xml
|
67
89
|
[file].flatten.each {|f| session.config.files.validate(:xml, f)}
|
@@ -83,5 +105,3 @@ ASSETS.cli.config do |cnf|
|
|
83
105
|
input
|
84
106
|
end
|
85
107
|
end
|
86
|
-
|
87
|
-
# rubocop:enable Metrics/BlockLength
|
@@ -69,7 +69,10 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
|
|
69
69
|
sch_id = session.schemas.to_id(sch_name)
|
70
70
|
|
71
71
|
unless sch_id
|
72
|
-
msg = "You need to specify a correct schema id or name.
|
72
|
+
msg = "You need to specify a correct schema id or name. "
|
73
|
+
msg << "'#{sch_name}' does not exist. Correct options are: "
|
74
|
+
msg << session.schemas.map(&:name).join(", ")
|
75
|
+
|
73
76
|
session.log(:error) { msg }
|
74
77
|
exit(1)
|
75
78
|
end
|
@@ -1,69 +1,124 @@
|
|
1
|
-
|
1
|
+
class Eco::CliDefault::People < Eco::API::Common::Loaders::CliConfig
|
2
|
+
MAX_GET_PARTIAL = 12_000
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
get = {} if get.nil?
|
4
|
+
class << self
|
5
|
+
attr_reader :options, :session
|
6
|
+
attr_writer :get_full, :get_partial
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
def get_options # rubocop:disable Naming/AccessorMethodName
|
9
|
+
get = options.dig(:people, :get)
|
10
|
+
get = {} if get.nil?
|
11
|
+
get
|
12
|
+
end
|
13
|
+
|
14
|
+
def no_get?
|
15
|
+
get_options == false
|
16
|
+
end
|
10
17
|
|
11
|
-
|
12
|
-
|
13
|
-
|
18
|
+
def from_remote?
|
19
|
+
return false unless get_options
|
20
|
+
|
21
|
+
get_options[:from] == :remote
|
22
|
+
end
|
23
|
+
|
24
|
+
def from_local?
|
25
|
+
return false unless get_options
|
26
|
+
|
27
|
+
get_options[:from] == :local
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_full?
|
31
|
+
return @get_full if instance_variable_defined?(:@get_full)
|
32
|
+
return false unless from_remote?
|
33
|
+
|
34
|
+
get_options[:type] == :full
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_partial?
|
38
|
+
return @get_partial if instance_variable_defined?(:@get_partial)
|
39
|
+
return false unless from_remote?
|
40
|
+
|
41
|
+
@get_partial = (get_options[:type] == :partial)
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_by_file?
|
45
|
+
return false unless from_local?
|
46
|
+
|
47
|
+
get_options[:type] == :file
|
48
|
+
end
|
49
|
+
|
50
|
+
def source_file
|
51
|
+
return unless get_by_file?
|
52
|
+
|
53
|
+
get_options[:file]
|
54
|
+
end
|
55
|
+
|
56
|
+
def switch_to_full_remote!
|
57
|
+
self.get_full = true
|
58
|
+
self.get_partial = false
|
59
|
+
|
60
|
+
options.deep_merge!(people: {
|
61
|
+
get: {
|
62
|
+
from: :remote,
|
63
|
+
type: :full
|
64
|
+
}
|
65
|
+
})
|
66
|
+
end
|
67
|
+
|
68
|
+
def switch_to_full_local!
|
69
|
+
self.get_full = true
|
70
|
+
self.get_partial = false
|
71
|
+
|
72
|
+
options.deep_merge!(people: {
|
73
|
+
get: {
|
74
|
+
from: :local,
|
75
|
+
type: :full
|
76
|
+
}
|
77
|
+
})
|
78
|
+
end
|
79
|
+
|
80
|
+
def optimize_get_partial!(input)
|
81
|
+
return unless get_partial?
|
14
82
|
|
15
|
-
# -get-partial: validate input present and under max
|
16
|
-
if get_partial
|
17
83
|
msg = "To use -get-partial (partial updates), you need to use -entries-from"
|
18
84
|
raise msg unless input.is_a?(Enumerable)
|
19
85
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
options.deep_merge!(people: {
|
31
|
-
get: {
|
32
|
-
from: :remote,
|
33
|
-
type: :full
|
34
|
-
}
|
35
|
-
})
|
36
|
-
end
|
86
|
+
return unless input.count > MAX_GET_PARTIAL
|
87
|
+
|
88
|
+
msg = "(Optimization) "
|
89
|
+
msg << "Switching from partial to full people download. "
|
90
|
+
msg << "Input (#{input.count}) surpases MAX_GET_PARTIAL "
|
91
|
+
msg << "(#{MAX_GET_PARTIAL}) entries."
|
92
|
+
session.log(:info) { msg }
|
93
|
+
|
94
|
+
switch_to_full_remote!
|
37
95
|
end
|
96
|
+
end
|
97
|
+
|
98
|
+
people do |input, session, options|
|
99
|
+
@options = options
|
100
|
+
@session = session
|
38
101
|
|
39
|
-
|
102
|
+
# -get-partial: validate input present and under max
|
103
|
+
optimize_get_partial!(input) if get_partial?
|
104
|
+
|
105
|
+
if no_get?
|
40
106
|
Eco::API::Organization::People.new([])
|
41
|
-
elsif get_full
|
107
|
+
elsif get_full?
|
42
108
|
# -get-people
|
43
109
|
session.micro.people_cache
|
44
|
-
elsif get_partial
|
110
|
+
elsif get_partial?
|
45
111
|
# -get-partial
|
46
112
|
session.micro.people_search(input, options: options)
|
47
|
-
elsif get_by_file
|
113
|
+
elsif get_by_file?
|
48
114
|
# -people-from-backup
|
49
|
-
session.micro.people_load(
|
115
|
+
session.micro.people_load(source_file, modifier: :file)
|
50
116
|
else
|
51
|
-
|
52
|
-
get: {
|
53
|
-
from: :local,
|
54
|
-
type: :full
|
55
|
-
}
|
56
|
-
})
|
57
|
-
|
117
|
+
switch_to_full_local!
|
58
118
|
people = session.micro.people_load(modifier: %i[newest save])
|
59
119
|
|
60
120
|
if people.empty?
|
61
|
-
|
62
|
-
get: {
|
63
|
-
from: :remote,
|
64
|
-
type: :full
|
65
|
-
}
|
66
|
-
})
|
121
|
+
switch_to_full_remote!
|
67
122
|
people = session.micro.people_cache
|
68
123
|
end
|
69
124
|
|
@@ -92,7 +92,10 @@ ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength
|
|
92
92
|
sch_id = session.schemas.to_id(sch_name)
|
93
93
|
|
94
94
|
unless sch_id
|
95
|
-
msg = "You need to specify a correct schema id or name.
|
95
|
+
msg = "You need to specify a correct schema id or name. "
|
96
|
+
msg << "'#{sch_name}' does not exist. Correct options are: "
|
97
|
+
msg << session.schemas.map(&:name).join(", ")
|
98
|
+
|
96
99
|
session.log(:error) { msg }
|
97
100
|
exit(1)
|
98
101
|
end
|
@@ -1,12 +1,14 @@
|
|
1
1
|
ASSETS.cli do |cli| # rubocop:disable Metrics/BlockLength
|
2
2
|
ASSETS.config.workflow do |wf| # rubocop:disable Metrics/BlockLength
|
3
3
|
rescued = false
|
4
|
+
|
4
5
|
# default rescue
|
5
6
|
wf.rescue do |err, io|
|
6
7
|
next io if rescued
|
7
8
|
|
8
9
|
rescued = true
|
9
10
|
log(:debug) { err.patch_full_message }
|
11
|
+
|
10
12
|
wf.run(:close, io: io)
|
11
13
|
rescue StandardError => e
|
12
14
|
puts "Some problem in workflow.rescue: #{e}"
|
@@ -74,10 +76,10 @@ ASSETS.cli do |cli| # rubocop:disable Metrics/BlockLength
|
|
74
76
|
end
|
75
77
|
|
76
78
|
wf.on(:usecases) do |_wf_ca, io|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
79
|
+
next if cli.config.usecases.process(io: io)
|
80
|
+
|
81
|
+
log(:info) { "No update operation specified... quitting" }
|
82
|
+
exit 0
|
81
83
|
end
|
82
84
|
|
83
85
|
wf.before(:launch_jobs) do |_wf_jobs, _io|
|
@@ -95,11 +97,13 @@ ASSETS.cli do |cli| # rubocop:disable Metrics/BlockLength
|
|
95
97
|
run_it = !options[:dry_run] || options.dig(:post_launch, :run)
|
96
98
|
unless run_it
|
97
99
|
wf_post.skip!
|
100
|
+
|
98
101
|
log(:info) {
|
99
102
|
msg = "Although there are post_launch cases, they will NOT be RUN"
|
100
103
|
msg << ", because we are in dry-run (simulate)." if options[:dry_run]
|
101
104
|
msg
|
102
105
|
}
|
106
|
+
|
103
107
|
next
|
104
108
|
end
|
105
109
|
|
@@ -117,6 +121,7 @@ ASSETS.cli do |cli| # rubocop:disable Metrics/BlockLength
|
|
117
121
|
end
|
118
122
|
msg
|
119
123
|
}
|
124
|
+
|
120
125
|
next
|
121
126
|
end
|
122
127
|
|
@@ -131,6 +136,7 @@ ASSETS.cli do |cli| # rubocop:disable Metrics/BlockLength
|
|
131
136
|
use.launch(io: io).base
|
132
137
|
rescue Eco::API::UseCases::BaseIO::MissingParameter => e
|
133
138
|
raise unless e.required == :people
|
139
|
+
|
134
140
|
log(:debug) {
|
135
141
|
"Skipping use case '#{use.name}' -- no base people detected for the current run"
|
136
142
|
}
|
data/lib/eco/csv/stream.rb
CHANGED
@@ -7,6 +7,7 @@ module Eco
|
|
7
7
|
|
8
8
|
def initialize(filename, **kargs)
|
9
9
|
raise ArgumentError, "File '#{filename}' does not exist" unless ::File.exist?(filename)
|
10
|
+
|
10
11
|
@filename = filename
|
11
12
|
@params = {
|
12
13
|
headers: true,
|
@@ -55,6 +56,7 @@ module Eco
|
|
55
56
|
# see https://dalibornasevic.com/posts/68-processing-large-csv-files-with-ruby
|
56
57
|
def csv
|
57
58
|
return @csv if instance_variable_defined?(:@csv)
|
59
|
+
|
58
60
|
@fd = ::File.open(filename, 'r')
|
59
61
|
@csv = Eco::CSV.new(fd, **params)
|
60
62
|
end
|
data/lib/eco/csv.rb
CHANGED
@@ -5,9 +5,9 @@ module Eco
|
|
5
5
|
include Eco::Data::Files
|
6
6
|
|
7
7
|
# @return [Eco::CSV::Table]
|
8
|
-
def parse(data, **kargs
|
8
|
+
def parse(data, **kargs)
|
9
9
|
kargs = {headers: true, skip_blanks: true}.merge(kargs)
|
10
|
-
Eco::CSV::Table.new(super
|
10
|
+
Eco::CSV::Table.new(super)
|
11
11
|
end
|
12
12
|
|
13
13
|
# @return [Eco::CSV::Table]
|
@@ -51,6 +51,7 @@ module Eco
|
|
51
51
|
included = yield(row) if block_given?
|
52
52
|
count += 1 if included
|
53
53
|
end
|
54
|
+
|
54
55
|
count
|
55
56
|
end
|
56
57
|
end
|