From e497d540f74f4f34bbab5536b861a414ef5a6d49 Mon Sep 17 00:00:00 2001 From: TzeYiing Date: Thu, 17 Apr 2025 17:39:52 +0800 Subject: [PATCH 1/3] fix: add in new >v0.18 ssl option configuration, add auto-reconnect for notifications --- README.md | 6 +++--- lib/strategy.ex | 9 ++++++--- mix.exs | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 69e66d3..a66acab 100644 --- a/README.md +++ b/README.md @@ -41,17 +41,17 @@ config :libcluster, port: 5432, # optional, connection parameters. Defaults to [] parameters: [], - # optional, defaults to false + # optional, defaults to false. Refer to Postgrex docs ssl: true, # optional, please refer to the Postgrex docs - ssl_opts: nil, - # optional, please refer to the Postgrex docs socket_options: nil, # optional, defaults to node cookie # must be a valid postgres identifier (alphanumeric and underscores only) with valid length channel_name: "cluster", # optional, heartbeat interval in ms. defaults to 5s heartbeat_interval: 10_000 + # optional, auto-reconnect to notifications, defaults to true + auto_reconnect: false ], ] ] diff --git a/lib/strategy.ex b/lib/strategy.ex index bff79e5..b8d742b 100644 --- a/lib/strategy.ex +++ b/lib/strategy.ex @@ -26,17 +26,20 @@ defmodule LibclusterPostgres.Strategy do def init([state]) do channel_name = Keyword.get(state.config, :channel_name, clean_cookie(Node.get_cookie())) + ssl = if ssl_value = Keyword.get(state.config, :ssl) do + Keyword.get(state.config, :ssl_opts) || ssl_value + end opts = [ hostname: Keyword.fetch!(state.config, :hostname), username: Keyword.fetch!(state.config, :username), password: Keyword.fetch!(state.config, :password), database: Keyword.fetch!(state.config, :database), port: Keyword.fetch!(state.config, :port), - ssl: Keyword.get(state.config, :ssl), - ssl_opts: Keyword.get(state.config, :ssl_opts), + ssl: ssl, socket_options: Keyword.get(state.config, :socket_options, []), parameters: Keyword.get(state.config, :parameters, []), - channel_name: channel_name + channel_name: channel_name, + auto_reconnect: Keyword.get(state.config, :auto_reconnect, true) ] config = diff --git a/mix.exs b/mix.exs index be837f2..5ae783a 100644 --- a/mix.exs +++ b/mix.exs @@ -5,7 +5,7 @@ defmodule LibclusterPostgres.MixProject do [ name: "libcluster_postgres", app: :libcluster_postgres, - version: "0.1.3", + version: "0.2.0", elixir: "~> 1.14", start_permanent: Mix.env() == :prod, deps: deps(), @@ -27,7 +27,7 @@ defmodule LibclusterPostgres.MixProject do defp deps do [ {:libcluster, "~> 3.3"}, - {:postgrex, ">= 0.0.0"}, + {:postgrex, ">= 0.18.0"}, {:ex_doc, ">= 0.0.0", only: :dev, runtime: false} ] end From 5e00f9e741427eebd8f92cf5192e6b6b98ba2d3e Mon Sep 17 00:00:00 2001 From: TzeYiing Date: Thu, 17 Apr 2025 17:41:57 +0800 Subject: [PATCH 2/3] docs: add more ssl docs --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a66acab..989d0a3 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ config :libcluster, # optional, connection parameters. Defaults to [] parameters: [], # optional, defaults to false. Refer to Postgrex docs + # as of v0.18 postgrex, accepts `true` or a keyword list of options ssl: true, # optional, please refer to the Postgrex docs socket_options: nil, From a052af75f4cc96d9b8cd8e49c65a27e44bd6bd43 Mon Sep 17 00:00:00 2001 From: TzeYiing Date: Thu, 17 Apr 2025 17:46:13 +0800 Subject: [PATCH 3/3] chore: formatting --- lib/strategy.ex | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/strategy.ex b/lib/strategy.ex index b8d742b..769d724 100644 --- a/lib/strategy.ex +++ b/lib/strategy.ex @@ -26,9 +26,11 @@ defmodule LibclusterPostgres.Strategy do def init([state]) do channel_name = Keyword.get(state.config, :channel_name, clean_cookie(Node.get_cookie())) - ssl = if ssl_value = Keyword.get(state.config, :ssl) do - Keyword.get(state.config, :ssl_opts) || ssl_value - end + ssl = + if ssl_value = Keyword.get(state.config, :ssl) do + Keyword.get(state.config, :ssl_opts) || ssl_value + end + opts = [ hostname: Keyword.fetch!(state.config, :hostname), username: Keyword.fetch!(state.config, :username),