connectors_utility 8.6.0.4.pre.20221114T233920Z → 8.6.0.4.pre.20221114T235434Z

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37c7557fa83583533bb2259248ab405166619dce6ba8c89667c4377ff0e9f4a2
4
- data.tar.gz: 83e9e53681e78993213d11d4f100bbc93a788c85dc559423df108cc26a8807bc
3
+ metadata.gz: 5925861ca9c2d09d5a4b27cbb1262e7dee74420815b0df1988d97b5f1c4cbb3b
4
+ data.tar.gz: 06bc7686285b134ac9198bb8ad3579b759fda60d2e4962e1fe4fc730828a8428
5
5
  SHA512:
6
- metadata.gz: 1dcde38d997b4bf23fe9bbcc6b90ac0d2617b8bd70692db21178e8ae7ceaf38406242c0a782a78a64d9822e3fa3e01a41f217bd1c39e6e2be0b6c10629775bac
7
- data.tar.gz: ad902aa4782a28c8630192376c8873cb8e2fd9df2b10e72d2e6598b8e544a896f7b0e00b9e5fa4e14a20d718e45b50c8c8213f8d1f0bac5b02fc7d2d3a149c8c
6
+ metadata.gz: ffb17fd4a35bbecacddc59b018b20b3d24ef1581e5ca6b182dc73aa42100da4976fbb0d2e2e2504767769a0ea259e3091c877e5ac8ad58683cd1a45022215a0b
7
+ data.tar.gz: ce59bc3313006d3324d62c572cf9c743028cab4d052ea985a7ca183bf3bd9f55ad5edd6bf93fabd4eb54f2614226c1d8ed195a236d6916cb16682575c902b099
@@ -0,0 +1,85 @@
1
+ #
2
+ # Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ # or more contributor license agreements. Licensed under the Elastic License;
4
+ # you may not use this file except in compliance with the Elastic License.
5
+ #
6
+
7
+ require 'json'
8
+
9
+ module Utility
10
+ class BulkQueue
11
+ class QueueOverflowError < StandardError; end
12
+
13
+ # 500 items or 5MB
14
+ def initialize(operation_count_threshold = 500, size_threshold = 5 * 1024 * 1024)
15
+ @operation_count_threshold = operation_count_threshold.freeze
16
+ @size_threshold = size_threshold.freeze
17
+
18
+ @buffer = ''
19
+
20
+ @current_operation_count = 0
21
+
22
+ @current_buffer_size = 0
23
+ @current_data_size = 0
24
+ end
25
+
26
+ def pop_all
27
+ result = @buffer
28
+
29
+ reset
30
+
31
+ result
32
+ end
33
+
34
+ def add(operation, payload = nil)
35
+ raise QueueOverflowError unless will_fit?(operation, payload)
36
+
37
+ operation_size = get_size(operation)
38
+ payload_size = get_size(payload)
39
+
40
+ @current_operation_count += 1
41
+ @current_buffer_size += operation_size
42
+ @current_buffer_size += payload_size
43
+ @current_data_size += payload_size
44
+
45
+ @buffer << operation
46
+ @buffer << "\n"
47
+
48
+ if payload
49
+ @buffer << payload
50
+ @buffer << "\n"
51
+ end
52
+ end
53
+
54
+ def will_fit?(operation, payload = nil)
55
+ return false if @current_operation_count + 1 > @operation_count_threshold
56
+
57
+ operation_size = get_size(operation)
58
+ payload_size = get_size(payload)
59
+
60
+ @current_buffer_size + operation_size + payload_size < @size_threshold
61
+ end
62
+
63
+ def current_stats
64
+ {
65
+ :current_operation_count => @current_operation_count,
66
+ :current_buffer_size => @current_buffer_size
67
+ }
68
+ end
69
+
70
+ private
71
+
72
+ def get_size(str)
73
+ return 0 unless str
74
+ str.bytesize
75
+ end
76
+
77
+ def reset
78
+ @current_operation_count = 0
79
+ @current_buffer_size = 0
80
+ @current_data_size = 0
81
+
82
+ @buffer = ''
83
+ end
84
+ end
85
+ end
@@ -4,7 +4,6 @@
4
4
  # you may not use this file except in compliance with the Elastic License.
5
5
  #
6
6
 
7
- require 'config'
8
7
  require 'logger'
9
8
  require 'active_support/core_ext/module'
10
9
  require 'active_support/core_ext/string/filters'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: connectors_utility
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.6.0.4.pre.20221114T233920Z
4
+ version: 8.6.0.4.pre.20221114T235434Z
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
@@ -110,6 +110,7 @@ files:
110
110
  - lib/core/elastic_connector_actions.rb
111
111
  - lib/core/scheduler.rb
112
112
  - lib/utility.rb
113
+ - lib/utility/bulk_queue.rb
113
114
  - lib/utility/common.rb
114
115
  - lib/utility/constants.rb
115
116
  - lib/utility/cron.rb