statement_timeout 0.0.1 → 1.0.0.pre.rc.1
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/README.md +66 -13
- data/lib/statement_timeout/railtie.rb +14 -0
- data/lib/statement_timeout/version.rb +1 -1
- data/lib/statement_timeout.rb +47 -0
- metadata +75 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b42943a4a7aaa58ea1d0111e663391f30e8781dee8d220ad8db2ad011b1efda3
|
4
|
+
data.tar.gz: c585bf0781f46e562b3947c0813c478ba6d14e038d9c0f876ba27dd0ee0fe4be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66a2345bbb4088bdebd6fe59327c5550b4d114e6edac342d4778641a081184cd5a7e5d0bfec6db4d5e07be71acf9f9abbd727a0b665725b916f41f6798742641
|
7
|
+
data.tar.gz: 566f9e844756d16d3d85da9a31a35a5c52b52969cf8acf95879dbf04c915e1eb974b7bc1c5d8c4e3fa0902be25885cf24ce67375ac10bb3dd0b373674d45606c
|
data/README.md
CHANGED
@@ -1,31 +1,84 @@
|
|
1
|
-
#
|
1
|
+
# statement_timeout
|
2
2
|
|
3
|
-
|
3
|
+
[](https://github.com/keygen-sh/statement_timeout/actions)
|
4
|
+
[](https://badge.fury.io/rb/statement_timeout)
|
4
5
|
|
5
|
-
|
6
|
+
Use `statement_timeout` to wrap an Active Record transaction or query in a
|
7
|
+
local statement timeout.
|
8
|
+
|
9
|
+
This gem was extracted from [Keygen](https://keygen.sh).
|
10
|
+
|
11
|
+
Sponsored by:
|
12
|
+
|
13
|
+
<a href="https://keygen.sh?ref=statement_timeout">
|
14
|
+
<div>
|
15
|
+
<img src="https://keygen.sh/images/logo-pill.png" width="200" alt="Keygen">
|
16
|
+
</div>
|
17
|
+
</a>
|
18
|
+
|
19
|
+
_A fair source software licensing and distribution API._
|
6
20
|
|
7
21
|
## Installation
|
8
22
|
|
9
|
-
|
23
|
+
Add this line to your application's `Gemfile`:
|
10
24
|
|
11
|
-
|
25
|
+
```ruby
|
26
|
+
gem 'statement_timeout'
|
27
|
+
```
|
12
28
|
|
13
|
-
|
29
|
+
And then execute:
|
14
30
|
|
15
|
-
|
31
|
+
```bash
|
32
|
+
$ bundle
|
33
|
+
```
|
16
34
|
|
17
|
-
|
35
|
+
Or install it yourself as:
|
36
|
+
|
37
|
+
```bash
|
38
|
+
$ gem install statement_timeout
|
39
|
+
```
|
18
40
|
|
19
41
|
## Usage
|
20
42
|
|
21
|
-
|
43
|
+
```ruby
|
44
|
+
User.statement_timeout 42.minutes do
|
45
|
+
some_expensive_operation
|
46
|
+
end
|
47
|
+
|
48
|
+
User.posts.statement_timeout 10.seconds do
|
49
|
+
some_cheap_operation
|
50
|
+
end
|
51
|
+
|
52
|
+
Tag.statement_timeout 6.hours do |conn|
|
53
|
+
conn.execute 'VACUUM ANALYZE tags'
|
54
|
+
end
|
55
|
+
```
|
22
56
|
|
23
|
-
##
|
57
|
+
## Future
|
24
58
|
|
25
|
-
|
59
|
+
Right now, the gem only supports RSpec, but we're open to pull requests that
|
60
|
+
extend the functionality to other testing frameworks.
|
26
61
|
|
27
|
-
|
62
|
+
## Supported databases
|
63
|
+
|
64
|
+
We currently support PostgreSQL. We'd love contributions that add MySQL,
|
65
|
+
MariaDB, and SQLite support, but we probably won't add it ourselves.
|
66
|
+
|
67
|
+
## Supported Rubies
|
68
|
+
|
69
|
+
**`statement_timeout` supports Ruby 3.1 and above.** We encourage you to upgrade
|
70
|
+
if you're on an older version. Ruby 3 provides a lot of great features, like
|
71
|
+
better pattern matching and a new shorthand hash syntax.
|
72
|
+
|
73
|
+
## Is it any good?
|
74
|
+
|
75
|
+
Yes.
|
28
76
|
|
29
77
|
## Contributing
|
30
78
|
|
31
|
-
|
79
|
+
If you have an idea, or have discovered a bug, please open an issue or create a
|
80
|
+
pull request.
|
81
|
+
|
82
|
+
## License
|
83
|
+
|
84
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_record/connection_adapters/postgresql_adapter'
|
4
|
+
require 'active_record/relation'
|
5
|
+
|
6
|
+
module StatementTimeout
|
7
|
+
ActiveSupport.on_load :active_record do
|
8
|
+
ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(AbstractAdapterExtension)
|
9
|
+
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(PostgreSQLAdapterExtension)
|
10
|
+
ActiveRecord::QueryMethods.prepend(QueryMethodsExtension)
|
11
|
+
ActiveRecord::Querying.prepend(QueryingExtension)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
data/lib/statement_timeout.rb
CHANGED
@@ -1,6 +1,53 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_record'
|
5
|
+
|
3
6
|
require_relative 'statement_timeout/version'
|
7
|
+
require_relative 'statement_timeout/railtie'
|
4
8
|
|
5
9
|
module StatementTimeout
|
10
|
+
module AbstractAdapterExtension
|
11
|
+
def supports_statement_timeout? = false
|
12
|
+
def statement_timeout = raise NotImplementedError
|
13
|
+
def statement_timeout=(timeout)
|
14
|
+
raise NotImplementedError
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module PostgreSQLAdapterExtension
|
19
|
+
def supports_statement_timeout? = true
|
20
|
+
def statement_timeout = @statement_timeout ||= query_value("SHOW statement_timeout")
|
21
|
+
def statement_timeout=(timeout)
|
22
|
+
@statement_timeout = nil
|
23
|
+
|
24
|
+
internal_exec_query("SET statement_timeout = #{quote(timeout)}")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module QueryMethodsExtension
|
29
|
+
def statement_timeout(timeout)
|
30
|
+
timeout = if timeout in ActiveSupport::Duration
|
31
|
+
timeout.in_milliseconds
|
32
|
+
else
|
33
|
+
timeout
|
34
|
+
end
|
35
|
+
|
36
|
+
connection_pool.with_connection do |connection|
|
37
|
+
raise ActiveRecord::AdapterError, "statement_timeout is not supported for the #{connection.class.inspect} adapter" unless
|
38
|
+
connection.supports_statement_timeout?
|
39
|
+
|
40
|
+
statement_timeout_was, connection.statement_timeout = connection.statement_timeout, timeout
|
41
|
+
|
42
|
+
yield connection
|
43
|
+
ensure
|
44
|
+
connection.statement_timeout = statement_timeout_was
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module QueryingExtension
|
50
|
+
delegate :statement_timeout, to: :all
|
51
|
+
end
|
6
52
|
end
|
53
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statement_timeout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
4
|
+
version: 1.0.0.pre.rc.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zeke Gabrielse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,6 +38,76 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: temporary_tables
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sql_matchers
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.4'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.4'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mysql2
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pg
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
41
111
|
description: Wrap an Active Record transaction or query in a local statement timeout.
|
42
112
|
email:
|
43
113
|
- oss@keygen.sh
|
@@ -51,6 +121,7 @@ files:
|
|
51
121
|
- README.md
|
52
122
|
- SECURITY.md
|
53
123
|
- lib/statement_timeout.rb
|
124
|
+
- lib/statement_timeout/railtie.rb
|
54
125
|
- lib/statement_timeout/version.rb
|
55
126
|
homepage: https://github.com/keygen-sh/statement_timeout
|
56
127
|
licenses:
|
@@ -67,9 +138,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
138
|
version: '3.1'
|
68
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
140
|
requirements:
|
70
|
-
- - "
|
141
|
+
- - ">"
|
71
142
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
143
|
+
version: 1.3.1
|
73
144
|
requirements: []
|
74
145
|
rubygems_version: 3.4.13
|
75
146
|
signing_key:
|