bas 1.9.0 → 1.9.2

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: fe416744cd3c3fb9f0902dfc6a3b1432b63425a00da2cea4828a69b0f7e4595a
4
- data.tar.gz: 02701d0e8b83c71e0721ebae2a197c6f9204414d3a6f313052152bc2e6957863
3
+ metadata.gz: 680fbfea9ee1348a6315220f7b92b58e1cca92003dbe637100c4ba97f6dfb1fe
4
+ data.tar.gz: 68d8da3ea3b1ca80ba09ad95b4715a5ced92f05e59c4e9a43e9980a869a216ad
5
5
  SHA512:
6
- metadata.gz: b63e685728abb1a3c80ab896aca20f9621a08b3f3defa9ca682912e9722359a3510b2bfd65154bedc3a0171f372ea9f1df63ae6305bbfc48b28f36477c8c2761
7
- data.tar.gz: 7f73e57bc600b044a82deb51c97b30eab54bc5de48122f554d18614e08a273950fa705f5403accd6ff5899e54dbba5ccb3634cf0504769073a55d8d6a7b695bc
6
+ metadata.gz: 57de8f36915f5a42a69d664cd5d712ffcfecafba3957b2bc1d3a24c26bebe679c2f87fc2544f513393938825b45c2ef64b477178414d4684aac4704f27f11148
7
+ data.tar.gz: 411d5662f4790e35c3430aeb38eafb2d48958b5d7783cbfb880a993ec477363762eea868578334039614a82d6e72dbb418e4cff9170e88434c8f3d52744ef80c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ # 1.9.2 (21.07.2025)
4
+ - [Refactor PostgreSQL connections](https://github.com/kommitters/bas/pull/153)
5
+
6
+ # 1.9.1 (15.07.2025)
7
+ - [refactor: Refactor client to meet the needs of the implementation to be performed](https://github.com/kommitters/bas/pull/149)
8
+
3
9
  # 1.9.0 (15.07.2025)
4
10
  - [feat: Implement client to perform process deployments and instance creation in Operaton via the REST API](https://github.com/kommitters/bas/pull/146)
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
- @process_options = options || {}
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,8 @@ 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)
34
37
  end
35
38
 
36
39
  protected
@@ -60,6 +63,11 @@ module Bas
60
63
 
61
64
  read_data.nil? || read_data == {} || read_data.any? { |_key, value| [[], "", nil].include?(value) }
62
65
  end
66
+
67
+ def close_connections
68
+ @shared_storage_reader.close_connections if @shared_storage_reader.respond_to?(:close_connections)
69
+ @shared_storage_writer.close_connections if @shared_storage_writer.respond_to?(:close_connections)
70
+ end
63
71
  end
64
72
  end
65
73
  end
@@ -21,6 +21,8 @@ module Bas
21
21
 
22
22
  def set_processed; end
23
23
 
24
+ def close_connections; end
25
+
24
26
  protected
25
27
 
26
28
  def read
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative "base"
4
4
  require_relative "types/read"
5
- require_relative "../utils/postgres/request"
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
- params = { connection: read_options[:connection], query: read_query }
20
+ establish_connection(:read)
21
21
 
22
- first_result = Utils::Postgres::Request.execute(params).first || {}
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
- params = { connection: write_options[:connection], query: write_query(data) }
30
- @write_response = Utils::Postgres::Request.execute(params)
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
- params = { connection: read_options[:connection], query: update_query(id, stage) }
98
+ establish_connection(:read)
82
99
 
83
- Utils::Postgres::Request.execute(params)
100
+ @read_connection.query(update_query(id, stage))
84
101
  end
85
102
 
86
103
  def update_query(id, stage)
@@ -40,16 +40,15 @@ module Utils
40
40
  def instance_with_business_key_exists?(process_key, business_key)
41
41
  query_params = {
42
42
  processDefinitionKey: process_key,
43
- maxResults: 50
43
+ maxResults: 50,
44
+ active: true
44
45
  }
45
46
 
46
47
  response = get("/history/process-instance", query_params)
47
48
  response.any? { |instance| instance["businessKey"] == business_key }
48
49
  end
49
50
 
50
- def start_process_instance_by_key(process_key, business_key:, variables: {}, validate_business_key: true)
51
- validate_uniqueness!(process_key, business_key) if validate_business_key
52
-
51
+ def start_process_instance_by_key(process_key, business_key:, variables: {})
53
52
  json_payload = {
54
53
  businessKey: business_key,
55
54
  variables: format_variables(variables)
@@ -72,12 +71,6 @@ module Utils
72
71
  f.adapter Faraday.default_adapter
73
72
  end
74
73
  end
75
-
76
- def validate_uniqueness!(process_key, business_key)
77
- return unless instance_with_business_key_exists?(process_key, business_key)
78
-
79
- raise "There is already an instance for processing '#{process_key}' with business key '#{business_key}'"
80
- end
81
74
  end
82
75
  end
83
76
  end
@@ -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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Bas
4
4
  # Gem version
5
- VERSION = "1.9.0"
5
+ VERSION = "1.9.2"
6
6
  end
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.0
4
+ version: 1.9.2
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
@@ -139,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
140
  - !ruby/object:Gem::Version
140
141
  version: '0'
141
142
  requirements: []
142
- rubygems_version: 3.6.7
143
+ rubygems_version: 3.6.9
143
144
  specification_version: 4
144
145
  summary: BAS - Business automation suite
145
146
  test_files: []