1use job::Job;
2use JobSuccessType;
3use ::JobSuccessType::*;
4use errors::{ErrorKind, Result};
5
6pub type JobHandlerResult = Result<JobSuccessType>;
7
8pub trait JobHandler: Send {
9 fn handle(&mut self, job: &Job) -> JobHandlerResult;
10 fn cloned(&mut self) -> Box<JobHandler>;
11}
12
13impl<F> JobHandler for F
14 where F: FnMut(&Job) -> JobHandlerResult + Copy + Send + 'static
15{
16 fn handle(&mut self, job: &Job) -> JobHandlerResult {
17 self(job)
18 }
19 fn cloned(&mut self) -> Box<JobHandler> {
20 Box::new(*self)
21 }
22}
23
24pub fn printer_handler(job: &Job) -> JobHandlerResult {
25 info!("handling {:?}", job);
26 Ok(Success)
27}
28
29pub fn error_handler(_: &Job) -> JobHandlerResult {
30 Err(ErrorKind::JobHandlerError(Box::new("a".parse::<i8>().unwrap_err())).into())
31}
32
33pub fn panic_handler(_: &Job) -> JobHandlerResult {
34 panic!("yeah, I do it deliberately")
35}