Class: Bas::SharedStorage::Postgres
- Inherits:
-
Base
- Object
- Base
- Bas::SharedStorage::Postgres
show all
- Defined in:
- lib/bas/shared_storage/postgres.rb
Overview
The SharedStorage::Postgres class serves as a shared storage implementation to read and write on a shared storage defined as a postgres database
Constant Summary
collapse
- TABLE_PARAMS =
"data, tag, archived, stage, status, error_message, version"
Instance Attribute Summary
Attributes inherited from Base
#read_options, #read_response, #write_options, #write_response
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#close_connections ⇒ Object
34
35
36
37
38
39
|
# File 'lib/bas/shared_storage/postgres.rb', line 34
def close_connections
@read_connection&.finish
@write_connection&.finish
@read_connection = nil
@write_connection = nil
end
|
#read ⇒ Object
19
20
21
22
23
24
25
26
|
# File 'lib/bas/shared_storage/postgres.rb', line 19
def read
establish_connection(:read)
first_result = @read_connection.query(read_query).first || {}
@read_response = Bas::SharedStorage::Types::Read.new(first_result[:id], first_result[:data],
first_result[:inserted_at])
end
|
#set_in_process ⇒ Object
41
42
43
44
45
|
# File 'lib/bas/shared_storage/postgres.rb', line 41
def set_in_process
return if read_options[:avoid_process].eql?(true) || read_response.id.nil?
update_stage(read_response.id, "in process")
end
|
#set_processed ⇒ Object
47
48
49
50
51
|
# File 'lib/bas/shared_storage/postgres.rb', line 47
def set_processed
return if read_options[:avoid_process].eql?(true) || read_response.id.nil?
update_stage(read_response.id, "processed") unless @read_response.nil?
end
|
#write(data) ⇒ Object
28
29
30
31
32
|
# File 'lib/bas/shared_storage/postgres.rb', line 28
def write(data)
establish_connection(:write)
@write_response = @write_connection.query(write_query(data))
end
|