getaround_utils 0.1.19 → 0.1.20
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/Gemfile.lock +1 -1
- data/lib/getaround_utils/utils.rb +1 -0
- data/lib/getaround_utils/utils/async_queue.rb +33 -43
- data/lib/getaround_utils/utils/captur_reporter.rb +32 -0
- data/lib/getaround_utils/utils/deep_key_value.rb +16 -15
- data/lib/getaround_utils/utils/http_reporter.rb +5 -23
- data/lib/getaround_utils/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac89bb57e946209df2cd90a27662dd6eafe09eaf1ad75c70e0120843600eaa73
|
4
|
+
data.tar.gz: b5e42696a498a174113437cf8350b1eb742391f74588621a3bae00e12cab7fc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20debe44bc0c094ce9dcc3cde822eb7565c6c399cc4ba5849c2a6c5bbc249c9fa96e8fda50648c9974c03b1177030b3880aab5df65c3eba6ea9632845e796d69
|
7
|
+
data.tar.gz: 3017542f9d2b157a8f6ee9637c5659212a3fa3ad8803975ac2fd8b76e255487183e7b671944a6ec8a9b841890917dfb0c3ae7f3973eba0966257d7a9089c0161
|
data/Gemfile.lock
CHANGED
@@ -2,4 +2,5 @@ module GetaroundUtils::Utils
|
|
2
2
|
autoload :AsyncQueue, 'getaround_utils/utils/async_queue'
|
3
3
|
autoload :DeepKeyValue, 'getaround_utils/utils/deep_key_value'
|
4
4
|
autoload :HttpReporter, 'getaround_utils/utils/http_reporter'
|
5
|
+
autoload :CapturReporter, 'getaround_utils/utils/captur_reporter'
|
5
6
|
end
|
@@ -2,58 +2,48 @@ module GetaroundUtils; end
|
|
2
2
|
module GetaroundUtils::Utils; end
|
3
3
|
|
4
4
|
class GetaroundUtils::Utils::AsyncQueue
|
5
|
-
|
6
|
-
include GetaroundUtils::Mixins::Loggable
|
5
|
+
include GetaroundUtils::Mixins::Loggable
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
MAX_QUEUE_SIZE = 1000
|
8
|
+
BUFFER_SIZE = 50
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def initialize
|
11
|
+
@queue = []
|
12
|
+
@mutex = Mutex.new
|
13
|
+
@closed = false
|
14
|
+
@worker = Thread.new(&method(:thread_run))
|
15
|
+
at_exit { terminate }
|
16
|
+
end
|
14
17
|
|
15
|
-
|
16
|
-
|
18
|
+
def perform
|
19
|
+
raise NotImplementedError
|
20
|
+
end
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
def push(payload)
|
23
|
+
@mutex.synchronize do
|
24
|
+
if @queue.size >= MAX_QUEUE_SIZE
|
25
|
+
loggable_log(:error, 'queue overflow')
|
26
|
+
else
|
27
|
+
@queue.push(payload)
|
21
28
|
end
|
22
|
-
|
23
|
-
@queue.push(args)
|
24
29
|
end
|
30
|
+
end
|
25
31
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
@queue = Queue.new
|
32
|
-
|
33
|
-
@worker = Thread.new do
|
34
|
-
while args = @queue.pop
|
35
|
-
begin
|
36
|
-
perform(*args)
|
37
|
-
rescue ClosedQueueError
|
38
|
-
nil
|
39
|
-
rescue StandardError => e
|
40
|
-
loggable('error', e.message, class: e.class.to_s, backtrace: e.backtrace)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
at_exit { terminate }
|
46
|
-
end
|
47
|
-
end
|
32
|
+
def thread_run
|
33
|
+
loop do
|
34
|
+
buffer = @mutex.synchronize { @queue.shift(BUFFER_SIZE) }
|
35
|
+
loggable_log(:debug, 'thread_run', buffer_size: buffer.size)
|
36
|
+
return if @closed && buffer.empty?
|
48
37
|
|
49
|
-
|
50
|
-
@queue
|
51
|
-
|
38
|
+
perform(buffer) unless buffer.empty?
|
39
|
+
sleep(1) unless @mutex.synchronize { @queue.any? }
|
40
|
+
rescue StandardError => e
|
41
|
+
loggable_log(:error, e.message, class: e.class.to_s, backtrace: e.backtrace)
|
52
42
|
end
|
43
|
+
end
|
53
44
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
45
|
+
def terminate
|
46
|
+
@mutex.synchronize { @closed = true }
|
47
|
+
@worker&.join
|
58
48
|
end
|
59
49
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'faraday'
|
3
|
+
require 'getaround_utils/utils/async_queue'
|
4
|
+
|
5
|
+
class GetaroundUtils::Utils::CapturReporter < GetaroundUtils::Utils::AsyncQueue
|
6
|
+
CAPTUR_URL = ENV['CAPTUR_URL']
|
7
|
+
|
8
|
+
def perform(events)
|
9
|
+
return unless CAPTUR_URL&.match('^https?://')
|
10
|
+
|
11
|
+
Faraday.post(CAPTUR_URL) do |req|
|
12
|
+
req.options[:open_timeout] = 1
|
13
|
+
req.options[:timeout] = 1
|
14
|
+
req.headers = { 'Content-Type': 'application/json' }
|
15
|
+
req.body = JSON.generate(events: events, metas: metas)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def metas
|
20
|
+
{}
|
21
|
+
end
|
22
|
+
|
23
|
+
def push(uuid:, type:, anonymous_id:, timestamp: nil, attributes: {})
|
24
|
+
super(
|
25
|
+
uuid: uuid,
|
26
|
+
type: type,
|
27
|
+
timestamp: timestamp || Time.now.iso8601,
|
28
|
+
anonymous_id: anonymous_id,
|
29
|
+
attributes: attributes,
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
@@ -2,47 +2,48 @@ module GetaroundUtils; end
|
|
2
2
|
module GetaroundUtils::Utils; end
|
3
3
|
|
4
4
|
module GetaroundUtils::Utils::DeepKeyValue
|
5
|
+
def self.escape(value, max_length = 512)
|
6
|
+
value = value[1...-1] if value =~ /^".*"$/
|
7
|
+
value = "#{value[0...max_length]} ..." if value.length >= max_length
|
8
|
+
value.inspect
|
9
|
+
end
|
10
|
+
|
5
11
|
def self.serialize(data)
|
6
12
|
case data
|
7
13
|
when Array
|
8
|
-
flattify(data).map { |key, value| "#{key}=#{value}" }.join(' ')
|
14
|
+
flattify(data).map { |key, value| "#{key}=#{serialize(value)}" }.join(' ')
|
9
15
|
when Hash
|
10
|
-
flattify(data).map { |key, value| "#{key}=#{value}" }.join(' ')
|
16
|
+
flattify(data).map { |key, value| "#{key}=#{serialize(value)}" }.join(' ')
|
11
17
|
when Numeric
|
12
18
|
data.to_s
|
13
19
|
when String
|
14
|
-
data
|
20
|
+
escape(data)
|
15
21
|
else
|
16
|
-
data.to_s
|
22
|
+
escape(data.to_s)
|
17
23
|
end
|
18
24
|
end
|
19
25
|
|
20
26
|
# https://stackoverflow.com/questions/48836464/how-to-flatten-a-hash-making-each-key-a-unique-value
|
21
|
-
def self.flattify(value, result = {}, path = [],
|
27
|
+
def self.flattify(value, result = {}, path = [], max_depth = 5)
|
22
28
|
if path.length > max_depth
|
23
|
-
result[path.join(".")] = '
|
29
|
+
result[path.join(".")] = '...'
|
24
30
|
return result
|
25
31
|
end
|
26
32
|
case value
|
27
33
|
when Array
|
28
34
|
value.each.with_index(0) do |v, i|
|
29
|
-
flattify(v, result, path + [i],
|
35
|
+
flattify(v, result, path + [i], max_depth)
|
30
36
|
end
|
31
37
|
when Hash
|
32
38
|
value.each do |k, v|
|
33
|
-
flattify(v, result, path + [k],
|
39
|
+
flattify(v, result, path + [k], max_depth)
|
34
40
|
end
|
35
41
|
when Numeric
|
36
|
-
result[path.join(".")] = value
|
42
|
+
result[path.join(".")] = value
|
37
43
|
when String
|
38
|
-
value = if value =~ /^".*"$/
|
39
|
-
value.length >= max_length ? %{#{value[0...max_length]} ..."} : value
|
40
|
-
else
|
41
|
-
value.length >= max_length ? %{#{value[0...max_length]} ...}.inspect : value.inspect
|
42
|
-
end
|
43
44
|
result[path.join(".")] = value
|
44
45
|
else
|
45
|
-
flattify(value.to_s, result, path,
|
46
|
+
flattify(value.to_s, result, path, max_depth)
|
46
47
|
end
|
47
48
|
result
|
48
49
|
end
|
@@ -1,29 +1,11 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'faraday'
|
3
|
-
require 'getaround_utils/utils/async_queue'
|
4
|
-
|
5
1
|
class GetaroundUtils::Utils::HttpReporter
|
6
|
-
|
7
|
-
def self.perform(url:, params: {}, headers: {}, body: nil)
|
8
|
-
Faraday.post(url) do |req|
|
9
|
-
req.options[:open_timeout] = 1
|
10
|
-
req.options[:timeout] = 1
|
11
|
-
req.params = params
|
12
|
-
req.headers = headers
|
13
|
-
req.body = body
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
2
|
+
include GetaroundUtils::Mixins::Loggable
|
17
3
|
|
18
|
-
def initialize(
|
19
|
-
|
4
|
+
def initialize(_)
|
5
|
+
loggable_log(:warn, 'use of deprecated class')
|
20
6
|
end
|
21
7
|
|
22
|
-
def report(
|
23
|
-
|
24
|
-
url: @url,
|
25
|
-
headers: { 'Content-Type' => 'application/json' },
|
26
|
-
body: JSON.generate(event)
|
27
|
-
)
|
8
|
+
def report(_)
|
9
|
+
loggable_log(:warn, 'use of deprecated class')
|
28
10
|
end
|
29
11
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: getaround_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Drivy
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-02-
|
12
|
+
date: 2020-02-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -213,6 +213,7 @@ files:
|
|
213
213
|
- lib/getaround_utils/railties/lograge.rb
|
214
214
|
- lib/getaround_utils/utils.rb
|
215
215
|
- lib/getaround_utils/utils/async_queue.rb
|
216
|
+
- lib/getaround_utils/utils/captur_reporter.rb
|
216
217
|
- lib/getaround_utils/utils/deep_key_value.rb
|
217
218
|
- lib/getaround_utils/utils/http_reporter.rb
|
218
219
|
- lib/getaround_utils/version.rb
|