pub struct AlienContext { /* private fields */ }Expand description
Main context for Alien applications that provides access to:
- Resource bindings (storage, kv, queue, vault, etc.)
- Event handlers (storage events, cron events, queue messages, commands)
- Background tasks (wait_until)
- HTTP server registration
Implementations§
Source§impl AlienContext
impl AlienContext
Sourcepub async fn from_env() -> Result<Self>
pub async fn from_env() -> Result<Self>
Creates a new AlienContext from environment variables. This automatically sets up gRPC communication and starts the drain listener.
Sourcepub async fn from_env_with_vars(
env_vars: &HashMap<String, String>,
) -> Result<Self>
pub async fn from_env_with_vars( env_vars: &HashMap<String, String>, ) -> Result<Self>
Creates a new AlienContext from provided environment variables. This is useful for testing or when environment variables are not available via std::env.
Sourcepub fn new(
wait_until_context: Arc<WaitUntilContext>,
bindings_provider: Arc<dyn BindingsProviderApi>,
) -> Self
pub fn new( wait_until_context: Arc<WaitUntilContext>, bindings_provider: Arc<dyn BindingsProviderApi>, ) -> Self
Creates a new AlienContext with custom provider and wait_until context. This is mainly useful for testing or advanced use cases.
Sourcepub fn bindings(&self) -> &dyn BindingsProviderApi
pub fn bindings(&self) -> &dyn BindingsProviderApi
Gets the bindings provider for accessing storage, build, and other resources.
Sourcepub fn get_bindings(&self) -> Arc<dyn BindingsProviderApi>
pub fn get_bindings(&self) -> Arc<dyn BindingsProviderApi>
Gets the bindings provider as an Arc
Sourcepub fn on_storage_event<F, Fut>(&self, resource: &str, handler: F)
pub fn on_storage_event<F, Fut>(&self, resource: &str, handler: F)
Sourcepub fn on_cron_event<F, Fut>(&self, schedule: &str, handler: F)
pub fn on_cron_event<F, Fut>(&self, schedule: &str, handler: F)
Sourcepub fn on_queue_message<F, Fut>(&self, queue: &str, handler: F)
pub fn on_queue_message<F, Fut>(&self, queue: &str, handler: F)
Sourcepub fn on_command<P, R, F, Fut>(&self, command: &str, handler: F)
pub fn on_command<P, R, F, Fut>(&self, command: &str, handler: F)
Sourcepub async fn register_http_server(&self, port: u16) -> Result<()>
pub async fn register_http_server(&self, port: u16) -> Result<()>
Sourcepub fn wait_until<F, Fut>(&self, task_fn: F) -> Result<()>
pub fn wait_until<F, Fut>(&self, task_fn: F) -> Result<()>
Registers a background task that will run even after the main handler returns. The task runs in the application process and is tracked by the runtime for proper shutdown coordination.
Sourcepub fn application_id(&self) -> &str
pub fn application_id(&self) -> &str
Gets the application ID for this context.
Sourcepub async fn get_task_count(&self) -> Result<u32>
pub async fn get_task_count(&self) -> Result<u32>
Gets the current number of registered wait_until tasks.
Sourcepub async fn get_current_function(&self) -> Result<Option<Arc<dyn Function>>>
pub async fn get_current_function(&self) -> Result<Option<Arc<dyn Function>>>
Gets the current function binding if available.
Sourcepub async fn get_current_container(&self) -> Result<Option<Arc<dyn Container>>>
pub async fn get_current_container(&self) -> Result<Option<Arc<dyn Container>>>
Gets the current container binding if available.
This allows a container to discover its own public and internal URLs. Useful for constructing callback URLs, OAuth redirects, etc.
§Example
let ctx = AlienContext::from_env().await?;
if let Some(container) = ctx.get_current_container().await? {
let public_url = container.get_public_url();
let callback_url = format!("{}/callback", public_url.unwrap_or(""));
}Auto Trait Implementations§
impl Freeze for AlienContext
impl !RefUnwindSafe for AlienContext
impl Send for AlienContext
impl Sync for AlienContext
impl Unpin for AlienContext
impl UnsafeUnpin for AlienContext
impl !UnwindSafe for AlienContext
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request