ecoportal-api 0.10.2 → 0.10.4

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.
@@ -46,6 +46,5 @@ module Ecoportal
46
46
  end
47
47
  end
48
48
 
49
- require 'ecoportal/api/v1/job_status'
50
49
  require 'ecoportal/api/v1/person_schemas'
51
50
  require 'ecoportal/api/v1/people'
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- VERSION = '0.10.2'.freeze
3
+ VERSION = '0.10.4'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecoportal-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
4
+ version: 0.10.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tapio Saarinen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-27 00:00:00.000000000 Z
11
+ date: 2024-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -180,6 +180,20 @@ dependencies:
180
180
  - - "<"
181
181
  - !ruby/object:Gem::Version
182
182
  version: '6'
183
+ - !ruby/object:Gem::Dependency
184
+ name: rate_throttle_client
185
+ requirement: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - "~>"
188
+ - !ruby/object:Gem::Version
189
+ version: '0.1'
190
+ type: :runtime
191
+ prerelease: false
192
+ version_requirements: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - "~>"
195
+ - !ruby/object:Gem::Version
196
+ version: '0.1'
183
197
  description:
184
198
  email:
185
199
  - tapio@ecoportal.co.nz
@@ -209,12 +223,18 @@ files:
209
223
  - lib/ecoportal/api/common/batch_operation.rb
210
224
  - lib/ecoportal/api/common/batch_response.rb
211
225
  - lib/ecoportal/api/common/client.rb
226
+ - lib/ecoportal/api/common/client/elastic_apm_integration.rb
227
+ - lib/ecoportal/api/common/client/error.rb
228
+ - lib/ecoportal/api/common/client/error/checks.rb
229
+ - lib/ecoportal/api/common/client/rate_throttling.rb
230
+ - lib/ecoportal/api/common/client/throughput.rb
231
+ - lib/ecoportal/api/common/client/throughput/stats.rb
232
+ - lib/ecoportal/api/common/client/time_out.rb
233
+ - lib/ecoportal/api/common/client/with_retry.rb
212
234
  - lib/ecoportal/api/common/doc_helpers.rb
213
- - lib/ecoportal/api/common/elastic_apm_integration.rb
214
235
  - lib/ecoportal/api/common/hash_diff.rb
215
236
  - lib/ecoportal/api/common/logging.rb
216
237
  - lib/ecoportal/api/common/response.rb
217
- - lib/ecoportal/api/common/time_out.rb
218
238
  - lib/ecoportal/api/common/wrapped_response.rb
219
239
  - lib/ecoportal/api/errors.rb
220
240
  - lib/ecoportal/api/errors/base.rb
@@ -236,7 +256,9 @@ files:
236
256
  - lib/ecoportal/api/internal/schema_field_value.rb
237
257
  - lib/ecoportal/api/logger.rb
238
258
  - lib/ecoportal/api/v1.rb
239
- - lib/ecoportal/api/v1/job_status.rb
259
+ - lib/ecoportal/api/v1/job.rb
260
+ - lib/ecoportal/api/v1/job/awaiter.rb
261
+ - lib/ecoportal/api/v1/job/status.rb
240
262
  - lib/ecoportal/api/v1/people.rb
241
263
  - lib/ecoportal/api/v1/person.rb
242
264
  - lib/ecoportal/api/v1/person_details.rb
@@ -1,112 +0,0 @@
1
- require 'elastic-apm'
2
- module Ecoportal
3
- module API
4
- module Common
5
- module ElasticApmIntegration
6
-
7
- class UnexpectedServerError < StandardError
8
- def initialize(code, msg)
9
- super("Code: #{code} -- Error: #{msg}")
10
- end
11
- end
12
-
13
- APM_SERVICE_NAME = 'ecoportal-api-gem'
14
-
15
- # Log only errors that are only server's responsibility
16
- def log_unexpected_server_error(response)
17
- raise "Expecting Ecoportal::API::Common::Response. Given: #{response.class}" unless response.is_a?(Common::Response)
18
- return nil unless elastic_apm_service
19
- return nil unless unexpected_server_error?(response.status)
20
- if ElasticAPM.running?
21
- ElasticAPM.report(UnexpectedServerError.new(response.status, response.body))
22
- end
23
- end
24
-
25
- private
26
-
27
- def unexpected_server_error?(code)
28
- !code || ((code >= 500) && (code <= 599)) || (code <= 99)
29
- end
30
-
31
- # finalizer to stop the agent
32
- close_elastic_apm = Proc.new do |id|
33
- begin
34
- if ElasticAPM.running?
35
- puts "Stopping ElasticAPM service"
36
- ElasticAPM.stop
37
- end
38
- rescue StandardError => e
39
- # Silent
40
- end
41
- end
42
- ObjectSpace.define_finalizer("ElasticAPM", close_elastic_apm)
43
-
44
- def elastic_apm_service
45
- return false if @disable_apm
46
- begin
47
- ElasticAPM.start(**elastic_apm_options) unless ElasticAPM.running?
48
- rescue StandardError => e
49
- @disable_apm = true
50
- puts "ElasticAPM services not available: #{e}"
51
- end
52
- end
53
-
54
- def elastic_apm_options
55
- {
56
- service_name: APM_SERVICE_NAME,
57
- server_url: elastic_apm_url,
58
- secret_token: elastic_apm_key,
59
- environment: environment,
60
- #http_compression: false,
61
- transaction_sample_rate: 0.1,
62
- transaction_max_spans: 100,
63
- span_frames_min_duration: "5ms"
64
- }.tap do |options|
65
- options.merge!({
66
- log_level: Logger::DEBUG,
67
- log_path: File.join(__dir__, "elastic_apm.log")
68
- }) if false
69
- end
70
- end
71
-
72
- def elastic_apm_url
73
- @elastic_apm_url ||= "https://".tap do |url|
74
- url << "#{elastic_apm_account_id}"
75
- url << ".#{elastic_apm_base_url}"
76
- url << ":#{elastic_apm_port}"
77
- end
78
- end
79
-
80
- def elastic_apm_key
81
- @elastic_apm_key ||= ENV['ELASTIC_APM_KEY']
82
- end
83
-
84
- def elastic_apm_account_id
85
- @elastic_apm_account_id ||= ENV['ELASTIC_APM_ACCOUNT_ID']
86
- end
87
-
88
- def elastic_apm_base_url
89
- @elastic_apm_base_url ||= "apm.#{elastic_apm_region}.aws.cloud.es.io"
90
- end
91
-
92
- def elastic_apm_region
93
- @elastic_apm_region ||= ENV['ELASTIC_APM_REGION'] || "ap-southeast-2"
94
- end
95
-
96
-
97
- def elastic_apm_port
98
- @elastic_apm_port ||= ENV['ELASTIC_APM_PORT'] || "443"
99
- end
100
-
101
- def environment
102
- @environment ||= "unknown".tap do |value|
103
- if instance_variable_defined?(:@host) && env = @host.gsub(".ecoportal.com", '')
104
- value.clear << env
105
- end
106
- end
107
- end
108
-
109
- end
110
- end
111
- end
112
- end
@@ -1,26 +0,0 @@
1
- module Ecoportal
2
- module API
3
- module Common
4
- module TimeOut
5
- MIN_THROUGHPUT = 0.2 # people per second
6
- MIN_SIZE = 10
7
-
8
- private
9
-
10
- def min_throughput
11
- self.class::MIN_THROUGHPUT
12
- end
13
-
14
- def min_size
15
- self.class::MIN_SIZE
16
- end
17
-
18
- def timeout_for(count)
19
- count = 1 unless count&.positive?
20
- count = min_size if count < min_size
21
- (count.ceil / min_throughput).ceil
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,33 +0,0 @@
1
- module Ecoportal
2
- module API
3
- class V1
4
- class JobStatus
5
- attr_reader :id, :progress
6
-
7
- def initialize(id, complete, errored, progress)
8
- @id = id
9
- @complete = complete
10
- @errored = errored
11
- @progress = progress
12
- end
13
-
14
- def complete?(total = nil)
15
- return @complete if total.nil?
16
-
17
- progress >= total
18
- end
19
-
20
- def errored?
21
- @errored
22
- end
23
-
24
- def to_s
25
- msg = complete? ? "Completed" : "In progress"
26
- msg = "Errored" if errored?
27
- msg << " with #{progress} done."
28
- msg
29
- end
30
- end
31
- end
32
- end
33
- end