Trait faktory::JobRunner

source ·
pub trait JobRunner: Send + Sync {
    type Error;

    // Required method
    fn run(&self, job: Job) -> Result<(), Self::Error>;
}
Expand description

Implementations of this trait can be registered to run jobs in a Consumer.

§Example

Create a worker with all default options, register a single handler (for the foo job type), connect to the Faktory server, and start accepting jobs. The handler is a struct that implements JobRunner.

use faktory::{ConsumerBuilder, JobRunner, Job};
use std::io;

struct MyHandler {
    config: String,
}
impl JobRunner for MyHandler {
   type Error = io::Error;
   fn run(&self, job: Job) -> Result<(), Self::Error> {
      println!("config: {}", self.config);
      println!("job: {:?}", job);
      Ok(())
  }
}

let mut c = ConsumerBuilder::default();
let handler = MyHandler {
   config: "bar".to_string(),
};
c.register_runner("foo", handler);
let mut c = c.connect(None).unwrap();
if let Err(e) = c.run(&["default"]) {
    println!("worker failed: {}", e);
}

Required Associated Types§

source

type Error

The error type that the handler may return.

Required Methods§

source

fn run(&self, job: Job) -> Result<(), Self::Error>

A handler function that runs a job.

Implementations on Foreign Types§

source§

impl<'a, E, F> JobRunner for &'a F
where F: Fn(Job) -> Result<(), E> + Send + Sync,

§

type Error = E

source§

fn run(&self, job: Job) -> Result<(), E>

source§

impl<'a, E, F> JobRunner for &'a mut F
where F: Fn(Job) -> Result<(), E> + Send + Sync,

§

type Error = E

source§

fn run(&self, job: Job) -> Result<(), E>

source§

impl<E, F> JobRunner for Box<F>
where F: Fn(Job) -> Result<(), E> + Send + Sync,

§

type Error = E

source§

fn run(&self, job: Job) -> Result<(), E>

Implementors§