pg_notifier 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDQ3YjdhYWExNjMzZjNhZTBhMWE5ZmQ1ZTU0NGU3YTNhMzY2MmQyZA==
4
+ MmZlMmY5YjE5MzVhMjI1NjljZGVkZTU2NGUwYjA2MGFmMGRmZDcxNg==
5
5
  data.tar.gz: !binary |-
6
- MWQ4MzkzNzNkOGJjZDQ2MmMzYzc4ZTcxZWJjZmFjOTBiMzA3MjMzNA==
6
+ ZjRkYjU1MjM4Zjk4ZTUzOGYxZjg4YmFkMTAyYmIyNWFhZDYyZDM5Yw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YWU5ZGNiNDBhMmMzN2U1YTdiN2E1YTg4MDE5NGQ5MTQ5NjRiM2I4MWJiM2M0
10
- YTgzMzdlYjBjYjA3M2RmMzAwZTEzZmY3N2ExZjQzYjQ5ODFiNjQ3MDQxZTVl
11
- YTUyNjQxOWI4NDM3NzIwYjgzN2JiMjAwODU1MzRlOWFkNDNlMDU=
9
+ ZmM5MTA3M2ZjZWU3NjJmZDkyMWMyNmM0OTZiYmRhMzBlNzM3NGVlYWM1OWNl
10
+ ZWRjZGNjZTljNDA3Zjk0YTdkODhkOGIyNWY4Y2M2MDBkMmI5ZmNiYjQyNzU2
11
+ NTZiNzI0YjY2ZDI4NDUxMjk1YzdmMmQxYjBmODgxYjczODUwYWU=
12
12
  data.tar.gz: !binary |-
13
- YjkwNDUzN2E4ODg2N2U4ZWEwYTRiMDI1M2U1NzQ3MDJkZTRhYjcwZjY0NGZh
14
- MjkwMTNkNTllMDY0NDE4ZDMwOGUzY2E3N2M5ODVhZjM4NWY2NGE3MTgwZjUz
15
- NDJjODUyODI1ZGNmNzIxYWE0ZThiNmY3ZTQ0NDMzZWQ0OTZjOTI=
13
+ Yzg3NjE3YmM3MjRmYTgyNTUzMDkyOTczY2VkMjYyYTM4NzQ2NDUzYWI2YWYy
14
+ MmJiZWFjNzg5OWE0ZGJkOWNlMDZmMTAzOTA1MWU4NTlhOTQ4OTg3ZmNhYTNl
15
+ ZTlhMjcyODZhYWZmNzE0N2FkMTExMzBjNmFiM2QyYmFlOTcyZDU=
data/README.md CHANGED
@@ -20,7 +20,6 @@ require 'pg_notifier'
20
20
  module PgNotifier
21
21
  configure do |notifier|
22
22
  notifier.logger = Logger.new('/var/log/pg_notifier.log')
23
- notifier.timeout = 1
24
23
  notifier.db_config = {
25
24
  host: 'localhost',
26
25
  port: 5432,
@@ -4,17 +4,13 @@ require 'logger'
4
4
 
5
5
  module PgNotifier
6
6
  class Manager
7
- attr_accessor :logger, :db_config, :timeout
7
+ attr_accessor :logger, :db_config
8
8
 
9
9
  def initialize(attrs = {})
10
10
  @logger = attrs.fetch :logger, Logger.new(STDOUT)
11
11
  @db_config = attrs.fetch :db_config , {}
12
- @timeout = attrs.fetch :timeout, 1
13
12
 
14
13
  @finish = false
15
- @mutex = Mutex.new
16
- @resource = ConditionVariable.new
17
-
18
14
  Thread.abort_on_exception = true
19
15
  end
20
16
 
@@ -55,16 +51,12 @@ module PgNotifier
55
51
  end
56
52
  end
57
53
 
58
- @mutex.synchronize do
59
- until @finish do
60
- connection.wait_for_notify do |channel, pid, payload|
61
- logger.info "Notifying channel: #{channel}, pid: #{pid}, payload: #{payload}"
62
-
63
- subscriptions = subscriptions_by_channels.fetch channel, []
64
- subscriptions.each { |subscription| subscription.notify(channel, pid, payload) }
65
- end
54
+ until @finish do
55
+ connection.wait_for_notify do |channel, pid, payload|
56
+ logger.info "Notifying channel: #{channel}, pid: #{pid}, payload: #{payload}"
66
57
 
67
- @resource.wait @mutex, timeout
58
+ subscriptions = subscriptions_by_channels.fetch channel, []
59
+ subscriptions.each { |subscription| subscription.notify(channel, pid, payload) }
68
60
  end
69
61
  end
70
62
  end
@@ -78,26 +70,13 @@ module PgNotifier
78
70
  def handle_signal(sig)
79
71
  logger.debug "Got #{sig} signal"
80
72
 
81
- case sig
82
- when 'INT'
83
- shutdown
84
- when 'TERM'
85
- graceful_shutdown
86
- when 'HUP'
87
- graceful_shutdown
88
- end
73
+ shutdown if %w[INT TERM HUP].include? sig
89
74
  end
90
75
 
91
76
  def shutdown
92
77
  logger.info 'Shutting down'
93
78
 
94
79
  @finish = true
95
- close_connection
96
-
97
- exit(0)
98
- end
99
-
100
- def close_connection
101
80
  unless connection.finished?
102
81
  channels.each do |channel|
103
82
  connection.exec "UNLISTEN #{channel};"
@@ -105,17 +84,6 @@ module PgNotifier
105
84
 
106
85
  connection.finish
107
86
  end
108
- end
109
-
110
- def graceful_shutdown
111
- logger.info 'Gracefully shutting down'
112
-
113
- @finish = true
114
-
115
- @mutex.synchronize do
116
- close_connection
117
- @resource.signal
118
- end
119
87
 
120
88
  exit(0)
121
89
  end
@@ -1,3 +1,3 @@
1
1
  module PgNotifier
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - German Antsiferov