pg_notifier 0.1.1 → 0.1.2
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 +8 -8
- data/README.md +0 -1
- data/lib/pg_notifier/manager.rb +7 -39
- data/lib/pg_notifier/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MmZlMmY5YjE5MzVhMjI1NjljZGVkZTU2NGUwYjA2MGFmMGRmZDcxNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjRkYjU1MjM4Zjk4ZTUzOGYxZjg4YmFkMTAyYmIyNWFhZDYyZDM5Yw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZmM5MTA3M2ZjZWU3NjJmZDkyMWMyNmM0OTZiYmRhMzBlNzM3NGVlYWM1OWNl
|
10
|
+
ZWRjZGNjZTljNDA3Zjk0YTdkODhkOGIyNWY4Y2M2MDBkMmI5ZmNiYjQyNzU2
|
11
|
+
NTZiNzI0YjY2ZDI4NDUxMjk1YzdmMmQxYjBmODgxYjczODUwYWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Yzg3NjE3YmM3MjRmYTgyNTUzMDkyOTczY2VkMjYyYTM4NzQ2NDUzYWI2YWYy
|
14
|
+
MmJiZWFjNzg5OWE0ZGJkOWNlMDZmMTAzOTA1MWU4NTlhOTQ4OTg3ZmNhYTNl
|
15
|
+
ZTlhMjcyODZhYWZmNzE0N2FkMTExMzBjNmFiM2QyYmFlOTcyZDU=
|
data/README.md
CHANGED
data/lib/pg_notifier/manager.rb
CHANGED
@@ -4,17 +4,13 @@ require 'logger'
|
|
4
4
|
|
5
5
|
module PgNotifier
|
6
6
|
class Manager
|
7
|
-
attr_accessor :logger, :db_config
|
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
|
-
@
|
59
|
-
|
60
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/pg_notifier/version.rb
CHANGED