pg_notifier 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/pg_notifier.rb +1 -0
- data/lib/pg_notifier/errors.rb +4 -0
- data/lib/pg_notifier/manager.rb +20 -2
- data/lib/pg_notifier/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDQ3YjdhYWExNjMzZjNhZTBhMWE5ZmQ1ZTU0NGU3YTNhMzY2MmQyZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWQ4MzkzNzNkOGJjZDQ2MmMzYzc4ZTcxZWJjZmFjOTBiMzA3MjMzNA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YWU5ZGNiNDBhMmMzN2U1YTdiN2E1YTg4MDE5NGQ5MTQ5NjRiM2I4MWJiM2M0
|
10
|
+
YTgzMzdlYjBjYjA3M2RmMzAwZTEzZmY3N2ExZjQzYjQ5ODFiNjQ3MDQxZTVl
|
11
|
+
YTUyNjQxOWI4NDM3NzIwYjgzN2JiMjAwODU1MzRlOWFkNDNlMDU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjkwNDUzN2E4ODg2N2U4ZWEwYTRiMDI1M2U1NzQ3MDJkZTRhYjcwZjY0NGZh
|
14
|
+
MjkwMTNkNTllMDY0NDE4ZDMwOGUzY2E3N2M5ODVhZjM4NWY2NGE3MTgwZjUz
|
15
|
+
NDJjODUyODI1ZGNmNzIxYWE0ZThiNmY3ZTQ0NDMzZWQ0OTZjOTI=
|
data/lib/pg_notifier.rb
CHANGED
data/lib/pg_notifier/manager.rb
CHANGED
@@ -14,6 +14,8 @@ module PgNotifier
|
|
14
14
|
@finish = false
|
15
15
|
@mutex = Mutex.new
|
16
16
|
@resource = ConditionVariable.new
|
17
|
+
|
18
|
+
Thread.abort_on_exception = true
|
17
19
|
end
|
18
20
|
|
19
21
|
def notify(channel, options = {}, &block)
|
@@ -47,11 +49,17 @@ module PgNotifier
|
|
47
49
|
Thread.new do
|
48
50
|
channels.each do |channel|
|
49
51
|
pg_result = connection.exec "LISTEN #{channel};"
|
52
|
+
|
53
|
+
unless pg_result.result_status.eql? PG::PGRES_COMMAND_OK
|
54
|
+
raise ChannelNotLaunched, "Channel ##{channel} not launched"
|
55
|
+
end
|
50
56
|
end
|
51
57
|
|
52
58
|
@mutex.synchronize do
|
53
59
|
until @finish do
|
54
60
|
connection.wait_for_notify do |channel, pid, payload|
|
61
|
+
logger.info "Notifying channel: #{channel}, pid: #{pid}, payload: #{payload}"
|
62
|
+
|
55
63
|
subscriptions = subscriptions_by_channels.fetch channel, []
|
56
64
|
subscriptions.each { |subscription| subscription.notify(channel, pid, payload) }
|
57
65
|
end
|
@@ -84,18 +92,28 @@ module PgNotifier
|
|
84
92
|
logger.info 'Shutting down'
|
85
93
|
|
86
94
|
@finish = true
|
87
|
-
|
95
|
+
close_connection
|
88
96
|
|
89
97
|
exit(0)
|
90
98
|
end
|
91
99
|
|
100
|
+
def close_connection
|
101
|
+
unless connection.finished?
|
102
|
+
channels.each do |channel|
|
103
|
+
connection.exec "UNLISTEN #{channel};"
|
104
|
+
end
|
105
|
+
|
106
|
+
connection.finish
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
92
110
|
def graceful_shutdown
|
93
111
|
logger.info 'Gracefully shutting down'
|
94
112
|
|
95
113
|
@finish = true
|
96
114
|
|
97
115
|
@mutex.synchronize do
|
98
|
-
|
116
|
+
close_connection
|
99
117
|
@resource.signal
|
100
118
|
end
|
101
119
|
|
data/lib/pg_notifier/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- German Antsiferov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- bin/pg_notifier
|
87
87
|
- bin/setup
|
88
88
|
- lib/pg_notifier.rb
|
89
|
+
- lib/pg_notifier/errors.rb
|
89
90
|
- lib/pg_notifier/manager.rb
|
90
91
|
- lib/pg_notifier/subscription.rb
|
91
92
|
- lib/pg_notifier/version.rb
|