Class: Utility::BulkQueue
- Inherits:
-
Object
- Object
- Utility::BulkQueue
show all
- Defined in:
- lib/utility/bulk_queue.rb
Defined Under Namespace
Classes: QueueOverflowError
Instance Method Summary
collapse
Constructor Details
#initialize(operation_count_threshold = Utility::Constants::DEFAULT_MAX_INGESTION_QUEUE_SIZE, size_threshold = Utility::Constants::DEFAULT_MAX_INGESTION_QUEUE_BYTES) ⇒ BulkQueue
Instance Method Details
#add(operation, payload = nil) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/utility/bulk_queue.rb', line 36
def add(operation, payload = nil)
raise QueueOverflowError unless will_fit?(operation, payload)
operation_size = get_size(operation)
payload_size = get_size(payload)
@current_operation_count += 1
@current_buffer_size += operation_size
@current_buffer_size += payload_size
@current_data_size += payload_size
@buffer << operation
@buffer << "\n"
if payload
@buffer << payload
@buffer << "\n"
end
end
|
#current_stats ⇒ Object
65
66
67
68
69
70
|
# File 'lib/utility/bulk_queue.rb', line 65
def current_stats
{
:current_operation_count => @current_operation_count,
:current_buffer_size => @current_buffer_size
}
end
|
#pop_all ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/utility/bulk_queue.rb', line 28
def pop_all
result = @buffer
reset
result
end
|
#will_fit?(operation, payload = nil) ⇒ Boolean
56
57
58
59
60
61
62
63
|
# File 'lib/utility/bulk_queue.rb', line 56
def will_fit?(operation, payload = nil)
return false if @current_operation_count + 1 > @operation_count_threshold
operation_size = get_size(operation)
payload_size = get_size(payload)
@current_buffer_size + operation_size + payload_size < @size_threshold
end
|