eco-helpers 2.0.33 → 2.0.37
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/CHANGELOG.md +51 -1
- data/eco-helpers.gemspec +1 -1
- data/lib/eco/api/usecases/default_cases/upsert_case.rb +1 -1
- data/lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb +15 -0
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +143 -0
- data/lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb +0 -7
- data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +21 -93
- data/lib/eco/api/usecases/ooze_samples/ooze_update_case.rb +0 -9
- data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +163 -0
- data/lib/eco/api/usecases/ooze_samples.rb +2 -0
- data/lib/eco/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0a1e3f56c23a45ecb80f852556b02b1ac7cc3a2546a72bcb5d2d05283bbc66b6
|
|
4
|
+
data.tar.gz: 82250daa8e645c1a68d79d047d938fd3371c909d9eeb04dca58548d5bd907543
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d93e88f2f6dab9ca740d7c21741be6c6aec2885c98336fe7d0d247964e995b519603aaf989872073a3ff93234f64cce3cb62bece56ed4c33d7597de186f70bae
|
|
7
|
+
data.tar.gz: 4cd351d33ef0f66d178273d64ba52b39356204a8b31aabc358bda6267892af678c785b17537eb2ca2b00533a81b2ee600b3e648f40891b4438162a7362d33825
|
data/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,57 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
|
3
3
|
|
|
4
|
-
## [2.0.
|
|
4
|
+
## [2.0.37] - 2021-09-03
|
|
5
|
+
|
|
6
|
+
### Added
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
- `Eco::API::UseCases::OozeSamples::OozeBaseCase`
|
|
11
|
+
- `#update_ooze` only count dry run for changed pages (to have better feedack)
|
|
12
|
+
- stop downloading the people manager
|
|
13
|
+
- `Eco::API::UseCases::OozeSamples::RegisterUpdateCase`
|
|
14
|
+
- prevent queuing non page objects
|
|
15
|
+
|
|
16
|
+
## [2.0.36] - 2021-08-31
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
- `Eco::API::UseCases::OozeSamples::OozeBaseCase`
|
|
20
|
+
- `#update_ooze` only count dry run for changed pages (to have better feedack)
|
|
21
|
+
|
|
22
|
+
## [2.0.35] - 2021-08-30
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
- `Eco::API::UseCases::OozeSamples::OozeBaseCase`
|
|
26
|
+
- `#new_target` optional warning when switching `target`
|
|
27
|
+
- `block` that is called when switching target and there were unsaved changes
|
|
28
|
+
- `#dirty?` helper method to check if there are changes
|
|
29
|
+
- `#before_loading_new_target` hook to allow child classes to anticipate when the `target` is going to change
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
- `Eco::API::UseCases::OozeSamples::Helpers::Shortcuts#object_reference` improved reference text
|
|
33
|
+
- `Eco::API::UseCases::OozeSamples::RegisterUpdateCase`
|
|
34
|
+
- added resilience when switching target (i.e. from one stage to another stage in same entry)
|
|
35
|
+
- added `batch_queue`
|
|
36
|
+
|
|
37
|
+
### Fixed
|
|
38
|
+
- `Eco::API::UseCases::OozeSamples::RegisterUpdateCase`
|
|
39
|
+
- actual `batch_size` updates
|
|
40
|
+
- actual safe switch of target (i.e. against another stage of same ooze)
|
|
41
|
+
|
|
42
|
+
## [2.0.34] - 2021-08-28
|
|
43
|
+
|
|
44
|
+
### Added
|
|
45
|
+
- `Eco::API::UseCases::OozeSamples::OozeBaseCase` refactored ooze base case
|
|
46
|
+
- `Eco::API::UseCases::OozeSamples::RegisterUpdateCase` new case for full register update
|
|
47
|
+
|
|
48
|
+
### Changed
|
|
49
|
+
- `Eco::API::UseCases::OozeSamples::OozeRunBaseCase` made child of `OozeBaseCase` and simplified to its essential
|
|
50
|
+
- `Eco::API::UseCases::OozeSamples::OozeUpdateCase` remove unnecessary code and helpers that are now inherited from `OoozeBaseCase`
|
|
51
|
+
- `Eco::API::UseCases::OozeSamples::OozeFromDocCase` remove unnecessary code
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## [2.0.33] - 2021-08-16
|
|
5
55
|
|
|
6
56
|
### Added
|
|
7
57
|
- `Eco::API::UseCases::OozeSamples::OozeFromDocCase` use case to abstract form from doc
|
data/eco-helpers.gemspec
CHANGED
|
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
|
|
|
31
31
|
spec.add_development_dependency "redcarpet", ">= 3.5.1", "< 3.6"
|
|
32
32
|
|
|
33
33
|
spec.add_dependency 'ecoportal-api', '>= 0.8.3', '< 0.9'
|
|
34
|
-
spec.add_dependency 'ecoportal-api-v2', '>= 0.8.
|
|
34
|
+
spec.add_dependency 'ecoportal-api-v2', '>= 0.8.13', '< 0.9'
|
|
35
35
|
spec.add_dependency 'aws-sdk-s3', '>= 1.83.0', '< 2'
|
|
36
36
|
spec.add_dependency 'aws-sdk-ses', '>= 1.36.0', '< 2'
|
|
37
37
|
spec.add_dependency 'dotenv', '>= 2.7.6', '< 2.8'
|
|
@@ -54,6 +54,21 @@ module Eco
|
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
+
def object_reference(obj)
|
|
58
|
+
return "No reference" unless obj
|
|
59
|
+
"".tap do |ref|
|
|
60
|
+
case obj
|
|
61
|
+
when Ecoportal::API::V2::Page::Stage
|
|
62
|
+
ref << "Stage"
|
|
63
|
+
when Ecoportal::API::V2::Pages::PageStage
|
|
64
|
+
ref << "Page (#{obj.id}) (#{object_reference(obj.current_stage)})"
|
|
65
|
+
when Ecoportal::API::V2::Page
|
|
66
|
+
ref << "Page"
|
|
67
|
+
end
|
|
68
|
+
ref << " '#{obj.name}'" if obj.respond_to?(:name)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
57
72
|
end
|
|
58
73
|
end
|
|
59
74
|
end
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# @attr_reader target [Ecoportal::API::V2::Page] current target ooze.
|
|
2
|
+
class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders::UseCase
|
|
3
|
+
name "ooze-base"
|
|
4
|
+
type :other
|
|
5
|
+
|
|
6
|
+
include Eco::API::UseCases::OozeSamples::Helpers
|
|
7
|
+
|
|
8
|
+
attr_reader :session, :options, :usecase
|
|
9
|
+
attr_reader :target
|
|
10
|
+
|
|
11
|
+
SAVE_PATCH = "ooze_patch_update.json"
|
|
12
|
+
DRY_COUNT = 5
|
|
13
|
+
|
|
14
|
+
def main(session, options, usecase)
|
|
15
|
+
options[:end_get] = false
|
|
16
|
+
raise "You need to inherit from this class ('#{self.class}') and call super with a block" unless block_given?
|
|
17
|
+
@session = session; @options = options; @usecase = usecase
|
|
18
|
+
@target = nil
|
|
19
|
+
yield
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Write here your script
|
|
23
|
+
def process_ooze(ooze = target)
|
|
24
|
+
raise "You need to inherit from this class ('#{self.class}') and call super with a block" unless block_given?
|
|
25
|
+
yield(ooze)
|
|
26
|
+
update_ooze(ooze)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
# Hook method to use before the target is switched
|
|
32
|
+
def before_loading_new_target(ooze_id)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def ooze(ooze_id = nil, stage_id: nil)
|
|
36
|
+
return target unless ooze_id
|
|
37
|
+
before_loading_new_target(ooze_id)
|
|
38
|
+
apiv2.pages.get(ooze_id, stage_id: stage_id).tap do |ooze|
|
|
39
|
+
if ooze
|
|
40
|
+
new_target(ooze)
|
|
41
|
+
logger.info("Got #{object_reference(ooze)}")
|
|
42
|
+
else
|
|
43
|
+
exit_error "Could not get ooze '#{ooze_id}'"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def stage(id_name = nil, ooze: target)
|
|
49
|
+
if ooze_id = ooze && ooze.id
|
|
50
|
+
exit_error "#{object_reference(ooze)} does not have stages!" unless ooze.stages?
|
|
51
|
+
else
|
|
52
|
+
exit_error "There's no target ooze to get retrieve stages from"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
if stg = ooze.stages[id_name] || ooze.stages.get_by_name(id_name)
|
|
56
|
+
return ooze if ooze.respond_to?(:current_stage_id) && (ooze.current_stage_id == stg.id)
|
|
57
|
+
before_loading_new_target(ooze_id)
|
|
58
|
+
return apiv2.pages.get(ooze_id, stage_id: stg.id).tap do |stage|
|
|
59
|
+
if stage
|
|
60
|
+
new_target(stage)
|
|
61
|
+
logger.info("Got #{object_reference(stage)} from #{object_reference(ooze)}")
|
|
62
|
+
else
|
|
63
|
+
exit_error "Could not get stage '#{id_name}' in ooze '#{ooze_id}'"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
exit_error "Stage '#{id_name}' doesn't exist in ooze '#{ooze_id}'"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def update_ooze(ooze = target)
|
|
71
|
+
if !options[:simulate]
|
|
72
|
+
return unless dirty?(ooze)
|
|
73
|
+
apiv2.pages.update(ooze).tap do |response|
|
|
74
|
+
if response.success?
|
|
75
|
+
ooze.consolidate!
|
|
76
|
+
logger.info("Successful update of #{object_reference(ooze)}")
|
|
77
|
+
else
|
|
78
|
+
logger.error("Could not update #{object_reference(ooze)} (created_at: #{ooze.created_at}: #{response.body}")
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
else
|
|
82
|
+
unless options.dig(:feedback, :only_stats)
|
|
83
|
+
if patch = (patch_doc(ooze) || {})["page"]
|
|
84
|
+
pp patch
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
backup_patch!(ooze)
|
|
88
|
+
exit(0) if dirty?(ooze) && dry_count > DRY_COUNT
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def new_target(object, warn_pending_changes: true)
|
|
93
|
+
if dirty?(target)
|
|
94
|
+
if warn_pending_changes
|
|
95
|
+
msg = "You you are switching to a new target #{object_reference(object)}"
|
|
96
|
+
msg += " after doing unsaved changes to #{object_reference(target)}"
|
|
97
|
+
logger.warn msg
|
|
98
|
+
end
|
|
99
|
+
yield(target) if block_given?
|
|
100
|
+
end
|
|
101
|
+
@target = object
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def dirty?(object)
|
|
105
|
+
object && patch_doc(object)["page"]
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def backup_patch!(ooze = target)
|
|
109
|
+
unless patch = (patch_doc(ooze) || {})["page"]
|
|
110
|
+
logger.info "No changes to update for #{object_reference(ooze)}."
|
|
111
|
+
return
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
patch = patch_doc(ooze)
|
|
115
|
+
# store the request
|
|
116
|
+
File.open(SAVE_PATCH, "w") do |file|
|
|
117
|
+
#file << (patch_doc || {}).to_json
|
|
118
|
+
file << JSON.pretty_generate(patch || {})
|
|
119
|
+
end
|
|
120
|
+
# TODO: ooze_requests folder with subfolders: for each run
|
|
121
|
+
puts "Saved patch at: #{File.expand_path(SAVE_PATCH)}"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def patch_doc(ooze = target)
|
|
125
|
+
apiv2.pages.get_body(ooze)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def dry_count
|
|
129
|
+
@dry_count ||= 0
|
|
130
|
+
@dry_count += 1
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def apiv2
|
|
134
|
+
@apiv2 ||= session.api(version: :oozes)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def exit_error(msg)
|
|
138
|
+
logger.error(msg)
|
|
139
|
+
exit(1)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
end
|
|
@@ -4,13 +4,6 @@ class Eco::API::UseCases::OozeSamples::OozeFromDocCase < Eco::API::UseCases::Ooz
|
|
|
4
4
|
name "ooze-forms-case"
|
|
5
5
|
type :other
|
|
6
6
|
|
|
7
|
-
def main(session, options, usecase)
|
|
8
|
-
raise "You need to inherit from this class and call super with a block" unless block_given?
|
|
9
|
-
super(session, options, usecase) do
|
|
10
|
-
yield
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
7
|
private
|
|
15
8
|
|
|
16
9
|
def with_column(num = 0)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
class
|
|
1
|
+
# Base class to run a script against a single ooze.
|
|
2
|
+
class Eco::API::UseCases::OozeSamples::OozeRunBaseCase < Eco::API::UseCases::OozeSamples::OozeBaseCase
|
|
2
3
|
name "ooze-run-base"
|
|
3
4
|
type :other
|
|
4
5
|
|
|
@@ -6,20 +7,28 @@ class Eco::API::UseCases::OozeSamples::OozeRunBaseCase < Eco::API::Common::Loade
|
|
|
6
7
|
|
|
7
8
|
SAVE_PATCH = "ooze_patch_update.json"
|
|
8
9
|
|
|
9
|
-
def main(session, options, usecase)
|
|
10
|
-
raise "You need to inherit from this class and call super with a block" unless
|
|
10
|
+
def main(session, options, usecase, &block)
|
|
11
|
+
raise "You need to inherit from this class and call super with a block" unless block
|
|
11
12
|
@session = session; @options = options; @usecase = usecase
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
process_ooze(&block)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def process_ooze(ooze = target)
|
|
17
|
+
raise "You need to inherit from this class and call super with a block" unless block_given?
|
|
18
|
+
super(ooze) do
|
|
19
|
+
yield(ooze)
|
|
20
|
+
exit_if_no_changes!
|
|
21
|
+
end
|
|
14
22
|
end
|
|
15
23
|
|
|
16
24
|
private
|
|
17
25
|
|
|
18
|
-
def
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
def ooze
|
|
27
|
+
super(ooze_id, stage_id: stage_id)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def stage(stage_id_name = stage_id, ooze: target)
|
|
31
|
+
super(stage_id_name, ooze: ooze)
|
|
23
32
|
end
|
|
24
33
|
|
|
25
34
|
def ooze_id
|
|
@@ -30,54 +39,9 @@ class Eco::API::UseCases::OozeSamples::OozeRunBaseCase < Eco::API::Common::Loade
|
|
|
30
39
|
options.dig(:source, :stage_id)
|
|
31
40
|
end
|
|
32
41
|
|
|
33
|
-
def
|
|
34
|
-
@target ||= ooze
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def new_target(object)
|
|
38
|
-
if @target && patch_doc["page"]
|
|
39
|
-
logger.warn "You you are switching to a new target #{object_reference(object)} after doing unsaved changes to #{object_reference(@target)}"
|
|
40
|
-
end
|
|
41
|
-
@target = object
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def stage(id_name = stage_id)
|
|
45
|
-
if stg = ooze.stages[id_name] || ooze.stages.get_by_name(id_name)
|
|
46
|
-
return apiv2.pages.get(ooze_id, stage_id: stg.id).tap do |stage|
|
|
47
|
-
if stage
|
|
48
|
-
new_target(stage)
|
|
49
|
-
logger.info("Got #{object_reference(stage)} from #{object_reference(ooze)}")
|
|
50
|
-
else
|
|
51
|
-
logger.error("Could not get stage '#{id_name}' in ooze '#{ooze_id}'")
|
|
52
|
-
exit(1)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
raise "Stage '#{id_name}' doesn't exist in ooze '#{ooze_id}'"
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def ooze
|
|
60
|
-
@ooze ||= apiv2.pages.get(ooze_id, stage_id: stage_id).tap do |ooze|
|
|
61
|
-
if ooze
|
|
62
|
-
new_target(ooze)
|
|
63
|
-
logger.info("Got #{object_reference(ooze)}")
|
|
64
|
-
else
|
|
65
|
-
logger.error("Could not get ooze '#{ooze_id}'")
|
|
66
|
-
exit(1)
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def launch_request
|
|
42
|
+
def update_ooze
|
|
72
43
|
prompt_to_confirm!
|
|
73
|
-
|
|
74
|
-
apiv2.pages.update(target).tap do |response|
|
|
75
|
-
if response.success?
|
|
76
|
-
logger.info("All went OK")
|
|
77
|
-
else
|
|
78
|
-
logger.error(response.body)
|
|
79
|
-
end
|
|
80
|
-
end
|
|
44
|
+
super
|
|
81
45
|
end
|
|
82
46
|
|
|
83
47
|
def exit_if_no_changes!
|
|
@@ -87,46 +51,10 @@ class Eco::API::UseCases::OozeSamples::OozeRunBaseCase < Eco::API::Common::Loade
|
|
|
87
51
|
end
|
|
88
52
|
end
|
|
89
53
|
|
|
90
|
-
def apiv2
|
|
91
|
-
@apiv2 ||= session.api(version: :oozes)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def patch_doc
|
|
95
|
-
apiv2.pages.get_body(target)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def backup_patch!
|
|
99
|
-
# store the request
|
|
100
|
-
File.open(SAVE_PATCH, "w") do |file|
|
|
101
|
-
#file << (patch_doc || {}).to_json
|
|
102
|
-
file << JSON.pretty_generate(patch_doc || {})
|
|
103
|
-
end
|
|
104
|
-
puts "Saved patch at: #{File.expand_path(SAVE_PATCH)}"
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def object_reference(obj)
|
|
108
|
-
return "No reference" unless obj
|
|
109
|
-
"".tap do |ref|
|
|
110
|
-
case obj
|
|
111
|
-
when Ecoportal::API::V2::Page::Stage
|
|
112
|
-
ref << "Stage "
|
|
113
|
-
when Ecoportal::API::V2::Pages::PageStage
|
|
114
|
-
ref << "StagePage "
|
|
115
|
-
when Ecoportal::API::V2::Page
|
|
116
|
-
ref << "Page "
|
|
117
|
-
end
|
|
118
|
-
ref << "'#{obj.name}' " if obj.respond_to?(:name)
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
54
|
def prompt_to_confirm!
|
|
123
55
|
micro.prompt_user("Do you want to proceed (y/N)?", default: "Y") do |response|
|
|
124
56
|
exit(1) unless response.upcase.start_with?("Y")
|
|
125
57
|
end
|
|
126
58
|
end
|
|
127
59
|
|
|
128
|
-
def logger
|
|
129
|
-
session.logger
|
|
130
|
-
end
|
|
131
|
-
|
|
132
60
|
end
|
|
@@ -2,15 +2,6 @@ class Eco::API::UseCases::OozeSamples::OozeUpdateCase < Eco::API::UseCases::Ooze
|
|
|
2
2
|
name "single-ooze-case"
|
|
3
3
|
type :other
|
|
4
4
|
|
|
5
|
-
include Eco::API::UseCases::OozeSamples::Helpers
|
|
6
|
-
|
|
7
|
-
def main(session, options, usecase)
|
|
8
|
-
raise "You need to inherit from this class and call super with a block" unless block_given?
|
|
9
|
-
super(session, options, usecase) do
|
|
10
|
-
yield
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
5
|
private
|
|
15
6
|
|
|
16
7
|
def with_fields(type: nil, label: nil)
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Use case to update a register
|
|
2
|
+
# @note
|
|
3
|
+
# - You can define methods `filters` and `search` to change the target entries of the register
|
|
4
|
+
# - You need to define the `process_ooze` method
|
|
5
|
+
# This case expects `options[:source][:register_id]`
|
|
6
|
+
class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::OozeSamples::OozeBaseCase
|
|
7
|
+
|
|
8
|
+
class << self
|
|
9
|
+
# @return [Integer] the number of pages to be processed in each batch
|
|
10
|
+
def batch_size(size = nil)
|
|
11
|
+
@batch_size ||= 25
|
|
12
|
+
return @batch_size unless size
|
|
13
|
+
@batch_size = size
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
name "register-update-case"
|
|
18
|
+
type :other
|
|
19
|
+
|
|
20
|
+
def main(session, options, usecase, &block)
|
|
21
|
+
super(session, options, usecase) do
|
|
22
|
+
with_each_entry do |ooze|
|
|
23
|
+
process_ooze(&block)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def process_ooze(ooze = target)
|
|
29
|
+
raise "You need to define this method"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def before_loading_new_target(ooze_id)
|
|
35
|
+
if pending = queue_shift(ooze_id)
|
|
36
|
+
update_ooze(pending)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def new_target(object, warn_pending_changes: false)
|
|
41
|
+
enqueue(object)
|
|
42
|
+
super(object, warn_pending_changes: warn_pending_changes) do |pending|
|
|
43
|
+
#enqueue(pending)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def with_each_entry
|
|
48
|
+
batched_search_results do |page_results|
|
|
49
|
+
page_results.each do |page_result|
|
|
50
|
+
if pending = queue_shift(page_result.id)
|
|
51
|
+
if dirty?(pending)
|
|
52
|
+
msg = "Inconsistent search results. "
|
|
53
|
+
msg << "Launching update on '#{object_reference(pending)}' to be able to queue it back"
|
|
54
|
+
console.warn msg
|
|
55
|
+
update_ooze(pending)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
if ooz = ooze(page_result.id)
|
|
59
|
+
yield(ooz)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
update_oozes
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def enqueue(object)
|
|
67
|
+
return unless object && object.respond_to?(:id)
|
|
68
|
+
unless object.is_a?(Ecoportal::API::V2::Page) or object.is_a?(Ecoportal::API::V2::Pages::PageStage)
|
|
69
|
+
raise "Queuing is just for entries. Expecting Page or PageStage. Given: #{object.class}"
|
|
70
|
+
end
|
|
71
|
+
if elem = queue_get(object.id)
|
|
72
|
+
msg = "Something is wrong. Native case 'RegisterUpdateCase' is "
|
|
73
|
+
if (elem != object) && dirty?(elem)
|
|
74
|
+
msg << "trying to queue different objects with same page id:\n"
|
|
75
|
+
msg << " • already queued (changes will go): #{object_reference(elem)}\n"
|
|
76
|
+
msg << " • tried to queue (lost changes): #{object_reference(object)}"
|
|
77
|
+
logger.warn msg
|
|
78
|
+
end
|
|
79
|
+
else
|
|
80
|
+
batch_queue << object unless batch_queue.include?(object)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def queue_shift(id = nil)
|
|
85
|
+
if id
|
|
86
|
+
batch_queue.delete(queue_get(id))
|
|
87
|
+
else
|
|
88
|
+
batch_queue.shift
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def queue_get(id)
|
|
93
|
+
batch_queue.find {|e| e.id == id}
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def batch_queue
|
|
97
|
+
@batch_queue ||= []
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def batched_search_results
|
|
101
|
+
raise "Missing block. It yields in slices of #{self.class.batch_size} results" unless block_given?
|
|
102
|
+
results_preview
|
|
103
|
+
results = []
|
|
104
|
+
apiv2.registers.search(register_id, search_options) do |page_result|
|
|
105
|
+
results << page_result
|
|
106
|
+
if results.length >= self.class.batch_size
|
|
107
|
+
yield(results)
|
|
108
|
+
results = []
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
yield(results) unless results.empty?
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def update_oozes(batched_oozes = batch_queue)
|
|
115
|
+
batched_oozes.each do |ooze|
|
|
116
|
+
update_ooze(ooze)
|
|
117
|
+
end
|
|
118
|
+
batched_oozes.clear
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def backup_patch!(ooze = target)
|
|
122
|
+
unless patch = (patch_doc(ooze) || {})["page"]
|
|
123
|
+
logger.info "No changes to update for #{object_reference(ooze)}."
|
|
124
|
+
return
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def results_preview
|
|
129
|
+
apiv2.registers.search(register_id, search_options.merge(only_first: true)).tap do |search_results|
|
|
130
|
+
str_results = "Total target entries: #{search_results.total} (out of #{search_results.total_before_filtering})"
|
|
131
|
+
session.prompt_user("Do you want to proceed (y/N):", explanation: str_results, default: "N", timeout: 10) do |res|
|
|
132
|
+
if res.upcase.start_with?("N")
|
|
133
|
+
puts "..."
|
|
134
|
+
logger.info "Aborting script..."
|
|
135
|
+
exit(0)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def search_options
|
|
142
|
+
@search_options ||= {}.tap do |opts|
|
|
143
|
+
opts.merge!(sort: "created_at")
|
|
144
|
+
opts.merge!(dir: "asc")
|
|
145
|
+
opts.merge!(query: conf_filters) if conf_search
|
|
146
|
+
opts.merge!(filters: conf_filters)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def conf_filters
|
|
151
|
+
return filters if self.respond_to?(:filters)
|
|
152
|
+
[]
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def conf_search
|
|
156
|
+
return search if self.respond_to?(:search)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def register_id
|
|
160
|
+
options.dig(:source, :register_id)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
end
|
|
@@ -9,6 +9,8 @@ module Eco
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
require_relative 'ooze_samples/helpers'
|
|
12
|
+
require_relative 'ooze_samples/ooze_base_case'
|
|
12
13
|
require_relative 'ooze_samples/ooze_run_base_case'
|
|
13
14
|
require_relative 'ooze_samples/ooze_update_case'
|
|
14
15
|
require_relative 'ooze_samples/ooze_from_doc_case'
|
|
16
|
+
require_relative 'ooze_samples/register_update_case'
|
data/lib/eco/version.rb
CHANGED
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: 2.0.
|
|
4
|
+
version: 2.0.37
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Oscar Segura
|
|
@@ -136,7 +136,7 @@ dependencies:
|
|
|
136
136
|
requirements:
|
|
137
137
|
- - ">="
|
|
138
138
|
- !ruby/object:Gem::Version
|
|
139
|
-
version: 0.8.
|
|
139
|
+
version: 0.8.13
|
|
140
140
|
- - "<"
|
|
141
141
|
- !ruby/object:Gem::Version
|
|
142
142
|
version: '0.9'
|
|
@@ -146,7 +146,7 @@ dependencies:
|
|
|
146
146
|
requirements:
|
|
147
147
|
- - ">="
|
|
148
148
|
- !ruby/object:Gem::Version
|
|
149
|
-
version: 0.8.
|
|
149
|
+
version: 0.8.13
|
|
150
150
|
- - "<"
|
|
151
151
|
- !ruby/object:Gem::Version
|
|
152
152
|
version: '0.9'
|
|
@@ -559,9 +559,11 @@ files:
|
|
|
559
559
|
- lib/eco/api/usecases/ooze_samples.rb
|
|
560
560
|
- lib/eco/api/usecases/ooze_samples/helpers.rb
|
|
561
561
|
- lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb
|
|
562
|
+
- lib/eco/api/usecases/ooze_samples/ooze_base_case.rb
|
|
562
563
|
- lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
|
|
563
564
|
- lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb
|
|
564
565
|
- lib/eco/api/usecases/ooze_samples/ooze_update_case.rb
|
|
566
|
+
- lib/eco/api/usecases/ooze_samples/register_update_case.rb
|
|
565
567
|
- lib/eco/api/usecases/use_case.rb
|
|
566
568
|
- lib/eco/api/usecases/use_case_chain.rb
|
|
567
569
|
- lib/eco/api/usecases/use_case_io.rb
|