pub struct DemoSessionRow {
pub id: i64,
pub token_hash: String,
pub created_at: DateTime<Utc>,
pub last_seen_at: DateTime<Utc>,
pub expires_at: DateTime<Utc>,
pub revoked_at: Option<DateTime<Utc>>,
}Expand description
A short-lived anonymous owner for simulator-only public demo runs. The raw bearer token is never stored; callers pass its lowercase hexadecimal SHA-256 hash to the repository.
Fields§
§id: i64§token_hash: String§created_at: DateTime<Utc>§last_seen_at: DateTime<Utc>§expires_at: DateTime<Utc>§revoked_at: Option<DateTime<Utc>>Implementations§
Source§impl DemoSessionRow
impl DemoSessionRow
Sourcepub async fn create(
pool: &SqlitePool,
token_hash: &str,
now: DateTime<Utc>,
expires_at: DateTime<Utc>,
) -> DbResult<Self>
pub async fn create( pool: &SqlitePool, token_hash: &str, now: DateTime<Utc>, expires_at: DateTime<Utc>, ) -> DbResult<Self>
Persists a session on first use, or returns the already-persisted valid row when another request won the same token-hash race.
Sourcepub async fn get_or_create(
pool: &SqlitePool,
token_hash: &str,
now: DateTime<Utc>,
expires_at: DateTime<Utc>,
) -> DbResult<Self>
pub async fn get_or_create( pool: &SqlitePool, token_hash: &str, now: DateTime<Utc>, expires_at: DateTime<Utc>, ) -> DbResult<Self>
Lazily persists a token hash on first use. Concurrent callers presenting the same token converge on one row: the unique-token loser reloads the winner’s valid row rather than surfacing a uniqueness error.
An expired or revoked conflicting row remains authoritative and is returned as
RowNotFound; it is never revived and its fixed expiry is never extended.
Sourcepub async fn get_by_token_hash(
pool: &SqlitePool,
token_hash: &str,
now: DateTime<Utc>,
) -> DbResult<Option<Self>>
pub async fn get_by_token_hash( pool: &SqlitePool, token_hash: &str, now: DateTime<Utc>, ) -> DbResult<Option<Self>>
Looks up an authorization session and atomically records its latest activity. Expired and revoked rows are deliberately indistinguishable from a missing row, and the fixed expiry is never extended.
Sourcepub async fn touch_by_token_hash(
pool: &SqlitePool,
token_hash: &str,
now: DateTime<Utc>,
) -> DbResult<Option<Self>>
pub async fn touch_by_token_hash( pool: &SqlitePool, token_hash: &str, now: DateTime<Utc>, ) -> DbResult<Option<Self>>
Records activity only while the session remains valid. expires_at is never changed:
demo sessions have an absolute lifetime, not a sliding one.
pub async fn revoke( pool: &SqlitePool, id: i64, now: DateTime<Utc>, ) -> DbResult<bool>
Sourcepub async fn cleanup_expired(
pool: &SqlitePool,
now: DateTime<Utc>,
) -> DbResult<u64>
pub async fn cleanup_expired( pool: &SqlitePool, now: DateTime<Utc>, ) -> DbResult<u64>
Removes expired/revoked sessions and cascades their terminal owned history.
A session owning a running run is protected even after expiry or revocation. Startup
recovery must first mark that run failed via Self::recover_running_demo_runs; only a
later cleanup can remove the session and its now-terminal history.
Sourcepub async fn recover_running_demo_runs(
pool: &SqlitePool,
now: DateTime<Utc>,
) -> DbResult<u64>
pub async fn recover_running_demo_runs( pool: &SqlitePool, now: DateTime<Utc>, ) -> DbResult<u64>
Marks demo runs left in running state by a process restart as failed. Demo work is
intentionally not resumed after a crash or restart.
Trait Implementations§
Source§impl Clone for DemoSessionRow
impl Clone for DemoSessionRow
Source§fn clone(&self) -> DemoSessionRow
fn clone(&self) -> DemoSessionRow
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DemoSessionRow
impl Debug for DemoSessionRow
impl Eq for DemoSessionRow
Source§impl PartialEq for DemoSessionRow
impl PartialEq for DemoSessionRow
Source§fn eq(&self, other: &DemoSessionRow) -> bool
fn eq(&self, other: &DemoSessionRow) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for DemoSessionRow
Auto Trait Implementations§
impl Freeze for DemoSessionRow
impl RefUnwindSafe for DemoSessionRow
impl Send for DemoSessionRow
impl Sync for DemoSessionRow
impl Unpin for DemoSessionRow
impl UnsafeUnpin for DemoSessionRow
impl UnwindSafe for DemoSessionRow
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more