Class: Bas::SharedStorage::Postgres

Inherits:
Base
  • Object
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

Constructor Details

This class inherits a constructor from Bas::SharedStorage::Base

Instance Method Details

#readObject

[View source]

19
20
21
22
23
24
25
26
# File 'lib/bas/shared_storage/postgres.rb', line 19

def read
  params = { connection: read_options[:connection], query: read_query }

  first_result = Utils::Postgres::Request.execute(params).first || {}

  @read_response = Bas::SharedStorage::Types::Read.new(first_result[:id], first_result[:data],
                                                       first_result[:inserted_at])
end

#set_in_processObject

[View source]

33
34
35
36
37
# File 'lib/bas/shared_storage/postgres.rb', line 33

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_processedObject

[View source]

39
40
41
42
43
# File 'lib/bas/shared_storage/postgres.rb', line 39

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

[View source]

28
29
30
31
# File 'lib/bas/shared_storage/postgres.rb', line 28

def write(data)
  params = { connection: write_options[:connection], query: write_query(data) }
  @write_response = Utils::Postgres::Request.execute(params)
end