Struct json_job_dispatch::Director
source · pub struct Director<'a> { /* private fields */ }
Expand description
Dispatch jobs to registered handlers.
Jobs are sorted into accept
, reject
, and fail
directories based on whether they were
accepted by the relevant handler. Once handled, a .stamp
file containing the timestamp of
when the job was completed is created beside the final location. In addition, rejected and
failed jobs have a .reason
file describing what happened.
Implementations§
source§impl<'a> Director<'a>
impl<'a> Director<'a>
sourcepub fn new(root: &Path) -> Result<Self, DirectorError>
pub fn new(root: &Path) -> Result<Self, DirectorError>
Creates a new Director
.
The accept
and reject
directories are created as children of the given directory.
sourcepub fn add_handler<K>(
&mut self,
kind: K,
handler: &'a dyn Handler
) -> Result<(), DirectorError>where
K: Into<String>,
pub fn add_handler<K>( &mut self, kind: K, handler: &'a dyn Handler ) -> Result<(), DirectorError>where K: Into<String>,
Add a handler for jobs labeled as kind
.
sourcepub async fn run<P>(&self, path: P) -> RunResultwhere
P: AsRef<Path>,
pub async fn run<P>(&self, path: P) -> RunResultwhere P: AsRef<Path>,
Handle a path.
Returns whether the path is a stream terminator or not.
sourcepub fn path_stream(
&self,
path: &Path
) -> Result<impl Stream<Item = PathBuf>, DirectorError>
pub fn path_stream( &self, path: &Path ) -> Result<impl Stream<Item = PathBuf>, DirectorError>
Return a stream of paths to act on.
The beginning of the stream will contain paths which exist at startup and afterwards, paths for which “important” events occur will be generated.
sourcepub fn watch_directory(&self, path: &Path) -> Result<RunResult, DirectorError>
pub fn watch_directory(&self, path: &Path) -> Result<RunResult, DirectorError>
Watch a directory and act on the paths within it.
sourcepub async fn watch_directory_in(
&self,
path: &Path
) -> Result<RunResult, DirectorError>
pub async fn watch_directory_in( &self, path: &Path ) -> Result<RunResult, DirectorError>
Watch a directory and act on the paths within it on an existing runtime.