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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3bd2f4561c83a6d10a0120670bb89f8140f01f3afad7434fbea969e113cc542
4
- data.tar.gz: 2fdb6e38890f1b085a32e72fee4d32eeb4e77e6a1f865737b2f3541d76d333ad
3
+ metadata.gz: 609f63093dd3729e2b05577d39d55d13a09cfeb78dadc185e3cd1bbeff15a5eb
4
+ data.tar.gz: 29bb4e5292296c81338ac5250efbc8e85927cdb8ede8354f0e4300b96bca7528
5
5
  SHA512:
6
- metadata.gz: 1396e94b66ae62db3ee552855cfe8b2e7d10c5efdf87f323bc889c8fb17530cf9076e6239f2dc9713907f28ddbb5de602f4baa507b38621419534be545be83c6
7
- data.tar.gz: a9bafef4918812b931737a0096cd2096181512e6eb5b35585b4e5caf50d7230f1dca4b8b2a37eeac7b521968577cf915cd97bff1f79b757dc909b5d1a4eb4f18
6
+ metadata.gz: 50377aa6446f17e900a28d427a0c6fc734ab78e29934f73af50d7957d3f81228515abb236964c1b6d5e866c5fad001eda0853f13d5aeb0a3cb540d70c7cd0011
7
+ data.tar.gz: 782c10cf04da3cbf8ec325cb15680f90bbea646344df1e5e1a1e72125781279f98321f1cce41c6c5d7da60dd59cfaa04a04eadff3233ebe0a282202808fd308e
@@ -2,15 +2,16 @@
2
2
 
3
3
  require "uri"
4
4
  require "pg"
5
- require "ruby-pg-extras"
5
+ require "rails-pg-extras"
6
+ require "active_record"
6
7
 
7
8
  module PgLocksMonitor
8
9
  def self.snapshot!
9
- locks = RubyPgExtras.locks(
10
+ locks = RailsPgExtras.locks(
10
11
  in_format: :hash,
11
12
  ).select do |lock|
12
13
  if (age = lock.fetch("age"))
13
- DurationHelper.parse_to_ms(age) > configuration.locks_min_duration_ms
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 = RubyPgExtras.blocking(in_format: :hash).select do |block|
23
- DurationHelper.parse_to_ms(block.fetch("blocking_duration")) > configuration.blocking_min_duration_ms
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgLocksMonitor
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
@@ -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 "ruby-pg-extras"
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 = PG.connect(ENV["DATABASE_URL"])
9
- conn.exec("
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
- conn = RubyPgExtras.connection
39
- conn.exec("CREATE TABLE IF NOT EXISTS pg_locks_monitor_users (id SERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL);")
40
- conn.exec("INSERT INTO pg_locks_monitor_users (name) VALUES ('Alice');")
41
- conn.exec("INSERT INTO pg_locks_monitor_users (name) VALUES ('Bob');")
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 = RubyPgExtras.connection
46
- conn.exec("DROP TABLE IF EXISTS pg_locks_monitor_users;")
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.0
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-02 00:00:00.000000000 Z
11
+ date: 2024-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: ruby-pg-extras
14
+ name: rails-pg-extras
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="