activerecord-postgres_pub_sub 2.0.0 → 2.2.0

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: f74c76d5872b835ef89c6fedb2f516225ce6b3b742598dc2401621ba6131f4e7
4
- data.tar.gz: a64cb743a412aeceb92192b93565b9ed56edeaf6f8aa48c35eaf8ed71afedfaf
3
+ metadata.gz: 1b886594148cd3420c38dee50e9baeba2d73f01901cd682704efb624ee999b51
4
+ data.tar.gz: ee644f50f830c05f60efc505f50b73ffefbbb4971bbbca256e63d4d00d16c9f2
5
5
  SHA512:
6
- metadata.gz: d19558e79e5bb221923f258fcaf1c1e6180e3e4393ea918a9a8a54e5e2156bac29ed83f27041e2bda474542b6023f6ccd63fd9b281e7262aa3bc5a58d32f86b1
7
- data.tar.gz: a585933b618e85e9e37706d3de0834be3dff763a01ffad5cbcadc13f2d023646ce0cd7d8e7ce9c018e5467de3a508cb2dc7ea580347cffe379fe59fcf35247da
6
+ metadata.gz: 02d2b855c61be06e21b9acedb849a0ada4a99f7345f5be171ac33fcf4ca67ceced2ffd9fa023cce5851a0cb3eadc8a344192f8d35ab15ac947c45a9d0ccf7ce6
7
+ data.tar.gz: c23a5d3df02df37aad3e136924926428a366721d1da68e854e6968c2f728db43cb6059f5258e276d0bbc10008ab2bec319908f4c1babc280ead7952d5d102d6d
data/Appraisals CHANGED
@@ -1,30 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise "rails-5.1" do
4
- gem "activerecord", "5.1.6"
5
- gem "pg", "0.18.4"
6
- end
7
-
8
3
  appraise "rails-5.2_pg-1.1" do
9
4
  gem "activerecord", "5.2.1"
10
5
  gem "pg", "1.1.4"
11
6
  end
12
7
 
13
- appraise "rails-5.2_pg-0.18" do
14
- gem "activerecord", "5.2.1"
15
- gem "pg", "0.18.4"
16
- end
17
-
18
8
  appraise "rails-5.2_pg-1.2" do
19
9
  gem "activerecord", "5.2.1"
20
10
  gem "pg", "1.2.0"
21
11
  end
22
12
 
23
- appraise "rails-6.0_pg-0.18" do
24
- gem "activerecord", ">= 6.0.0", "< 6.1"
25
- gem "pg", "0.18.4"
26
- end
27
-
28
13
  appraise "rails-6.0_pg-1.1" do
29
14
  gem "activerecord", ">= 6.0.0", "< 6.1"
30
15
  gem "pg", "1.1.4"
@@ -44,3 +29,13 @@ appraise "rails-6.1_pg-1.2" do
44
29
  gem "activerecord", ">= 6.1.0", "< 6.2"
45
30
  gem "pg", "1.2.0"
46
31
  end
32
+
33
+ appraise "rails-7.0_pg-1.1" do
34
+ gem "activerecord", ">= 7.0.0", "< 7.1"
35
+ gem "pg", "1.1.4"
36
+ end
37
+
38
+ appraise "rails-7.0_pg-1.2" do
39
+ gem "activerecord", ">= 7.0.0", "< 7.1"
40
+ gem "pg", "1.2.0"
41
+ end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # activerecord-postgres_pub_sub
2
2
 
3
+ ## v2.2.0
4
+ - Add support for listening to multiple channels.
5
+
6
+ ## v2.1.0
7
+ - Set required ruby version to 2.7.0
8
+ - Add support for Rails 7.0
9
+
10
+ ## v2.0.1
11
+ - Fix version constraint on pg gem.
12
+ - Drop support for rails 5.1 as a result of pg constraint change.
13
+
3
14
  ## v2.0.0
4
15
  - Add support for Rails 6.1.
5
16
  - Drop support for pg 0.18 as support has been [dropped in activerecord 6.1](https://github.com/rails/rails/commit/592358e182effecebe8c6a4645bd4431f5a73654).
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![CircleCI](https://circleci.com/gh/ezcater/activerecord-postgres_pub_sub.svg?style=svg)](https://circleci.com/gh/ezcater/activerecord-postgres_pub_sub)
4
4
 
5
- This gem contains support for PostgreSQL LISTEN and NOTIFY functionality:
5
+ This gem contains support for PostgreSQL LISTEN and NOTIFY functionality:
6
6
  [doc](https://www.postgresql.org/docs/9.6/static/libpq-notify.html).
7
7
 
8
8
  ## Installation
@@ -25,7 +25,8 @@ Or install it yourself as:
25
25
 
26
26
  ### Listener
27
27
 
28
- The `Listener` class is used to handle notification messages.
28
+ The `Listener` class is used to handle notification messages on one or more
29
+ channels.
29
30
 
30
31
  The listener can be configured with three blocks:
31
32
 
@@ -33,13 +34,13 @@ The listener can be configured with three blocks:
33
34
  * **on_start**: called before receiving any notifications.
34
35
  * **on_timeout**: called based on a configurable timeout, when no notifications
35
36
  have been received.
36
-
37
+
37
38
  When creating a listener, the following configuration is supported:
38
39
 
39
- * **listen_timeout**: If set, the `on_timeout` block will be called if
40
- no notifications are received within this period. (Default `nil`).
40
+ * **listen_timeout**: If set, the `on_timeout` block will be called if
41
+ no notifications are received within this period. (Default `nil`).
41
42
  * **notify_only**: A payload string can be included in notifications. By default
42
- the listener ignores the payload and coalesces multiple notifications into a
43
+ the listener ignores the payload and coalesces multiple notifications into a
43
44
  single call. When this option is `false`, the `on_notify` block is called with
44
45
  the payload for each notification. (Default `true`).
45
46
  * **exclusive_lock**: Acquire a lock using
@@ -51,16 +52,16 @@ Example:
51
52
  ```ruby
52
53
  ActiveRecord::PostgresPubSub::Listener.listen("notify_channel", listen_timeout: 30) do |listener|
53
54
  listener.on_start do
54
- # when starting assume we missed something and perform regular activity
55
+ # when starting assume we missed something and perform regular activity
55
56
  handle_notification
56
57
  end
57
-
58
+
58
59
  listener.on_notify do
59
60
  handle_notification
60
61
  end
61
-
62
+
62
63
  listener.on_timeout do
63
- perform_regular_maintenance
64
+ perform_regular_maintenance
64
65
  end
65
66
  end
66
67
  ```
@@ -39,9 +39,10 @@ Gem::Specification.new do |spec|
39
39
  spec.bindir = "bin"
40
40
  spec.executables = []
41
41
  spec.require_paths = ["lib"]
42
+ spec.required_ruby_version = ">= 2.7.0"
42
43
 
43
- spec.add_runtime_dependency "activerecord", ">= 5.1", "< 6.2"
44
- spec.add_runtime_dependency "pg", ">= 0.18", "< 2.0"
44
+ spec.add_runtime_dependency "activerecord", "> 5.1", "< 7.1"
45
+ spec.add_runtime_dependency "pg", "~> 1.1"
45
46
  spec.add_runtime_dependency "private_attr"
46
47
  spec.add_runtime_dependency "with_advisory_lock"
47
48
 
@@ -49,7 +50,7 @@ Gem::Specification.new do |spec|
49
50
  spec.add_development_dependency "bundler", ">= 1.3.0"
50
51
  spec.add_development_dependency "database_cleaner"
51
52
  spec.add_development_dependency "ezcater_matchers"
52
- spec.add_development_dependency "ezcater_rubocop", "1.0.2"
53
+ spec.add_development_dependency "ezcater_rubocop", "~> 3.0"
53
54
  spec.add_development_dependency "overcommit"
54
55
  spec.add_development_dependency "rake", "~> 10.0"
55
56
  spec.add_development_dependency "rspec", "~> 3.4"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", ">= 7.0.0", "< 7.1"
6
+ gem "pg", "1.1.4"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", ">= 7.0.0", "< 7.1"
6
+ gem "pg", "1.2.0"
7
+
8
+ gemspec path: "../"
@@ -9,10 +9,10 @@ module ActiveRecord
9
9
  extend PrivateAttr
10
10
 
11
11
  private_attr_reader :on_notify_blk, :on_start_blk, :on_timeout_blk,
12
- :channel, :listen_timeout, :exclusive_lock, :notify_only
12
+ :channels, :listen_timeout, :exclusive_lock, :notify_only
13
13
 
14
- def self.listen(channel, listen_timeout: nil, exclusive_lock: true, notify_only: true)
15
- listener = new(channel,
14
+ def self.listen(*channels, listen_timeout: nil, exclusive_lock: true, notify_only: true)
15
+ listener = new(*channels,
16
16
  listen_timeout: listen_timeout,
17
17
  exclusive_lock: exclusive_lock,
18
18
  notify_only: notify_only)
@@ -20,8 +20,8 @@ module ActiveRecord
20
20
  listener.listen
21
21
  end
22
22
 
23
- def initialize(channel, listen_timeout: nil, exclusive_lock: true, notify_only: true)
24
- @channel = channel
23
+ def initialize(*channels, listen_timeout: nil, exclusive_lock: true, notify_only: true)
24
+ @channels = channels
25
25
  @listen_timeout = listen_timeout
26
26
  @exclusive_lock = exclusive_lock
27
27
  @notify_only = notify_only
@@ -44,8 +44,8 @@ module ActiveRecord
44
44
  on_start_blk&.call
45
45
 
46
46
  loop do
47
- wait_for_notify(connection) do |payload|
48
- notify_only ? on_notify_blk.call : on_notify_blk.call(payload)
47
+ wait_for_notify(connection) do |payload, channel|
48
+ notify_only ? on_notify_blk.call : on_notify_blk.call(payload, channel)
49
49
  end
50
50
  end
51
51
  end
@@ -56,27 +56,31 @@ module ActiveRecord
56
56
  def with_connection
57
57
  ActiveRecord::Base.connection_pool.with_connection do |connection|
58
58
  with_optional_lock do
59
- connection.execute("LISTEN #{channel}")
59
+ channels.each do |channel|
60
+ connection.execute("LISTEN #{channel};")
61
+ end
60
62
 
61
63
  begin
62
64
  yield(connection)
63
65
  ensure
64
- connection.execute("UNLISTEN #{channel}")
66
+ channels.each do |channel|
67
+ connection.execute("UNLISTEN #{channel}")
68
+ end
65
69
  end
66
70
  end
67
71
  end
68
72
  end
69
73
 
70
- def with_optional_lock
74
+ def with_optional_lock(&block)
71
75
  if exclusive_lock
72
- ActiveRecord::Base.with_advisory_lock(lock_name) { yield }
76
+ ActiveRecord::Base.with_advisory_lock(lock_name, &block)
73
77
  else
74
78
  yield
75
79
  end
76
80
  end
77
81
 
78
82
  def lock_name
79
- "#{channel}-listener"
83
+ "#{channels.join('-')}-listener"
80
84
  end
81
85
 
82
86
  def empty_channel(connection)
@@ -87,10 +91,11 @@ module ActiveRecord
87
91
 
88
92
  def wait_for_notify(connection)
89
93
  connection_pid = connection.raw_connection.backend_pid
90
- event_result = connection.raw_connection.wait_for_notify(listen_timeout) do |_event, pid, payload|
94
+ event_result = connection.raw_connection.wait_for_notify(listen_timeout) do |notify_channel, pid, payload|
91
95
  if pid != connection_pid
92
96
  empty_channel(connection.raw_connection) if notify_only
93
- yield(payload)
97
+
98
+ yield(payload, notify_channel)
94
99
  end
95
100
  end
96
101
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module PostgresPubSub
5
- VERSION = "2.0.0"
5
+ VERSION = "2.2.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,55 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgres_pub_sub
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ezCater, Inc
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-20 00:00:00.000000000 Z
11
+ date: 2022-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5.1'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.2'
22
+ version: '7.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ">="
27
+ - - ">"
28
28
  - !ruby/object:Gem::Version
29
29
  version: '5.1'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.2'
32
+ version: '7.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: pg
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: '0.18'
40
- - - "<"
37
+ - - "~>"
41
38
  - !ruby/object:Gem::Version
42
- version: '2.0'
39
+ version: '1.1'
43
40
  type: :runtime
44
41
  prerelease: false
45
42
  version_requirements: !ruby/object:Gem::Requirement
46
43
  requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: '0.18'
50
- - - "<"
44
+ - - "~>"
51
45
  - !ruby/object:Gem::Version
52
- version: '2.0'
46
+ version: '1.1'
53
47
  - !ruby/object:Gem::Dependency
54
48
  name: private_attr
55
49
  requirement: !ruby/object:Gem::Requirement
@@ -138,16 +132,16 @@ dependencies:
138
132
  name: ezcater_rubocop
139
133
  requirement: !ruby/object:Gem::Requirement
140
134
  requirements:
141
- - - '='
135
+ - - "~>"
142
136
  - !ruby/object:Gem::Version
143
- version: 1.0.2
137
+ version: '3.0'
144
138
  type: :development
145
139
  prerelease: false
146
140
  version_requirements: !ruby/object:Gem::Requirement
147
141
  requirements:
148
- - - '='
142
+ - - "~>"
149
143
  - !ruby/object:Gem::Version
150
- version: 1.0.2
144
+ version: '3.0'
151
145
  - !ruby/object:Gem::Dependency
152
146
  name: overcommit
153
147
  requirement: !ruby/object:Gem::Requirement
@@ -240,6 +234,8 @@ files:
240
234
  - gemfiles/rails_6.0_pg_1.2.gemfile
241
235
  - gemfiles/rails_6.1_pg_1.1.gemfile
242
236
  - gemfiles/rails_6.1_pg_1.2.gemfile
237
+ - gemfiles/rails_7.0_pg_1.1.gemfile
238
+ - gemfiles/rails_7.0_pg_1.2.gemfile
243
239
  - lib/activerecord-postgres_pub_sub.rb
244
240
  - lib/activerecord/postgres_pub_sub/listener.rb
245
241
  - lib/activerecord/postgres_pub_sub/version.rb
@@ -250,7 +246,7 @@ licenses:
250
246
  - MIT
251
247
  metadata:
252
248
  allowed_push_host: https://rubygems.org
253
- post_install_message:
249
+ post_install_message:
254
250
  rdoc_options: []
255
251
  require_paths:
256
252
  - lib
@@ -258,15 +254,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
258
254
  requirements:
259
255
  - - ">="
260
256
  - !ruby/object:Gem::Version
261
- version: '0'
257
+ version: 2.7.0
262
258
  required_rubygems_version: !ruby/object:Gem::Requirement
263
259
  requirements:
264
260
  - - ">="
265
261
  - !ruby/object:Gem::Version
266
262
  version: '0'
267
263
  requirements: []
268
- rubygems_version: 3.0.3
269
- signing_key:
264
+ rubygems_version: 3.1.4
265
+ signing_key:
270
266
  specification_version: 4
271
267
  summary: Support for Postgres Notify/Listen
272
268
  test_files: []