Higgs
One request context across the stack
Higgs::from_request() loads the current user and Valence in a Leptos server function. Enqueue a Boson task (or a Chronon job, or a Photon publish) and the worker rebuilds that same user context.Where it lands
Hosts provide HiggsConfig at boot.Call require_session() and Higgs::from_request() in the server function. Enqueue with the User actor from the session. In the #[task] handler, valence_from_context(ctx) rebuilds Valence for that user. Chronon ScriptContext and Photon Actor factories use the same ValenceFactory. That is the unified context: one identity path for interactive and background work.
In the workspace
Hosts provide HiggsConfig at boot.Code sample
From the upstream getting-started docs — see also all code recipes on Resources.
Higgs + BosonHiggs
Server function enqueues a task; the task rebuilds the user
use boson_core::ExecutionContext;
use boson_macros::task;
use boson_valence_identity::valence_from_context;
use higgs::{require_session, Higgs};
use leptos::prelude::*;
#[server]
async fn queue_profile_rebuild() -> Result<(), ServerFnError> {
let session = require_session().await?;
let ctx = Higgs::from_request().await?;
let valence = ctx.valence().map_err(ServerFnError::new)?;
let user_id = valence
.actor()
.user_id()
.unwrap_or(&session.user_id)
.to_string();
RebuildProfile::send_with(
serde_json::json!({ "User": { "user_id": user_id } }),
RebuildProfileParams {
user_id: user_id.clone(),
},
)
.await
.map_err(ServerFnError::new)?;
Ok(())
}
#[task(name = "rebuild_profile")]
async fn rebuild_profile(
ctx: Box<dyn ExecutionContext>,
user_id: String,
) -> boson_core::Result<()> {
// Same user as the server function. Chronon scripts and Photon
// subscribers rebuild context from the same ValenceFactory.
let valence = valence_from_context(ctx.as_ref())?;
tracing::info!(rebuilt_user = valence.actor().user_id(), %user_id);
Ok(())
}