pgtk 0.16.2 → 0.16.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b04cd90c1011ad093997ba7f21cf0136104a7b4fb4de8d842c21794d3cf90ee
4
- data.tar.gz: 2c042b596ccebaaffb4f0597d3211ed53c9b02918e0daf400c0f8706135f0854
3
+ metadata.gz: f86b9a969a2e41e480e4596035128c5ac1f260eeaa4dfb0625a88316d5c34f5d
4
+ data.tar.gz: d6b9dfe1dd5717f2884ba63d72b87696ddc0331983527dbb530f74a469961af6
5
5
  SHA512:
6
- metadata.gz: cc9383ef551950dc82b2c825c11cc797965d38a29c2e4f1569b112035ea9ecf019e2437c6c50718fe001ff1bb8da0320da3d6b73fc305ce4ad3ab3d691bcea48
7
- data.tar.gz: e72d1e3321a6326d9e8afa66b819e4ceee68d4dd0d5708c27c73df584b5979ea02708070d0c185c333177f430f6925693a3c700aad1658d4dee2e9ad3bdaa63f
6
+ metadata.gz: 7f7433c8b02fae500929e2e62929469eae1511d958fb85d8d7a6ca56fe9010467bac3759b6f77155ec4e4d86f92b532e8f7c5bf57c83f4c6a7ce99caebc63b9d
7
+ data.tar.gz: ef3a0849da8ac6678a4957868618b6c6350c86fc255285e49efd6ed3cc8dbc5503765a54abed9387d60a90e0d1c1571dd5f35e4f2daad4e8c9b5ada8e141b1d5
data/Gemfile.lock CHANGED
@@ -10,6 +10,7 @@ PATH
10
10
  pg (~> 1.1)
11
11
  qbash (> 0)
12
12
  random-port (> 0)
13
+ tago (> 0)
13
14
 
14
15
  GEM
15
16
  remote: https://rubygems.org/
@@ -24,7 +25,7 @@ GEM
24
25
  elapsed (0.0.1)
25
26
  loog (> 0)
26
27
  tago (> 0)
27
- joined (0.1.0)
28
+ joined (0.2.0)
28
29
  json (2.12.0)
29
30
  language_server-protocol (3.17.0.5)
30
31
  lint_roller (1.1.0)
@@ -3,6 +3,7 @@
3
3
  # SPDX-FileCopyrightText: Copyright (c) 2019-2025 Yegor Bugayenko
4
4
  # SPDX-License-Identifier: MIT
5
5
 
6
+ require 'tago'
6
7
  require 'timeout'
7
8
  require_relative '../pgtk'
8
9
 
@@ -51,6 +52,9 @@ require_relative '../pgtk'
51
52
  # Copyright:: Copyright (c) 2019-2025 Yegor Bugayenko
52
53
  # License:: MIT
53
54
  class Pgtk::Impatient
55
+ # If timed out
56
+ class TooSlow < StandardError; end
57
+
54
58
  # Constructor.
55
59
  #
56
60
  # @param [Pgtk::Pool] pool The pool to decorate
@@ -74,8 +78,19 @@ class Pgtk::Impatient
74
78
  # @return [Array] Result rows
75
79
  # @raise [Timeout::Error] If the query takes too long
76
80
  def exec(sql, *args)
77
- Timeout.timeout(@timeout) do
78
- @pool.exec(sql, *args)
81
+ start = Time.now
82
+ begin
83
+ Timeout.timeout(@timeout) do
84
+ @pool.exec(sql, *args)
85
+ end
86
+ rescue Timeout::Error
87
+ raise TooSlow, [
88
+ 'SQL query',
89
+ ("with #{args.count} arguments" unless args.empty?),
90
+ 'stopped after',
91
+ start.ago,
92
+ 'of waiting'
93
+ ].compact.join(' ')
79
94
  end
80
95
  end
81
96
 
data/lib/pgtk/pool.rb CHANGED
@@ -5,6 +5,7 @@
5
5
 
6
6
  require 'pg'
7
7
  require 'loog'
8
+ require 'tago'
8
9
  require_relative '../pgtk'
9
10
  require_relative 'wire'
10
11
 
@@ -203,9 +204,9 @@ class Pgtk::Pool
203
204
  end
204
205
  lag = Time.now - start
205
206
  if lag < 1
206
- @log.debug("#{sql}: #{(lag * 1000).round}ms / #{@conn.object_id}")
207
+ @log.debug("#{sql}: #{start.ago} / #{@conn.object_id}")
207
208
  else
208
- @log.info("#{sql}: #{format('%.02f', lag)}s")
209
+ @log.info("#{sql}: #{start.ago}")
209
210
  end
210
211
  out
211
212
  end
data/lib/pgtk/version.rb CHANGED
@@ -11,5 +11,5 @@ require_relative '../pgtk'
11
11
  # License:: MIT
12
12
  module Pgtk
13
13
  # Current version of the library.
14
- VERSION = '0.16.2'
14
+ VERSION = '0.16.3'
15
15
  end
data/pgtk.gemspec CHANGED
@@ -34,5 +34,6 @@ Gem::Specification.new do |s|
34
34
  s.add_dependency 'pg', '~>1.1'
35
35
  s.add_dependency 'qbash', '>0'
36
36
  s.add_dependency 'random-port', '>0'
37
+ s.add_dependency 'tago', '>0'
37
38
  s.metadata['rubygems_mfa_required'] = 'true'
38
39
  end
@@ -25,6 +25,16 @@ class TestImpatient < Pgtk::Test
25
25
  end
26
26
  end
27
27
 
28
+ def test_interrupts
29
+ fake_pool do |pool|
30
+ assert_raises(Pgtk::Impatient::TooSlow) do
31
+ Pgtk::Impatient.new(pool, 0.1).exec(
32
+ 'SELECT COUNT(*) FROM generate_series(1, 10000000) AS a'
33
+ )
34
+ end
35
+ end
36
+ end
37
+
28
38
  def test_doesnt_interrupt
29
39
  fake_pool do |pool|
30
40
  id = Pgtk::Impatient.new(pool).exec(
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgtk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.2
4
+ version: 0.16.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -121,6 +121,20 @@ dependencies:
121
121
  - - ">"
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
+ - !ruby/object:Gem::Dependency
125
+ name: tago
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">"
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ type: :runtime
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">"
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
124
138
  description: This small Ruby gem helps you integrate PostgreSQL with your Ruby web
125
139
  app, through Liquibase. It also adds a simple connection pool and query processor,
126
140
  to make SQL manipulation simpler.