apalis_core/storage/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use std::time::Duration;

use futures::Future;

use crate::{
    request::{Parts, Request},
    task::task_id::TaskId,
};

/// Represents a [Storage] that can persist a request.
pub trait Storage {
    /// The type of job that can be persisted
    type Job;

    /// The error produced by the storage
    type Error;

    /// This is the type that storages store as the metadata related to a job
    type Context: Default;

    /// Pushes a job to a storage
    fn push(
        &mut self,
        job: Self::Job,
    ) -> impl Future<Output = Result<Parts<Self::Context>, Self::Error>> + Send {
        self.push_request(Request::new(job))
    }

    /// Pushes a constructed request to a storage
    fn push_request(
        &mut self,
        req: Request<Self::Job, Self::Context>,
    ) -> impl Future<Output = Result<Parts<Self::Context>, Self::Error>> + Send;

    /// Push a job with defaults into the scheduled set
    fn schedule(
        &mut self,
        job: Self::Job,
        on: i64,
    ) -> impl Future<Output = Result<Parts<Self::Context>, Self::Error>> + Send {
        self.schedule_request(Request::new(job), on)
    }

    /// Push a request into the scheduled set
    fn schedule_request(
        &mut self,
        request: Request<Self::Job, Self::Context>,
        on: i64,
    ) -> impl Future<Output = Result<Parts<Self::Context>, Self::Error>> + Send;

    /// Return the number of pending jobs from the queue
    fn len(&mut self) -> impl Future<Output = Result<i64, Self::Error>> + Send;

    /// Fetch a job given an id
    fn fetch_by_id(
        &mut self,
        job_id: &TaskId,
    ) -> impl Future<Output = Result<Option<Request<Self::Job, Self::Context>>, Self::Error>> + Send;

    /// Update a job details
    fn update(
        &mut self,
        job: Request<Self::Job, Self::Context>,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send;

    /// Reschedule a job
    fn reschedule(
        &mut self,
        job: Request<Self::Job, Self::Context>,
        wait: Duration,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send;

    /// Returns true if there is no jobs in the storage
    fn is_empty(&mut self) -> impl Future<Output = Result<bool, Self::Error>> + Send;

    /// Vacuum the storage, removes done and killed jobs
    fn vacuum(&mut self) -> impl Future<Output = Result<usize, Self::Error>> + Send;
}