Skip to main content

Server

Struct Server 

Source
pub struct Server<'a, F> { /* private fields */ }
Expand description

A function server with options beyond the command-line Args. Create it with Server::new, chain the options, then call Server::serve; with no options it serves exactly like serve. New options arrive as new methods, so code that builds a server keeps compiling.

function_sdk_rust::Server::new(function, args)
    .ready(async { Ok::<(), std::io::Error>(()) })
    .serve()
    .await

Implementations§

Source§

impl<'a, F: FunctionRunnerService> Server<'a, F>

Source

pub fn new(function: F, args: &'a Args) -> Self

Creates a server for function, configured by the command-line args.

Source

pub fn ready<R, E>(self, ready: R) -> Self
where R: Future<Output = Result<(), E>> + Send + 'static, E: Into<Box<dyn Error + Send + Sync>>,

Holds the function back until ready completes, for a function that must finish loading before it can run. The server listens at once, but reports NOT_SERVING on the gRPC health service and answers RunFunction with UNAVAILABLE. Ok flips the function to SERVING; an error or a panic stops the server, and Server::serve returns it as Error::NotReady.

Source

pub fn metrics_registry(self, registry: Registry) -> Self

Serves registry at /metrics, like function-sdk-go’s WithMetricsRegistry: register the function’s own series in it first, and the SDK adds its grpc_server_* series at the root. With --metrics-address empty nothing is served.

Build the registry and its metrics with a prometheus-client version that is semver-compatible with the SDK’s own dependency on it (while prometheus-client is 0.x, the same minor version). Cargo then resolves both to one copy of the crate; a registry from an incompatible version is a different type and does not compile here.

Source

pub async fn serve(self) -> Result<(), Error>

Serves RunFunctionRequests until SIGTERM or SIGINT, then shuts down gracefully. See serve for what is served.

Auto Trait Implementations§

§

impl<'a, F> !RefUnwindSafe for Server<'a, F>

§

impl<'a, F> !Sync for Server<'a, F>

§

impl<'a, F> !UnwindSafe for Server<'a, F>

§

impl<'a, F> Freeze for Server<'a, F>
where F: Freeze,

§

impl<'a, F> Send for Server<'a, F>
where F: Send,

§

impl<'a, F> Unpin for Server<'a, F>
where F: Unpin,

§

impl<'a, F> UnsafeUnpin for Server<'a, F>
where F: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more