Struct WorkerRuntime

Source
pub struct WorkerRuntime { /* private fields */ }
Expand description

A runtime for worker nodes.

This runtime provides functionality for the three responsibilities of a worker process.

  1. Listen for new Tasks.
  2. Execute those Tasks.
  3. Send back the results of a Task execution.

Implementations§

Source§

impl WorkerRuntime

Source

pub async fn from_config(config: &Config, marker: Marker) -> Result<Self>

Initializes the WorkerRuntime with the provided Config.

Source

pub async fn get_result_sender( &self, identifier: String, ) -> Result<Box<dyn Publisher<AnyTaskResult> + Send + Unpin + Sync + '_>>

Provides a Publisher for dispatching AnyTaskResults.

Typically used by a worker node for send back the results of a Task execution.

Source

pub async fn get_ipc_sender( &self, ) -> Result<Box<dyn Publisher<WorkerIpc> + Send + Unpin + Sync + '_>>

Get a Publisher for dispatching WorkerIpc messages.

Typically used by a worker node to notify other workers of a fatal error.

Source

pub async fn get_ipc_receiver(&self) -> Result<BoxStream<'static, WorkerIpc>>

Get a Stream for receiving WorkerIpc messages.

Typically used by a worker node to listen for fatal errors from other workers.

Source

pub async fn get_task_receiver( &self, ) -> Result<Box<dyn Stream<Item = (AnyTask, Box<dyn Acker>)> + Send + Unpin + '_>>

Provides a Stream incoming AnyTasks.

Typically the the worker node’s first interaction with the Runtime. This is how workers receive Tasks for remote execution.

§Example
use clap::Parser;
use paladin::{
    RemoteExecute,
    config::Config,
    registry,
    runtime::WorkerRuntime,
    operation::{Operation, Result},
};
use serde::{Deserialize, Serialize};
use futures::StreamExt;

#[derive(Parser, Debug)]
pub struct Cli {
    #[command(flatten)]
    pub options: Config,
}

paladin::registry!();

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let args = Cli::parse();
    let runtime = WorkerRuntime::from_config(&args.options, register()).await?;

    let mut task_stream = runtime.get_task_receiver().await?;
    while let Some((task, delivery)) = task_stream.next().await {
        // ... handle task
    }
}
Source

pub async fn dispatch_fatal<E>(&self, __arg1: ExecutionErr<E>) -> Result<()>
where E: Display + Debug,

Notify the Runtime of a fatal error.

This will pass the error back to the consumer of the Task and notify other workers of the error.

Source

pub async fn dispatch_ok<'a>(&self, __arg1: ExecutionOk) -> Result<()>

Notify the Runtime of a successful execution.

This will pass the output back to the consumer of the Task and ack the message.

Source

pub async fn main_loop(&self) -> Result<()>

A default worker loop that can be used to process Tasks.

Worker implementations generally wont vary, as the their primary responsibility is to process incoming tasks. We provide one out of the box that will work for most use cases. Users are free to implement their own if they need to.

Note that if you define your operations in a separate crate, you’ll need to use the registry! macro to register them with the runtime.

§Example
use paladin::{
    RemoteExecute,
    runtime::WorkerRuntime,
    config::Config,
    task::Task,
    operation::{Result, Operation},
    registry,
};
use clap::Parser;
use serde::{Deserialize, Serialize};

#[derive(Parser, Debug)]
pub struct Cli {
    #[command(flatten)]
    pub options: Config,
}

registry!();

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let args = Cli::parse();
    let runtime = WorkerRuntime::from_config(&args.options, register()).await?;
    runtime.main_loop().await?;

    Ok(())
}

Trait Implementations§

Source§

impl Clone for WorkerRuntime

Source§

fn clone(&self) -> WorkerRuntime

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,