Skip to main content

Notifications

scheduled_notifications queue for emails and reminders.
2 min read

Sources: 000009_scheduled_notifications.up.sql and 000033_qstash_delivery.up.sql.

scheduled_notifications#

ColumnTypeNotes
idUUID PK
profile_idUUID → profiles CASCADE
user_idUUID → usersRecipient
domainTEXTProduct domain
entity_type / entity_idTEXTSource entity
kindTEXTDefault email_reminder
send_atTIMESTAMPTZWhen to send
timezoneTEXTDefault UTC
payloadJSONBDefault {}
statusTEXTDefault pending
idempotency_keyTEXT UNIQUEPrevents duplicates
attempt_countINT
last_errorTEXT
sent_atTIMESTAMPTZ
qstash_message_idTEXTPublished message; nullable until publish
qstash_deduplication_idTEXTCurrent delivery generation (no :; QStash rejects it)
qstash_published_atTIMESTAMPTZLast successful publish
qstash_publish_attempt_countINTPublish attempts for the generation
qstash_last_errorTEXTLast QStash infrastructure failure
created_at / updated_atTIMESTAMPTZ

Indexes#

  • Due: (status, send_at) WHERE pending
  • Entity: (domain, entity_type, entity_id)
  • QStash publish: (send_at, created_at) WHERE pending and without a message id

Relation to domain#

*_scheduled_job_id fields on tasks, activities, reminders, library, finance recurring, etc. coordinate with this queue / jobs.

Postgres is the source of truth. QStash only wakes the exact callback: the handler claims the row if id, status, and qstash_deduplication_id are still current. Rescheduling, canceling, or retrying rotates the generation, so an old callback is a no-op.

Go domain: internal/notifications.