pub struct WorkerRuntime { /* private fields */ }
Expand description
Implementations§
Source§impl WorkerRuntime
impl WorkerRuntime
Sourcepub async fn from_config(config: &Config, marker: Marker) -> Result<Self>
pub async fn from_config(config: &Config, marker: Marker) -> Result<Self>
Initializes the WorkerRuntime
with the provided Config
.
Sourcepub async fn get_result_sender(
&self,
identifier: String,
) -> Result<Box<dyn Publisher<AnyTaskResult> + Send + Unpin + Sync + '_>>
pub async fn get_result_sender( &self, identifier: String, ) -> Result<Box<dyn Publisher<AnyTaskResult> + Send + Unpin + Sync + '_>>
Provides a Publisher
for dispatching AnyTaskResult
s.
Typically used by a worker node for send back the results of a Task
execution.
Sourcepub async fn get_ipc_sender(
&self,
) -> Result<Box<dyn Publisher<WorkerIpc> + Send + Unpin + Sync + '_>>
pub async fn get_ipc_sender( &self, ) -> Result<Box<dyn Publisher<WorkerIpc> + Send + Unpin + Sync + '_>>
Sourcepub async fn get_ipc_receiver(&self) -> Result<BoxStream<'static, WorkerIpc>>
pub async fn get_ipc_receiver(&self) -> Result<BoxStream<'static, WorkerIpc>>
Sourcepub async fn get_task_receiver(
&self,
) -> Result<Box<dyn Stream<Item = (AnyTask, Box<dyn Acker>)> + Send + Unpin + '_>>
pub async fn get_task_receiver( &self, ) -> Result<Box<dyn Stream<Item = (AnyTask, Box<dyn Acker>)> + Send + Unpin + '_>>
Provides a Stream
incoming AnyTask
s.
Typically the the worker node’s first interaction with the Runtime
.
This is how workers receive Task
s 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
}
}
Sourcepub async fn dispatch_fatal<E>(&self, __arg1: ExecutionErr<E>) -> Result<()>
pub async fn dispatch_fatal<E>(&self, __arg1: ExecutionErr<E>) -> Result<()>
Sourcepub async fn dispatch_ok<'a>(&self, __arg1: ExecutionOk) -> Result<()>
pub async fn dispatch_ok<'a>(&self, __arg1: ExecutionOk) -> Result<()>
Sourcepub async fn main_loop(&self) -> Result<()>
pub async fn main_loop(&self) -> Result<()>
A default worker loop that can be used to process
Task
s.
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
impl Clone for WorkerRuntime
Source§fn clone(&self) -> WorkerRuntime
fn clone(&self) -> WorkerRuntime
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more