Skip to main content

Module credit_registration_account_linking_emails

Module credit_registration_account_linking_emails 

Source
Expand description

Dedup ledger for account-linking mails.

Keyed on the Sisu person id plus the recipient address: at send time there is no account of ours to key on, and the student number changes when a student moves between programmes. A row is written when the right to mail is claimed, before a delivery exists, so a crash between the two phases cannot mail twice.

Structs§

CreditRegistrationAccountLinkingEmail
ExistingLinkingMailFact
As much of one existing mail as the dedup guard and the rate caps need to decide on a person.
LinkingMailFailureDomain
LinkingMailSendStatusTotals
Every mail in a window, bucketed the way crate::email_deliveries::derive_email_send_status does. Computed in SQL from the same facts rather than from its output, so the two cannot drift on what counts as failed.
LinkingMailToQueue
A claimed slot with no delivery yet, and everything the mail needs to be written.
NewAccountLinkingEmail
StaleUnclaimedLinkingMails
One person and course mailed to the cap without a single claim: the stale-address population, which is how “the student is ignoring us” is told from “the address Sisu holds is dead”.

Functions§

claim_send_slot
Claims the right to mail this (person, course, address) once; None means the caller must not send. Call in the transaction that mints the token, so a refused claim leaves no usable link.
claim_send_slots
Batched form of claim_send_slot, keyed by token: returns the student_number_verification_token_id of every row actually inserted, so the caller can tell which candidates lost the race to the unique index.
claim_unqueued
Claims slots whose mail has not been queued yet, oldest first.
count_send_failed_for_course
Hard send failures for one course, all time. Same predicate as get_send_status_totals_since, narrowed to a course instead of a time window.
count_sent_for_person_and_course
How many mails this person has had for this course, tokens that expired unused included. Read against the lifetime cap when an admin asks for a resend.
count_sent_since
Mails claimed in the window, whatever course they belong to. One row is one address, which is what the send-rate caps govern.
get_by_course_id_and_student_number
This course’s linking mails for one student number, newest first.
get_by_sisu_person_id
get_existing_facts_for_persons
Every live mail these people have ever been sent, any course: one query stands in for the quiet-period count, the per-course count and the dedup check of a whole batch of candidates.
get_latest_by_course_and_persons
This course’s newest linking mail for each of these Sisu people, keyed by person id.
get_send_failure_domains_since
Domains behind a hard send failure in the window, worst first. Same predicate as get_send_status_totals_since, enforced by both calling crate::email_deliveries::is_hard_send_failure rather than each repeating the condition.
get_send_status_reports
What we can honestly say about each linking mail. A slot with no delivery yet is queued: anything else would claim a send attempt that never happened.
get_send_status_totals_since
get_sent_since
Mails claimed in the window, newest first, whatever course they belong to.
get_stale_unclaimed
not_handed_over_yet
What a claimed slot with no delivery reports. Public so a caller falling back to a default says the same thing get_send_status_reports would have.
set_email_delivery_id
Records which delivery carries this mail, which is also what takes the slot out of the queue.
soft_delete
Lets a rate-cap override or an admin resend mail the same address again.
soft_delete_batch
Batch form of soft_delete: one UPDATE for every row instead of one per id.