- worker: sends email_outbox mail over SMTP (lettre), woken by LISTEN/NOTIFY, SKIP LOCKED claiming, retries with backoff, hu/en templates (text + HTML), hourly cleanup of expired data - migration 0002: next_attempt_at, failed_at, notify trigger - docker-compose.override.yml: Mailpit for development only - Dockerfiles: lock shared cargo cache mounts for parallel builds Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
22 lines
717 B
PL/PgSQL
22 lines
717 B
PL/PgSQL
-- E-mail delivery by the worker: retries with backoff, permanent failure,
|
|
-- and a notification so the worker sends new e-mails right away.
|
|
|
|
ALTER TABLE email_outbox
|
|
ADD COLUMN next_attempt_at timestamptz NOT NULL DEFAULT now(),
|
|
ADD COLUMN failed_at timestamptz;
|
|
|
|
DROP INDEX email_outbox_unsent_idx;
|
|
CREATE INDEX email_outbox_due_idx ON email_outbox (next_attempt_at)
|
|
WHERE sent_at IS NULL AND failed_at IS NULL;
|
|
|
|
CREATE FUNCTION notify_email_outbox() RETURNS trigger LANGUAGE plpgsql AS $$
|
|
BEGIN
|
|
PERFORM pg_notify('email_outbox', '');
|
|
RETURN NULL;
|
|
END;
|
|
$$;
|
|
|
|
CREATE TRIGGER email_outbox_notify
|
|
AFTER INSERT ON email_outbox
|
|
FOR EACH STATEMENT EXECUTE FUNCTION notify_email_outbox();
|