Skip to content

Recreate job notification triggers after PGListener reconnects#2458

Merged
mpscholten merged 2 commits intomasterfrom
fix/job-queue-reconnect-triggers
Feb 19, 2026
Merged

Recreate job notification triggers after PGListener reconnects#2458
mpscholten merged 2 commits intomasterfrom
fix/job-queue-reconnect-triggers

Conversation

@mpscholten
Copy link
Member

Summary

  • Adds a reconnection callback mechanism to PGListener that fires after connection recovery, giving callers the live Hasql.Connection to run SQL directly
  • Job queue registers a callback to recreate its pg_notify triggers on reconnect, fixing ~40s delays after make db drops the database
  • Adds debug logging to the pg_notify subscription callback for better observability

Context

After make db drops and recreates the database, the notification triggers that fire pg_notify are destroyed. PGListener reconnects and re-LISTENs correctly, but without triggers pg_notify never fires. Jobs are only picked up by the 60-second poller (average ~30-40s delay).

Fixes: https://github.com/amitaibu/ihp-sensors/issues/18

Test plan

  • Type-checks: ihp-pglistener/IHP/PGListener.hs and ihp/IHP/Job/Queue.hs
  • All 361 IDE tests pass
  • Manual: run make db while job worker is running, verify jobs are picked up immediately via pg_notify (not delayed by poller)

🤖 Generated with Claude Code

After `make db` drops and recreates the database, pg_notify triggers are
destroyed. PGListener reconnects and re-LISTENs correctly, but without
triggers pg_notify never fires, causing ~40s delays until the poller
picks up jobs.

Add a reconnection callback mechanism to PGListener that fires after
connection recovery. The job queue registers a callback to recreate its
notification triggers on the PGListener's own connection, avoiding pool
staleness issues.

Fixes: amitaibu/ihp-sensors#18

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 628db0fba3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Addresses review feedback: HasqlConnection.use can fail transiently
(e.g. if the job table doesn't exist yet during reconnect). Log warnings
on failure and info on success instead of silently discarding the result.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@amitaibu
Copy link
Collaborator

I'll try this PR on my repo

@mpscholten mpscholten merged commit 7ff7d90 into master Feb 19, 2026
1 check passed
@mpscholten mpscholten deleted the fix/job-queue-reconnect-triggers branch February 19, 2026 19:29
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.

2 participants

Comments