Skip to main content

transition

Function transition 

Source
pub async fn transition(
    conn: &mut PgConnection,
    id: Uuid,
    transition: &Transition,
) -> ModelResult<CreditRegistration>
Expand description

Moves a ledger row to a new state and appends the matching audit event, atomically.

The only writer of state, and the one place (from → to) legality is decided: an edge outside the transition’s TransitionPolicy is refused as InvalidRequest rather than written. A row no longer in expected_from_state is refused as PreconditionFailed; a caller that has to tell that apart from a real failure uses transition_unless_moved_on instead.

Owns the lifecycle stamps, so callers must not touch them (bar reset_for_resubmission clearing first_failed_at): state_entered_at, terminal_at, first_failed_at and submit_retry_count, which starting to wait for an enrolment clears, registered_at, submitted_at, enrolment_checked_at, enrolment_banner_dismissed_at, which starting to wait for an enrolment clears, no_usable_enrolment_since, and next_attempt_at, which takes the target state’s default cadence unless the caller names a time. Leaving the wait for an enrolment also clears the check schedule, but not enrolment_check_group, and every move clears the claim of an enrolment check. Returns the row as written.