Skip to content

Commit 769d0c6

Browse files
authored
Merge pull request #5 from macielti/release/3.2.0-postgresql-retry
release 3.2.0: retry PostgreSQL pool and migrations with diehard
2 parents 94b0036 + 07b8585 commit 769d0c6

4 files changed

Lines changed: 23 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
All notable changes to this project will be documented in this file. This change log follows the conventions
44
of [keepachangelog.com](http://keepachangelog.com/).
55

6+
## 3.2.0 - 2026-04-21
7+
8+
### Added
9+
10+
- Retry logic via `diehard` when initializing the PostgreSQL pool and running migrations, so the components tolerate the database being briefly unavailable during container startup. Uses exponential backoff (1s → capped at 15s) with up to 3 retries.
11+
612
## 3.1.0 - 2026-04-19
713

814
### Added

project.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject net.clojars.macielti/postgresql "3.1.0"
1+
(defproject net.clojars.macielti/postgresql "3.2.0"
22

33
:description "PostgreSQL Component"
44

@@ -17,7 +17,8 @@
1717
[com.github.igrishaev/pg2-migration "0.1.48"]
1818
[org.clojure/tools.logging "1.3.1"]
1919
[integrant "1.0.1"]
20-
[prismatic/schema "1.4.1"]]
20+
[prismatic/schema "1.4.1"]
21+
[diehard "0.12.0"]]
2122

2223
:resource-paths ["resources"]
2324

src/postgresql/component.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns postgresql.component
22
(:require [clojure.tools.logging :as log]
3+
[diehard.core :as dh]
34
[integrant.core :as ig]
45
[pg.core])
56
(:import (org.pg Pool)))
@@ -10,7 +11,12 @@
1011
[_ {:keys [components]}]
1112
(log/info :starting ::postgresql)
1213
(let [postgresql-config (-> components :config :postgresql)
13-
pool (pg.core/pool postgresql-config)]
14+
pool (dh/with-retry {:max-retries 3
15+
:backoff-ms [1000 15000]
16+
:retry-on Exception
17+
:on-retry (fn [_ _]
18+
(log/warn :retrying-postgresql-pool))}
19+
(pg.core/pool postgresql-config))]
1420
pool))
1521

1622
(defmethod ig/halt-key! ::postgresql

src/postgresql/migrations.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns postgresql.migrations
22
(:require [clojure.tools.logging :as log]
3+
[diehard.core :as dh]
34
[integrant.core :as ig]
45
[pg.migration.core :as migrations]))
56

@@ -9,7 +10,12 @@
910
(let [postgresql-config (-> components :config :postgresql)
1011
migrations-config (-> components :config :postgresql-migrations)
1112
configuration (merge postgresql-config migrations-config)]
12-
(migrations/migrate-all configuration)))
13+
(dh/with-retry {:max-retries 3
14+
:backoff-ms [1000 15000]
15+
:retry-on Exception
16+
:on-retry (fn [_ _]
17+
(log/warn :retrying-postgresql-migrations))}
18+
(migrations/migrate-all configuration))))
1319

1420
(defmethod ig/halt-key! ::postgresql-migrations
1521
[_ _]

0 commit comments

Comments
 (0)