activerecord-postgres_pub_sub 2.1.0 → 2.3.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: dbcb38025bb4b4992bb6a8d7ed1b2c1288fcc9b3df9c3bc4459a9be8ce7e96bd
4
- data.tar.gz: fefad9359ecce30c1198a3c34e2c64ebb9993b797e2ff7320dd47ae23e6dfa2f
3
+ metadata.gz: ab5807899dcfd7a9aa7b51233366b26742bee55276024aeb92c796e1fe6ef59b
4
+ data.tar.gz: 3e7a055319a847476d2c3f32bca43245cdf1d9f633ab3142b365ce0f3a2d9a1f
5
5
  SHA512:
6
- metadata.gz: ce692f2b1d176e51767ca21d679d8b618a84e9c029cd5f70e4430e32dec6ba6d9d9c226945c25530125d4e7f7692f7ab049673117aa0c86f3ed8bfdae08ef3d6
7
- data.tar.gz: 7166ae680431461ea81a0e44e0d3f8b0b26607255d23869417c2c59c98a74a04ba75c783e7682c576a8c4de9b305d0d9906e36fe433e11fe6ff8c979adc57d03
6
+ metadata.gz: d7b51388aaddb2ed46258e3515a0a49b6f30413701b899c2b6f725cbf2e44f18a7257c71fa7dd864493c716f49bfaed06e5080735c4e17ec4b0efca0cf5391d2
7
+ data.tar.gz: 1f87512ac9faef62475c133f288d39e2f46e7d6a465b37c19556e21976dff57be72e898b3a0ffac8000a0dc8956a119d8f6aaa3295fbbaec3eaba859d22ebd16
@@ -0,0 +1,71 @@
1
+ name: "CodeQL"
2
+
3
+ on:
4
+ push:
5
+ branches: [ "main" ]
6
+ pull_request:
7
+ # The branches below must be a subset of the branches above
8
+ branches: [ "main" ]
9
+ # https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning#avoiding-unnecessary-scans-of-pull-requests
10
+ paths-ignore:
11
+ - '**/*.md'
12
+ - '**/*.txt'
13
+ schedule:
14
+ - cron: '41 22 * * 2'
15
+
16
+ jobs:
17
+ scan:
18
+ name: Scan
19
+ runs-on: [ ubuntu-latest ]
20
+ permissions:
21
+ actions: read
22
+ contents: read
23
+ security-events: write
24
+
25
+ strategy:
26
+ # Setting fail-fast to false to prevent a failed scan in
27
+ # any of the matrix.language's from stopping the other scans
28
+ # If there are multiple offenses, better to find/report them
29
+ # all at once
30
+ fail-fast: false
31
+ matrix:
32
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
33
+ # https://aka.ms/codeql-docs/language-support
34
+ language: [ 'ruby' ]
35
+
36
+
37
+ steps:
38
+ - name: Checkout repository
39
+ uses: actions/checkout@v3
40
+
41
+ # Initializes the CodeQL tools for scanning.
42
+ - name: Initialize CodeQL
43
+ uses: github/codeql-action/init@v2
44
+ with:
45
+ languages: ${{ matrix.language }}
46
+ # If you wish to specify custom queries, you can do so here or in a config file.
47
+ # By default, queries listed here will override any specified in a config file.
48
+ # Prefix the list here with "+" to use these queries and those in the config file.
49
+
50
+ # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
51
+ # queries: security-extended,security-and-quality
52
+
53
+ # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
54
+ # If this step fails, then you should remove it and run the build manually (see below)
55
+ - name: Autobuild
56
+ uses: github/codeql-action/autobuild@v2
57
+
58
+ # ℹ️ Command-line programs to run using the OS shell.
59
+ # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
60
+
61
+ # If the Autobuild fails above, remove it and uncomment the following three lines.
62
+ # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
63
+
64
+ # - run: |
65
+ # echo "Run, Build Application using script"
66
+ # ./location_of_script_within_repo/buildscript.sh
67
+
68
+ - name: Perform CodeQL Analysis
69
+ uses: github/codeql-action/analyze@v2
70
+ with:
71
+ category: "/language:${{matrix.language}}"
data/Appraisals CHANGED
@@ -39,3 +39,13 @@ appraise "rails-7.0_pg-1.2" do
39
39
  gem "activerecord", ">= 7.0.0", "< 7.1"
40
40
  gem "pg", "1.2.0"
41
41
  end
42
+
43
+ appraise "rails-7.1_pg-1.1" do
44
+ gem "activerecord", ">= 7.1.0", "< 7.2"
45
+ gem "pg", "1.1.4"
46
+ end
47
+
48
+ appraise "rails-7.1_pg-1.2" do
49
+ gem "activerecord", ">= 7.1.0", "< 7.2"
50
+ gem "pg", "1.2.0"
51
+ end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # activerecord-postgres_pub_sub
2
2
 
3
+ ## v2.3.0
4
+ - Add support for Rails 7.1
5
+
6
+ ## v2.2.0
7
+ - Add support for listening to multiple channels.
8
+
3
9
  ## v2.1.0
4
10
  - Set required ruby version to 2.7.0
5
11
  - Add support for Rails 7.0
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # activerecord-postgres_pub_sub
2
2
 
3
- [![CircleCI](https://circleci.com/gh/ezcater/activerecord-postgres_pub_sub.svg?style=svg)](https://circleci.com/gh/ezcater/activerecord-postgres_pub_sub)
4
-
5
- This gem contains support for PostgreSQL LISTEN and NOTIFY functionality:
3
+ This gem contains support for PostgreSQL LISTEN and NOTIFY functionality:
6
4
  [doc](https://www.postgresql.org/docs/9.6/static/libpq-notify.html).
7
5
 
8
6
  ## Installation
@@ -25,7 +23,8 @@ Or install it yourself as:
25
23
 
26
24
  ### Listener
27
25
 
28
- The `Listener` class is used to handle notification messages.
26
+ The `Listener` class is used to handle notification messages on one or more
27
+ channels.
29
28
 
30
29
  The listener can be configured with three blocks:
31
30
 
@@ -33,13 +32,13 @@ The listener can be configured with three blocks:
33
32
  * **on_start**: called before receiving any notifications.
34
33
  * **on_timeout**: called based on a configurable timeout, when no notifications
35
34
  have been received.
36
-
35
+
37
36
  When creating a listener, the following configuration is supported:
38
37
 
39
- * **listen_timeout**: If set, the `on_timeout` block will be called if
40
- no notifications are received within this period. (Default `nil`).
38
+ * **listen_timeout**: If set, the `on_timeout` block will be called if
39
+ no notifications are received within this period. (Default `nil`).
41
40
  * **notify_only**: A payload string can be included in notifications. By default
42
- the listener ignores the payload and coalesces multiple notifications into a
41
+ the listener ignores the payload and coalesces multiple notifications into a
43
42
  single call. When this option is `false`, the `on_notify` block is called with
44
43
  the payload for each notification. (Default `true`).
45
44
  * **exclusive_lock**: Acquire a lock using
@@ -51,16 +50,16 @@ Example:
51
50
  ```ruby
52
51
  ActiveRecord::PostgresPubSub::Listener.listen("notify_channel", listen_timeout: 30) do |listener|
53
52
  listener.on_start do
54
- # when starting assume we missed something and perform regular activity
53
+ # when starting assume we missed something and perform regular activity
55
54
  handle_notification
56
55
  end
57
-
56
+
58
57
  listener.on_notify do
59
58
  handle_notification
60
59
  end
61
-
60
+
62
61
  listener.on_timeout do
63
- perform_regular_maintenance
62
+ perform_regular_maintenance
64
63
  end
65
64
  end
66
65
  ```
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
22
  end
23
23
 
24
- excluded_files = %w(.circleci/config.yml
24
+ excluded_files = %w(.github/workflows/ci.yml
25
25
  .github/PULL_REQUEST_TEMPLATE.md
26
26
  .gitignore
27
27
  .rspec
@@ -41,7 +41,7 @@ Gem::Specification.new do |spec|
41
41
  spec.require_paths = ["lib"]
42
42
  spec.required_ruby_version = ">= 2.7.0"
43
43
 
44
- spec.add_runtime_dependency "activerecord", "> 5.1", "< 7.1"
44
+ spec.add_runtime_dependency "activerecord", "> 5.1", "< 7.2"
45
45
  spec.add_runtime_dependency "pg", "~> 1.1"
46
46
  spec.add_runtime_dependency "private_attr"
47
47
  spec.add_runtime_dependency "with_advisory_lock"
@@ -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,12 +56,16 @@ 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
@@ -76,7 +80,7 @@ module ActiveRecord
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.1.0"
5
+ VERSION = "2.3.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgres_pub_sub
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.3.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: 2022-02-23 00:00:00.000000000 Z
11
+ date: 2023-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '5.1'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7.1'
22
+ version: '7.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '5.1'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7.1'
32
+ version: '7.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: pg
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -219,6 +219,7 @@ executables: []
219
219
  extensions: []
220
220
  extra_rdoc_files: []
221
221
  files:
222
+ - ".github/workflows/codeql.yml"
222
223
  - Appraisals
223
224
  - CHANGELOG.md
224
225
  - Gemfile
@@ -246,7 +247,7 @@ licenses:
246
247
  - MIT
247
248
  metadata:
248
249
  allowed_push_host: https://rubygems.org
249
- post_install_message:
250
+ post_install_message:
250
251
  rdoc_options: []
251
252
  require_paths:
252
253
  - lib
@@ -262,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
262
263
  version: '0'
263
264
  requirements: []
264
265
  rubygems_version: 3.1.6
265
- signing_key:
266
+ signing_key:
266
267
  specification_version: 4
267
268
  summary: Support for Postgres Notify/Listen
268
269
  test_files: []