bas 1.9.1 → 1.9.3
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/CHANGELOG.md +6 -0
- data/lib/bas/bot/base.rb +11 -1
- data/lib/bas/shared_storage/base.rb +2 -0
- data/lib/bas/shared_storage/postgres.rb +24 -7
- data/lib/bas/utils/postgres/connection.rb +42 -0
- data/lib/bas/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfa9acb9efb51fe26d268d6bc38799332b88993be0ee741ce23a227ba58ab7c5
|
4
|
+
data.tar.gz: d26a75cf2d382118c5a1e22c65800a25332fc87d887dbf6f017bd92985d80a14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bc1bbbcd20e52f09c45957f51ff3a28f760788c6ebca1fd2f90583a784b57ad0cad30057682cdeb16d0d297b1ed7064f7ccd6ec2c277c0eef996ef00f30748e
|
7
|
+
data.tar.gz: 2a7b07eab34fe4252174174f059108bd6d167f301cd49c15f56e99e6c7c1ec597b398ac1053db8102874a0120a2ff7e8075d8297d3c3ee323394c2c461f96d2c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
# 1.9.3 (23.07.2025)
|
4
|
+
- [Return write_response after on bot execution](https://github.com/kommitters/bas/pull/155)
|
5
|
+
|
6
|
+
# 1.9.2 (21.07.2025)
|
7
|
+
- [Refactor PostgreSQL connections](https://github.com/kommitters/bas/pull/153)
|
8
|
+
|
3
9
|
# 1.9.1 (15.07.2025)
|
4
10
|
- [refactor: Refactor client to meet the needs of the implementation to be performed](https://github.com/kommitters/bas/pull/149)
|
5
11
|
|
data/lib/bas/bot/base.rb
CHANGED
@@ -15,7 +15,8 @@ module Bas
|
|
15
15
|
attr_accessor :read_response, :process_response, :write_response
|
16
16
|
|
17
17
|
def initialize(options, shared_storage_reader, shared_storage_writer = nil)
|
18
|
-
|
18
|
+
default_options = { close_connections_after_process: true }
|
19
|
+
@process_options = default_options.merge(options || {})
|
19
20
|
@shared_storage_reader = shared_storage_reader
|
20
21
|
@shared_storage_writer = shared_storage_writer || shared_storage_reader
|
21
22
|
end
|
@@ -31,6 +32,10 @@ module Bas
|
|
31
32
|
@shared_storage_reader.set_processed
|
32
33
|
|
33
34
|
@write_response = write
|
35
|
+
|
36
|
+
close_connections if @process_options[:close_connections_after_process].eql?(true)
|
37
|
+
|
38
|
+
@write_response
|
34
39
|
end
|
35
40
|
|
36
41
|
protected
|
@@ -60,6 +65,11 @@ module Bas
|
|
60
65
|
|
61
66
|
read_data.nil? || read_data == {} || read_data.any? { |_key, value| [[], "", nil].include?(value) }
|
62
67
|
end
|
68
|
+
|
69
|
+
def close_connections
|
70
|
+
@shared_storage_reader.close_connections if @shared_storage_reader.respond_to?(:close_connections)
|
71
|
+
@shared_storage_writer.close_connections if @shared_storage_writer.respond_to?(:close_connections)
|
72
|
+
end
|
63
73
|
end
|
64
74
|
end
|
65
75
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative "base"
|
4
4
|
require_relative "types/read"
|
5
|
-
require_relative "../utils/postgres/
|
5
|
+
require_relative "../utils/postgres/connection"
|
6
6
|
require_relative "../version"
|
7
7
|
|
8
8
|
require "json"
|
@@ -17,17 +17,25 @@ module Bas
|
|
17
17
|
TABLE_PARAMS = "data, tag, archived, stage, status, error_message, version"
|
18
18
|
|
19
19
|
def read
|
20
|
-
|
20
|
+
establish_connection(:read)
|
21
21
|
|
22
|
-
first_result =
|
22
|
+
first_result = @read_connection.query(read_query).first || {}
|
23
23
|
|
24
24
|
@read_response = Bas::SharedStorage::Types::Read.new(first_result[:id], first_result[:data],
|
25
25
|
first_result[:inserted_at])
|
26
26
|
end
|
27
27
|
|
28
28
|
def write(data)
|
29
|
-
|
30
|
-
|
29
|
+
establish_connection(:write)
|
30
|
+
|
31
|
+
@write_response = @write_connection.query(write_query(data))
|
32
|
+
end
|
33
|
+
|
34
|
+
def close_connections
|
35
|
+
@read_connection&.finish
|
36
|
+
@write_connection&.finish
|
37
|
+
@read_connection = nil
|
38
|
+
@write_connection = nil
|
31
39
|
end
|
32
40
|
|
33
41
|
def set_in_process
|
@@ -44,6 +52,15 @@ module Bas
|
|
44
52
|
|
45
53
|
private
|
46
54
|
|
55
|
+
def establish_connection(action)
|
56
|
+
case action
|
57
|
+
when :read
|
58
|
+
@read_connection ||= Utils::Postgres::Connection.new(read_options[:connection])
|
59
|
+
when :write
|
60
|
+
@write_connection ||= Utils::Postgres::Connection.new(write_options[:connection])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
47
64
|
def read_query
|
48
65
|
query = "SELECT id, data, inserted_at FROM #{read_options[:db_table]} WHERE status='success' AND #{where}"
|
49
66
|
|
@@ -78,9 +95,9 @@ module Bas
|
|
78
95
|
end
|
79
96
|
|
80
97
|
def update_stage(id, stage)
|
81
|
-
|
98
|
+
establish_connection(:read)
|
82
99
|
|
83
|
-
|
100
|
+
@read_connection.query(update_query(id, stage))
|
84
101
|
end
|
85
102
|
|
86
103
|
def update_query(id, stage)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pg"
|
4
|
+
|
5
|
+
module Utils
|
6
|
+
module Postgres
|
7
|
+
# This module is a PostgresDB utility to establish connections to a Postgres database
|
8
|
+
# and execute raw or parameterized queries.
|
9
|
+
#
|
10
|
+
class Connection
|
11
|
+
def initialize(params)
|
12
|
+
@connection = PG::Connection.new(params)
|
13
|
+
end
|
14
|
+
|
15
|
+
def query(query)
|
16
|
+
results = if query.is_a? String
|
17
|
+
@connection.exec(query)
|
18
|
+
else
|
19
|
+
validate_query(query)
|
20
|
+
|
21
|
+
sentence, params = query
|
22
|
+
@connection.exec_params(sentence, params)
|
23
|
+
end
|
24
|
+
|
25
|
+
results.map { |result| result.transform_keys(&:to_sym) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def finish
|
29
|
+
@connection&.finish
|
30
|
+
@connection = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def validate_query(query)
|
36
|
+
return if query.is_a?(Array) && query.size == 2 && query[0].is_a?(String) && query[1].is_a?(Array)
|
37
|
+
|
38
|
+
raise ArgumentError, "Parameterized query must be an array of [sentence (String), params (Array)]"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/bas/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kommitters Open Source
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/bas/utils/operaton/base_operaton_client.rb
|
116
116
|
- lib/bas/utils/operaton/external_task_client.rb
|
117
117
|
- lib/bas/utils/operaton/process_client.rb
|
118
|
+
- lib/bas/utils/postgres/connection.rb
|
118
119
|
- lib/bas/utils/postgres/request.rb
|
119
120
|
- lib/bas/version.rb
|
120
121
|
- renovate.json
|