1
use std::fmt::Debug;
2

            
3
use async_trait::async_trait;
4

            
5
use crate::tasks::{handle::Id, manager::Manager, traits::Executable, Job};
6

            
7
#[derive(Debug)]
8
pub struct ManagedJob<J, Key> {
9
    pub id: Id,
10
    pub job: J,
11
    pub manager: Manager<Key>,
12
    pub key: Option<Key>,
13
}
14

            
15
#[async_trait]
16
impl<J, Key> Executable for ManagedJob<J, Key>
17
where
18
    J: Job,
19
    Key: Clone + std::hash::Hash + Eq + Send + Sync + Debug + 'static,
20
{
21
160856
    async fn execute(&mut self) {
22
160875
        let result = self.job.execute().await;
23

            
24
160772
        self.manager
25
160772
            .job_completed(self.id, self.key.as_ref(), result)
26
546
            .await;
27
160772
    }
28
}