Struct viceroy_lib::ExecuteCtx
source · pub struct ExecuteCtx { /* private fields */ }
Expand description
Execution context used by a ViceroyService
.
This is all of the state needed to instantiate a module, in order to respond to an HTTP
request. Note that it is very important that ExecuteCtx
be cheaply clonable, as it is cloned
every time that a viceroy service handles an incoming connection.
Implementations§
source§impl ExecuteCtx
impl ExecuteCtx
sourcepub fn new(
module_path: impl AsRef<Path>,
profiling_strategy: ProfilingStrategy,
wasi_modules: HashSet<ExperimentalModule>
) -> Result<Self, Error>
pub fn new(
module_path: impl AsRef<Path>,
profiling_strategy: ProfilingStrategy,
wasi_modules: HashSet<ExperimentalModule>
) -> Result<Self, Error>
Create a new execution context, given the path to a module and a set of experimental wasi modules.
sourcepub fn with_backends(self, backends: Backends) -> Self
pub fn with_backends(self, backends: Backends) -> Self
Set the backends for this execution context.
sourcepub fn geolocation(&self) -> &Geolocation
pub fn geolocation(&self) -> &Geolocation
Get the geolocation mappings for this execution context.
sourcepub fn with_geolocation(self, geolocation: Geolocation) -> Self
pub fn with_geolocation(self, geolocation: Geolocation) -> Self
Set the geolocation mappings for this execution context.
sourcepub fn dictionaries(&self) -> &Dictionaries
pub fn dictionaries(&self) -> &Dictionaries
Get the dictionaries for this execution context.
sourcepub fn with_dictionaries(self, dictionaries: Dictionaries) -> Self
pub fn with_dictionaries(self, dictionaries: Dictionaries) -> Self
Set the dictionaries for this execution context.
sourcepub fn with_object_store(self, object_store: ObjectStore) -> Self
pub fn with_object_store(self, object_store: ObjectStore) -> Self
Set the object store for this execution context.
sourcepub fn with_config_path(self, config_path: PathBuf) -> Self
pub fn with_config_path(self, config_path: PathBuf) -> Self
Set the path to the config for this execution context.
sourcepub fn log_stdout(&self) -> bool
pub fn log_stdout(&self) -> bool
Whether to treat stdout as a logging endpoint.
sourcepub fn with_log_stdout(self, log_stdout: bool) -> Self
pub fn with_log_stdout(self, log_stdout: bool) -> Self
Set the stdout logging policy for this execution context.
sourcepub fn log_stderr(&self) -> bool
pub fn log_stderr(&self) -> bool
Whether to treat stderr as a logging endpoint.
sourcepub fn with_log_stderr(self, log_stderr: bool) -> Self
pub fn with_log_stderr(self, log_stderr: bool) -> Self
Set the stderr logging policy for this execution context.
sourcepub fn tls_config(&self) -> &TlsConfig
pub fn tls_config(&self) -> &TlsConfig
Gets the TLS configuration
sourcepub async fn handle_request(
self,
incoming_req: Request<Body>,
remote: IpAddr
) -> Result<(Response<Body>, Option<Error>), Error>
pub async fn handle_request(
self,
incoming_req: Request<Body>,
remote: IpAddr
) -> Result<(Response<Body>, Option<Error>), Error>
Asynchronously handle a request.
This method fully instantiates the wasm module housed within the ExecuteCtx
,
including running the wasm start function. It then proceeds to execute the
instantiated module’s WASI entry point, running to completion. If execution
results in an error, a response is still produced, but with a 500 status code.
Build time: Before you build or test your code, we recommend to set the release flag
e.g. cargo test --release
otherwise the execution will be very slow. This has to do
with the Cranelift compiler, which is extremely slow when compiled in debug mode.
Example
use hyper::{Body, http::Request};
let ctx = ExecuteCtx::new("path/to/a/file.wasm", ProfilingStrategy::None, HashSet::new())?;
let resp = ctx.handle_request(req, "127.0.0.1".parse().unwrap()).await?;
pub async fn handle_request_with_runtime_error(
self,
incoming_req: Request<Body>,
remote: IpAddr
) -> Result<Response<Body>, Error>
Trait Implementations§
source§impl Clone for ExecuteCtx
impl Clone for ExecuteCtx
source§fn clone(&self) -> ExecuteCtx
fn clone(&self) -> ExecuteCtx
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ExecuteCtx
impl Send for ExecuteCtx
impl Sync for ExecuteCtx
impl Unpin for ExecuteCtx
impl !UnwindSafe for ExecuteCtx
Blanket Implementations§
§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self
file descriptor.