Skip to content

Conversation

@azygis
Copy link
Collaborator

@azygis azygis commented Dec 10, 2025

Added support for resilient startup in PostgreSqlStorage, introducing retry logic with exponential backoff and configurable degraded mode when connecting to the database during initialization. The storage can now optionally allow the application to start even if the database is temporarily unavailable, and will re-attempt initialization on first use.

Fixes #414.

@azygis azygis requested a review from Copilot December 10, 2025 10:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements resilient startup for PostgreSqlStorage, allowing the application to gracefully handle transient database connectivity issues during initialization. The key changes introduce retry logic with exponential backoff, configurable degraded mode, and lazy initialization on first use.

Key Changes:

  • Added retry mechanism with exponential backoff for database connection during storage initialization
  • Introduced degraded mode that allows applications to start even when the database is temporarily unavailable
  • Implemented lazy initialization that re-attempts connection on first storage use

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/Hangfire.PostgreSql/PostgreSqlStorageOptions.cs Added configuration properties for resilient startup including retry limits, backoff delays, and degraded mode flag
src/Hangfire.PostgreSql/PostgreSqlStorage.cs Refactored initialization logic to support retries, exponential backoff, and lazy initialization with proper thread safety
tests/Hangfire.PostgreSql.Tests/PostgreSqlStorageOptionsFacts.cs Added tests verifying default resilient startup options and computed property behavior
tests/Hangfire.PostgreSql.Tests/PostgreSqlStorageFacts.cs Added tests for retry behavior and degraded mode scenarios
tests/Hangfire.PostgreSql.Tests/Utils/DelegateConnectionFactory.cs Added test utility to simulate connection failures
README.md Added comprehensive documentation explaining resilient startup feature, configuration options, and usage examples

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@azygis azygis merged commit 48c6e51 into master Dec 10, 2025
2 checks passed
github-merge-queue bot pushed a commit to DFE-Digital/teaching-record-system that referenced this pull request Dec 12, 2025
Updated
[Hangfire.PostgreSql](https://github.com/frankhommers/Hangfire.PostgreSql)
from 1.20.12 to 1.20.13.

<details>
<summary>Release notes</summary>

_Sourced from [Hangfire.PostgreSql's
releases](https://github.com/frankhommers/Hangfire.PostgreSql/releases)._

## 1.20.13

## What's Changed
* Use EXECUTE for index creation for compatibility with older PostgreSQL
versions. by @​sake12 in
hangfire-postgres/Hangfire.PostgreSql#405
* Implemented resilient startup by @​azygis in
hangfire-postgres/Hangfire.PostgreSql#415

## New Contributors
* @​sake12 made their first contribution in
hangfire-postgres/Hangfire.PostgreSql#405

**Full Changelog**:
hangfire-postgres/Hangfire.PostgreSql@1.20.12...1.20.13

Commits viewable in [compare
view](hangfire-postgres/Hangfire.PostgreSql@1.20.12...1.20.13).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Hangfire.PostgreSql&package-manager=nuget&previous-version=1.20.12&new-version=1.20.13)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Application crashes on startup when the job storage (PostgreSQL) is unreachable - Resilient Initialization

2 participants