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 +4 -4
- data/Gemfile.lock +2 -1
- data/lib/pgtk/impatient.rb +17 -2
- data/lib/pgtk/pool.rb +3 -2
- data/lib/pgtk/version.rb +1 -1
- data/pgtk.gemspec +1 -0
- data/test/test_impatient.rb +10 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f86b9a969a2e41e480e4596035128c5ac1f260eeaa4dfb0625a88316d5c34f5d
|
4
|
+
data.tar.gz: d6b9dfe1dd5717f2884ba63d72b87696ddc0331983527dbb530f74a469961af6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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)
|
data/lib/pgtk/impatient.rb
CHANGED
@@ -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
|
-
|
78
|
-
|
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}: #{
|
207
|
+
@log.debug("#{sql}: #{start.ago} / #{@conn.object_id}")
|
207
208
|
else
|
208
|
-
@log.info("#{sql}: #{
|
209
|
+
@log.info("#{sql}: #{start.ago}")
|
209
210
|
end
|
210
211
|
out
|
211
212
|
end
|
data/lib/pgtk/version.rb
CHANGED
data/pgtk.gemspec
CHANGED
data/test/test_impatient.rb
CHANGED
@@ -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.
|
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.
|