pg-locks-monitor 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pg-locks-monitor.rb +8 -5
- data/lib/pg_locks_monitor/version.rb +1 -1
- data/pg-locks-monitor.gemspec +1 -1
- data/spec/smoke_spec.rb +6 -2
- data/spec/spec_helper.rb +7 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 609f63093dd3729e2b05577d39d55d13a09cfeb78dadc185e3cd1bbeff15a5eb
|
4
|
+
data.tar.gz: 29bb4e5292296c81338ac5250efbc8e85927cdb8ede8354f0e4300b96bca7528
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50377aa6446f17e900a28d427a0c6fc734ab78e29934f73af50d7957d3f81228515abb236964c1b6d5e866c5fad001eda0853f13d5aeb0a3cb540d70c7cd0011
|
7
|
+
data.tar.gz: 782c10cf04da3cbf8ec325cb15680f90bbea646344df1e5e1a1e72125781279f98321f1cce41c6c5d7da60dd59cfaa04a04eadff3233ebe0a282202808fd308e
|
data/lib/pg-locks-monitor.rb
CHANGED
@@ -2,15 +2,16 @@
|
|
2
2
|
|
3
3
|
require "uri"
|
4
4
|
require "pg"
|
5
|
-
require "
|
5
|
+
require "rails-pg-extras"
|
6
|
+
require "active_record"
|
6
7
|
|
7
8
|
module PgLocksMonitor
|
8
9
|
def self.snapshot!
|
9
|
-
locks =
|
10
|
+
locks = RailsPgExtras.locks(
|
10
11
|
in_format: :hash,
|
11
12
|
).select do |lock|
|
12
13
|
if (age = lock.fetch("age"))
|
13
|
-
|
14
|
+
(ActiveSupport::Duration.parse(age).to_f * 1000) > configuration.locks_min_duration_ms
|
14
15
|
end
|
15
16
|
end.select(&configuration.locks_filter_proc)
|
16
17
|
.first(configuration.locks_limit)
|
@@ -19,8 +20,10 @@ module PgLocksMonitor
|
|
19
20
|
configuration.notifier_class.call(locks)
|
20
21
|
end
|
21
22
|
|
22
|
-
blocking =
|
23
|
-
|
23
|
+
blocking = RailsPgExtras.blocking(in_format: :hash).select do |block|
|
24
|
+
if (age = block.fetch("blocking_duration"))
|
25
|
+
(ActiveSupport::Duration.parse(age).to_f * 1000) > configuration.locks_min_duration_ms
|
26
|
+
end
|
24
27
|
end.select(&configuration.blocking_filter_proc)
|
25
28
|
.first(configuration.locks_limit)
|
26
29
|
|
data/pg-locks-monitor.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.test_files = s.files.grep(%r{^(spec)/})
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.license = "MIT"
|
18
|
-
s.add_dependency "
|
18
|
+
s.add_dependency "rails-pg-extras"
|
19
19
|
s.add_dependency "slack-notifier"
|
20
20
|
s.add_development_dependency "rake"
|
21
21
|
s.add_development_dependency "rspec"
|
data/spec/smoke_spec.rb
CHANGED
@@ -5,8 +5,8 @@ require "spec_helper"
|
|
5
5
|
describe PgLocksMonitor do
|
6
6
|
def spawn_update
|
7
7
|
Thread.new do
|
8
|
-
conn =
|
9
|
-
conn.
|
8
|
+
conn = RailsPgExtras.connection
|
9
|
+
conn.execute("
|
10
10
|
BEGIN;
|
11
11
|
UPDATE pg_locks_monitor_users SET name = 'Updated';
|
12
12
|
select pg_sleep(2);
|
@@ -25,6 +25,10 @@ describe PgLocksMonitor do
|
|
25
25
|
it "returns correct locks data" do
|
26
26
|
spawn_update
|
27
27
|
spawn_update
|
28
|
+
result = PgLocksMonitor.snapshot!
|
29
|
+
expect(result.fetch(:locks).count).to eq(0)
|
30
|
+
expect(result.fetch(:blocking).count).to eq(0)
|
31
|
+
|
28
32
|
sleep 1
|
29
33
|
|
30
34
|
result = PgLocksMonitor.snapshot!
|
data/spec/spec_helper.rb
CHANGED
@@ -35,14 +35,15 @@ RSpec.configure do |config|
|
|
35
35
|
end
|
36
36
|
|
37
37
|
config.before(:suite) do
|
38
|
-
|
39
|
-
conn
|
40
|
-
conn.
|
41
|
-
conn.
|
38
|
+
ActiveRecord::Base.establish_connection(ENV["DATABASE_URL"])
|
39
|
+
conn = RailsPgExtras.connection
|
40
|
+
conn.execute("CREATE TABLE IF NOT EXISTS pg_locks_monitor_users (id SERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL);")
|
41
|
+
conn.execute("INSERT INTO pg_locks_monitor_users (name) VALUES ('Alice');")
|
42
|
+
conn.execute("INSERT INTO pg_locks_monitor_users (name) VALUES ('Bob');")
|
42
43
|
end
|
43
44
|
|
44
45
|
config.after(:suite) do
|
45
|
-
conn =
|
46
|
-
conn.
|
46
|
+
conn = RailsPgExtras.connection
|
47
|
+
conn.execute("DROP TABLE IF EXISTS pg_locks_monitor_users;")
|
47
48
|
end
|
48
49
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg-locks-monitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pawurb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rails-pg-extras
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|