eco-helpers 2.0.34 → 2.0.35
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -3
- data/eco-helpers.gemspec +1 -1
- data/lib/eco/api/usecases/ooze_samples/helpers/shortcuts.rb +5 -5
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +23 -6
- data/lib/eco/api/usecases/ooze_samples/register_update_case.rb +71 -15
- data/lib/eco/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4d6a312dda42afc3e6ba2becccf69d42121024d9b81e2c37276719089521971
|
4
|
+
data.tar.gz: a3536e8fba79c1600135b4c4fd523a9c3a5262d605c39c751a3dc278d096b96e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fcb26823bc3b6e3d35522c13d410094ea056269c14dea3b47bcaf16991ff36cde9537507a6a21c952aa15f590fb1f5b1fc594e55d08f04782a8e2802c695d0c
|
7
|
+
data.tar.gz: fb2768c6e345da3dec034e7793876ecf25ae1cff76a059d98a38d9328c57884efb2a2f0b449eb28aea686ba074e477875fd8ba30201773170935f1c766fd45ae
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,27 @@
|
|
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.35] - 2021-08-30
|
5
|
+
|
6
|
+
### Added
|
7
|
+
- `Eco::API::UseCases::OozeSamples::OozeBaseCase`
|
8
|
+
- `#new_target` optional warning when switching `target`
|
9
|
+
- `block` that is called when switching target and there were unsaved changes
|
10
|
+
- `#dirty?` helper method to check if there are changes
|
11
|
+
- `#before_loading_new_target` hook to allow child classes to anticipate when the `target` is going to change
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
- `Eco::API::UseCases::OozeSamples::Helpers::Shortcuts#object_reference` improved reference text
|
15
|
+
- `Eco::API::UseCases::OozeSamples::RegisterUpdateCase`
|
16
|
+
- added resilience when switching target (i.e. from one stage to another stage in same entry)
|
17
|
+
- added `batch_queue`
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
- `Eco::API::UseCases::OozeSamples::RegisterUpdateCase`
|
21
|
+
- actual `batch_size` updates
|
22
|
+
- actual safe switch of target (i.e. against another stage of same ooze)
|
23
|
+
|
24
|
+
## [2.0.34] - 2021-08-28
|
5
25
|
|
6
26
|
### Added
|
7
27
|
- `Eco::API::UseCases::OozeSamples::OozeBaseCase` refactored ooze base case
|
@@ -12,8 +32,6 @@ All notable changes to this project will be documented in this file.
|
|
12
32
|
- `Eco::API::UseCases::OozeSamples::OozeUpdateCase` remove unnecessary code and helpers that are now inherited from `OoozeBaseCase`
|
13
33
|
- `Eco::API::UseCases::OozeSamples::OozeFromDocCase` remove unnecessary code
|
14
34
|
|
15
|
-
### Fixed
|
16
|
-
|
17
35
|
|
18
36
|
## [2.0.33] - 2021-08-16
|
19
37
|
|
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.12', '< 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'
|
@@ -59,16 +59,16 @@ module Eco
|
|
59
59
|
"".tap do |ref|
|
60
60
|
case obj
|
61
61
|
when Ecoportal::API::V2::Page::Stage
|
62
|
-
ref << "Stage
|
62
|
+
ref << "Stage"
|
63
63
|
when Ecoportal::API::V2::Pages::PageStage
|
64
|
-
ref << "
|
64
|
+
ref << "Page (#{obj.id}) (#{object_reference(obj.current_stage)})"
|
65
65
|
when Ecoportal::API::V2::Page
|
66
|
-
ref << "Page
|
66
|
+
ref << "Page"
|
67
67
|
end
|
68
|
-
ref << "'#{obj.name}'
|
68
|
+
ref << " '#{obj.name}'" if obj.respond_to?(:name)
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -9,6 +9,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
|
|
9
9
|
attr_reader :target
|
10
10
|
|
11
11
|
SAVE_PATCH = "ooze_patch_update.json"
|
12
|
+
DRY_COUNT = 5
|
12
13
|
|
13
14
|
def main(session, options, usecase)
|
14
15
|
raise "You need to inherit from this class ('#{self.class}') and call super with a block" unless block_given?
|
@@ -26,8 +27,13 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
|
|
26
27
|
|
27
28
|
private
|
28
29
|
|
30
|
+
# Hook method to use before the target is switched
|
31
|
+
def before_loading_new_target(ooze_id)
|
32
|
+
end
|
33
|
+
|
29
34
|
def ooze(ooze_id = nil, stage_id: nil)
|
30
35
|
return target unless ooze_id
|
36
|
+
before_loading_new_target(ooze_id)
|
31
37
|
apiv2.pages.get(ooze_id, stage_id: stage_id).tap do |ooze|
|
32
38
|
if ooze
|
33
39
|
new_target(ooze)
|
@@ -47,6 +53,7 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
|
|
47
53
|
|
48
54
|
if stg = ooze.stages[id_name] || ooze.stages.get_by_name(id_name)
|
49
55
|
return ooze if ooze.respond_to?(:current_stage_id) && (ooze.current_stage_id == stg.id)
|
56
|
+
before_loading_new_target(ooze_id)
|
50
57
|
return apiv2.pages.get(ooze_id, stage_id: stg.id).tap do |stage|
|
51
58
|
if stage
|
52
59
|
new_target(stage)
|
@@ -61,12 +68,13 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
|
|
61
68
|
|
62
69
|
def update_ooze(ooze = target)
|
63
70
|
if !options[:simulate]
|
71
|
+
return unless dirty?(ooze)
|
64
72
|
apiv2.pages.update(ooze).tap do |response|
|
65
73
|
if response.success?
|
66
74
|
ooze.consolidate!
|
67
|
-
logger.info("Successful update of
|
75
|
+
logger.info("Successful update of #{object_reference(ooze)}")
|
68
76
|
else
|
69
|
-
logger.error("Could not update
|
77
|
+
logger.error("Could not update #{object_reference(ooze)} (created_at: #{ooze.created_at}: #{response.body}")
|
70
78
|
end
|
71
79
|
end
|
72
80
|
else
|
@@ -76,17 +84,26 @@ class Eco::API::UseCases::OozeSamples::OozeBaseCase < Eco::API::Common::Loaders:
|
|
76
84
|
end
|
77
85
|
end
|
78
86
|
backup_patch!(ooze)
|
79
|
-
exit(0) if dry_count >
|
87
|
+
exit(0) if dry_count > DRY_COUNT
|
80
88
|
end
|
81
89
|
end
|
82
90
|
|
83
|
-
def new_target(object)
|
84
|
-
if
|
85
|
-
|
91
|
+
def new_target(object, warn_pending_changes: true)
|
92
|
+
if dirty?(target)
|
93
|
+
if warn_pending_changes
|
94
|
+
msg = "You you are switching to a new target #{object_reference(object)}"
|
95
|
+
msg += " after doing unsaved changes to #{object_reference(target)}"
|
96
|
+
logger.warn msg
|
97
|
+
end
|
98
|
+
yield(target) if block_given?
|
86
99
|
end
|
87
100
|
@target = object
|
88
101
|
end
|
89
102
|
|
103
|
+
def dirty?(object)
|
104
|
+
object && patch_doc(object)["page"]
|
105
|
+
end
|
106
|
+
|
90
107
|
def backup_patch!(ooze = target)
|
91
108
|
unless patch = (patch_doc(ooze) || {})["page"]
|
92
109
|
logger.info "No changes to update for #{object_reference(ooze)}."
|
@@ -6,11 +6,11 @@
|
|
6
6
|
class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::OozeSamples::OozeBaseCase
|
7
7
|
|
8
8
|
class << self
|
9
|
-
attr_reader :batch_size
|
10
|
-
|
11
9
|
# @return [Integer] the number of pages to be processed in each batch
|
12
|
-
def batch_size
|
13
|
-
@batch_size
|
10
|
+
def batch_size(size = nil)
|
11
|
+
@batch_size ||= 25
|
12
|
+
return @batch_size unless size
|
13
|
+
@batch_size = size
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -31,39 +31,95 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
|
|
31
31
|
|
32
32
|
private
|
33
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
|
+
#queue(pending)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
34
47
|
def with_each_entry
|
35
48
|
batched_search_results do |page_results|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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)
|
40
60
|
end
|
41
|
-
ooze
|
42
61
|
end
|
43
|
-
update_oozes
|
62
|
+
update_oozes
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def enqueue(object)
|
67
|
+
return unless object && object.respond_to?(:id)
|
68
|
+
if elem = queue_get(object.id)
|
69
|
+
msg = "Something is wrong. Native case 'RegisterUpdateCase' is "
|
70
|
+
if (elem != object) && dirty?(elem)
|
71
|
+
msg << "trying to queue different objects with same page id:\n"
|
72
|
+
msg << " • already queued (changes will go): #{object_reference(elem)}\n"
|
73
|
+
msg << " • tried to queue (lost changes): #{object_reference(object)}"
|
74
|
+
logger.warn msg
|
75
|
+
end
|
76
|
+
else
|
77
|
+
batch_queue << object unless batch_queue.include?(object)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def queue_shift(id = nil)
|
82
|
+
if id
|
83
|
+
batch_queue.delete(queue_get(id))
|
84
|
+
else
|
85
|
+
batch_queue.shift
|
44
86
|
end
|
45
87
|
end
|
46
88
|
|
89
|
+
def queue_get(id)
|
90
|
+
batch_queue.find {|e| e.id == id}
|
91
|
+
end
|
92
|
+
|
93
|
+
def batch_queue
|
94
|
+
@batch_queue ||= []
|
95
|
+
end
|
96
|
+
|
47
97
|
def batched_search_results
|
48
98
|
raise "Missing block. It yields in slices of #{self.class.batch_size} results" unless block_given?
|
49
99
|
results_preview
|
50
|
-
|
100
|
+
results = []
|
51
101
|
apiv2.registers.search(register_id, search_options) do |page_result|
|
52
|
-
i += 1
|
53
102
|
results << page_result
|
54
|
-
if
|
103
|
+
if results.length >= self.class.batch_size
|
55
104
|
yield(results)
|
56
105
|
results = []
|
57
|
-
i = 0
|
58
106
|
end
|
59
107
|
end
|
60
108
|
yield(results) unless results.empty?
|
61
109
|
end
|
62
110
|
|
63
|
-
def update_oozes(batched_oozes)
|
111
|
+
def update_oozes(batched_oozes = batch_queue)
|
64
112
|
batched_oozes.each do |ooze|
|
65
113
|
update_ooze(ooze)
|
66
114
|
end
|
115
|
+
batched_oozes.clear
|
116
|
+
end
|
117
|
+
|
118
|
+
def backup_patch!(ooze = target)
|
119
|
+
unless patch = (patch_doc(ooze) || {})["page"]
|
120
|
+
logger.info "No changes to update for #{object_reference(ooze)}."
|
121
|
+
return
|
122
|
+
end
|
67
123
|
end
|
68
124
|
|
69
125
|
def results_preview
|
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.35
|
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.12
|
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.12
|
150
150
|
- - "<"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0.9'
|