pub struct SessionManager { /* private fields */ }Expand description
A coordinator pairing one Site implementation with one BrowserSession.
The manager:
- tracks the last refresh timestamp and respects
Site::refresh_interval_mininSelf::refresh_if_stale - exposes the current cookie snapshot for downstream agents
§Concurrency
The internal Mutex<SessionState> guards only the cookie snapshot and
last_refresh timestamp — it is not held across Site::refresh /
Site::validate calls. Concurrent callers of refresh /
refresh_with_seed / validate will therefore drive the underlying
browser simultaneously, which is generally unsafe (interleaved
navigations, seed cookies overwritten before the refresh navigation
reads them). Callers that share a SessionManager across tasks must
externally serialise these calls. A future release may move the lock
to cover the full call; until then, Phase 3+ multi-account pools /
schedulers are expected to own the serialisation boundary.
§Example
use std::sync::Arc;
use tail_fin_common::{BrowserSession, SessionManager};
use tail_fin_twitter::TwitterSite;
let session = BrowserSession::builder().build().await?;
let manager = SessionManager::new(Arc::new(TwitterSite), session);
// Force refresh:
manager.refresh().await?;
// Check validity:
let status = manager.validate().await?;Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn new(site: Arc<dyn Site>, browser: BrowserSession) -> SessionManager
pub fn new(site: Arc<dyn Site>, browser: BrowserSession) -> SessionManager
Create a manager wrapping a site + browser session. Initial cookie
snapshot is empty — call refresh() or reload_cookies() to populate.
Sourcepub fn browser(&self) -> &Arc<BrowserSession>
pub fn browser(&self) -> &Arc<BrowserSession>
Return the browser session.
Sourcepub async fn refresh(&self) -> Result<Vec<Value>, SiteError>
pub async fn refresh(&self) -> Result<Vec<Value>, SiteError>
Force a server-side refresh. Updates internal cookie snapshot.
Does NOT respect refresh_interval_min — for debounced refresh,
use refresh_if_stale.
Sourcepub async fn refresh_with_seed(
&self,
seed: &[Value],
) -> Result<Vec<Value>, SiteError>
pub async fn refresh_with_seed( &self, seed: &[Value], ) -> Result<Vec<Value>, SiteError>
Inject seed cookies into the browser, then call Site::refresh.
Use when the caller already has a (possibly stale) cookie set the site accepts as “proof of prior session” — the refresh navigation uses them to obtain fresh server-issued cookies.
An empty seed slice skips the injection and is equivalent to
calling SessionManager::refresh directly.
Like refresh, this does NOT respect refresh_interval_min.
Sourcepub async fn refresh_if_stale(&self) -> Result<Option<Vec<Value>>, SiteError>
pub async fn refresh_if_stale(&self) -> Result<Option<Vec<Value>>, SiteError>
Refresh only if the last refresh is older than site.refresh_interval_min().
Returns Some(cookies) on actual refresh, None if debounced.
Sourcepub async fn validate(&self) -> Result<SessionStatus, SiteError>
pub async fn validate(&self) -> Result<SessionStatus, SiteError>
Validate session liveness via the site’s validate hook.
Snapshot of the current cookies held by this manager.
Initially empty until first refresh() or reload_cookies().
Reload cookies from the browser without triggering server-side refresh. Useful if cookies were updated via some path outside the manager.