rivianexpiry

package
v0.41.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package rivianexpiry warns about a Rivian session before it expires.

Rivian ends a user session 180 days after sign-in and gives the app no way to extend it (see rivian.SessionLifetime), so a user who never signs in again loses recording on that day, silently. The sweep finds sessions with at most 14 days left, counts them for the metric, and emails each user once at 7 days and once at 1 day left. It is read-only on the sessions; the notices are claimed in engagement_sends so each goes out at most once across replicas and restarts, and a new sign-in (a new session time) starts over.

Index

Constants

View Source
const (
	WarnDays  = 7
	FinalDays = 1
	CountDays = 14
)

Horizons, in days left.

View Source
const Kind = "rivian_expiry"

Kind is the engagement_sends kind of the notices.

View Source
const UnsubPurpose = "rivian-expiry"

UnsubPurpose scopes a signed one-click link to these reminders: the statement email's unsubscribe accepts only YYYY-MM and the welcome and setup emails' only "onboarding".

Variables

This section is empty.

Functions

This section is empty.

Types

type Counts

type Counts struct {
	Within14, Within7, Within1, Expired int
}

Counts is what a sweep saw.

type Entry

type Entry struct {
	User        uuid.UUID
	NeedsReauth bool
	// OptedOut: the user stopped these reminders (Settings, or the link in the email).
	OptedOut bool
	// SignedIn is when the stored Rivian session was made (users.rivian_signed_in_at); zero when
	// unknown. The sweep never opens the session itself.
	SignedIn time.Time
}

Entry is a user with a stored Rivian session.

func (Entry) ExpiresAt added in v0.40.9

func (e Entry) ExpiresAt(lifetime time.Duration) time.Time

ExpiresAt is when the session is expected to stop working: the sign-in plus lifetime; zero when the sign-in time is unknown.

type Job

type Job struct {
	Sessions Sessions
	Claims   engage.Store
	Mail     Mailer
	// Email returns the address on file ("" when none).
	Email   func(ctx context.Context, uid uuid.UUID) (string, error)
	BaseURL string
	// Signer signs the one-click "stop these reminders" link. Nil, or a nil result: nothing is
	// sent (no way to opt out, no mail).
	Signer func() *statement.Signer
	// Skip excludes a user (the demo account).
	Skip     func(uid uuid.UUID) bool
	Lifetime time.Duration
	Now      func() time.Time
	Log      *slog.Logger
	// OnCounts gets the counts of each sweep; OnNotice each notice outcome ("sent",
	// "failed", "no_email", "already_sent") by days (WarnDays or FinalDays).
	OnCounts func(Counts)
	OnNotice func(days int, outcome string)
}

Job is the sweep. Set the fields; Lifetime defaults to rivian.SessionLifetime.

func (*Job) Sweep

func (j *Job) Sweep(ctx context.Context)

Sweep counts the sessions near expiry and sends the notices due. A user whose session is already flagged needs_reauth is left to that flow.

type Mailer

type Mailer interface {
	Send(ctx context.Context, m email.Message) error
}

Mailer sends an email.

type Sessions

type Sessions interface {
	List(ctx context.Context) ([]Entry, error)
}

Sessions lists every stored Rivian session.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL