Struct SqliteStorage

Source
pub struct SqliteStorage<T, C = JsonCodec<String>> { /* private fields */ }
Available on crate feature sqlite only.
Expand description

Represents a Storage that persists to Sqlite

Implementations§

Source§

impl SqliteStorage<()>

Source

pub async fn setup(pool: &Pool<Sqlite>) -> Result<(), Error>

Perform migrations for storage

Source

pub fn migrations() -> Migrator

Get sqlite migrations without running them

Source§

impl<T> SqliteStorage<T>

Source

pub fn new(pool: SqlitePool) -> Self

Create a new instance

Source

pub fn new_with_config(pool: SqlitePool, config: Config) -> Self

Create a new instance with a custom config

Source§

impl<T, C> SqliteStorage<T, C>

Source

pub async fn keep_alive_at( &mut self, worker: &Worker<Context>, last_seen: i64, ) -> Result<(), Error>

Keeps a storage notified that the worker is still alive manually

Source

pub fn pool(&self) -> &Pool<Sqlite>

Expose the pool for other functionality, eg custom migrations

Source

pub fn get_config(&self) -> &Config

Get the config used by the storage

Source§

impl<T, C> SqliteStorage<T, C>

Source

pub fn codec(&self) -> &PhantomData<C>

Expose the code used

Source§

impl<T, C> SqliteStorage<T, C>

Source

pub async fn retry( &mut self, worker_id: &WorkerId, job_id: &TaskId, ) -> Result<(), Error>

Puts the job instantly back into the queue Another Worker may consume

Source

pub async fn kill( &mut self, worker_id: &WorkerId, job_id: &TaskId, ) -> Result<(), Error>

Kill a job

Source

pub async fn reenqueue_orphaned( &self, count: i32, dead_since: DateTime<Utc>, ) -> Result<(), Error>

Add jobs that workers have disappeared to the queue

Trait Implementations§

Source§

impl<T: Sync + Send, C: Send, Res: Serialize + Sync> Ack<T, Res, C> for SqliteStorage<T, C>

Source§

type Context = SqlContext

The data to fetch from context to allow acknowledgement
Source§

type AckError = Error

The error returned by the ack
Source§

async fn ack( &mut self, ctx: &Self::Context, res: &Response<Res>, ) -> Result<(), Error>

Acknowledges successful processing of the given request
Source§

impl<T, C> Backend<Request<T, SqlContext>> for SqliteStorage<T, C>
where C: Codec<Compact = String> + Send + 'static + Sync, C::Error: Error + 'static + Send + Sync, T: Serialize + DeserializeOwned + Sync + Send + Unpin + 'static,

Source§

type Stream = BackendStream<Pin<Box<dyn Stream<Item = Result<Option<Request<T, SqlContext>>, Error>> + Send>>>

The stream to be produced by the backend
Source§

type Layer = AckLayer<SqliteStorage<T, C>, T, SqlContext, C>

Returns the final decoration of layers
Source§

type Codec = JsonCodec<String>

Specifies the codec type used by the backend
Source§

fn poll(self, worker: &Worker<Context>) -> Poller<Self::Stream, Self::Layer>

Returns a poller that is ready for streaming
Source§

impl<J: 'static + Serialize + DeserializeOwned + Unpin + Send + Sync> BackendExpose<J> for SqliteStorage<J, JsonCodec<String>>

Source§

type Request = Request<J, Parts<SqlContext>>

The request type being handled by the backend
Source§

type Error = SqlError

The error returned during reading jobs and stats
Source§

async fn stats(&self) -> Result<Stat, Self::Error>

Returns the counts of jobs in different states
Source§

async fn list_jobs( &self, status: &State, page: i32, ) -> Result<Vec<Self::Request>, Self::Error>

Fetch jobs persisted in a backend
Source§

async fn list_workers(&self) -> Result<Vec<Worker<WorkerState>>, Self::Error>

List all Workers that are working on a backend
Source§

impl<T, C> Clone for SqliteStorage<T, C>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, C> Debug for SqliteStorage<T, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, C> Storage for SqliteStorage<T, C>
where T: Serialize + DeserializeOwned + Send + 'static + Unpin + Sync, C: Codec<Compact = String> + Send + 'static + Sync, C::Error: Error + Send + Sync + 'static,

Source§

type Job = T

The type of job that can be persisted
Source§

type Error = Error

The error produced by the storage
Source§

type Context = SqlContext

This is the type that storages store as the metadata related to a job
Source§

type Compact = String

The format that the storage persists the jobs usually Vec<u8>
Source§

async fn push_request( &mut self, job: Request<Self::Job, SqlContext>, ) -> Result<Parts<SqlContext>, Self::Error>

Pushes a constructed request to a storage
Source§

async fn push_raw_request( &mut self, job: Request<Self::Compact, SqlContext>, ) -> Result<Parts<SqlContext>, Self::Error>

Pushes a constructed request to a storage
Source§

async fn schedule_request( &mut self, req: Request<Self::Job, SqlContext>, on: i64, ) -> Result<Parts<SqlContext>, Self::Error>

Push a request into the scheduled set
Source§

async fn fetch_by_id( &mut self, job_id: &TaskId, ) -> Result<Option<Request<Self::Job, SqlContext>>, Self::Error>

Fetch a job given an id
Source§

async fn len(&mut self) -> Result<i64, Self::Error>

Return the number of pending jobs from the queue
Source§

async fn reschedule( &mut self, job: Request<T, SqlContext>, wait: Duration, ) -> Result<(), Self::Error>

Reschedule a job
Source§

async fn update( &mut self, job: Request<Self::Job, SqlContext>, ) -> Result<(), Self::Error>

Update a job details
Source§

async fn is_empty(&mut self) -> Result<bool, Self::Error>

Returns true if there is no jobs in the storage
Source§

async fn vacuum(&mut self) -> Result<usize, Error>

Vacuum the storage, removes done and killed jobs
Source§

fn push( &mut self, job: Self::Job, ) -> impl Future<Output = Result<Parts<Self::Context>, Self::Error>> + Send

Pushes a job to a storage
Source§

fn schedule( &mut self, job: Self::Job, on: i64, ) -> impl Future<Output = Result<Parts<Self::Context>, Self::Error>> + Send

Push a job with defaults into the scheduled set

Auto Trait Implementations§

§

impl<T, C> Freeze for SqliteStorage<T, C>

§

impl<T, C = JsonCodec<String>> !RefUnwindSafe for SqliteStorage<T, C>

§

impl<T, C> Send for SqliteStorage<T, C>
where T: Send, C: Send,

§

impl<T, C> Sync for SqliteStorage<T, C>
where T: Sync, C: Sync,

§

impl<T, C> Unpin for SqliteStorage<T, C>
where T: Unpin, C: Unpin,

§

impl<T, C = JsonCodec<String>> !UnwindSafe for SqliteStorage<T, C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,