pub struct SqliteStorage<T> { /* private fields */ }
Available on crate feature sqlite only.
Expand description

Represents a Storage that persists to Sqlite

Implementations§

source§

impl<T: Job> SqliteStorage<T>

source

pub fn new(pool: SqlitePool) -> Self

Construct a new Storage from a pool

source

pub async fn connect<S: Into<String>>(db: S) -> Result<Self, Error>

Connect to a database given a url

source

pub async fn setup(&self) -> Result<(), Error>

Perform migrations for storage

source

pub fn migrations() -> Migrator

Get sqlite migrations without running them

source

pub async fn keep_alive_at<Service>( &mut self, worker_id: &WorkerId, last_seen: DateTime<Utc> ) -> StorageResult<()>

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

Trait Implementations§

source§

impl<T> Clone for SqliteStorage<T>

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: Debug> Debug for SqliteStorage<T>

source§

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

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

impl<J: 'static + Job + Serialize + DeserializeOwned + Unpin + Send + Sync> JobStreamExt<J> for SqliteStorage<J>

Available on crate feature expose only.
source§

fn counts<'life0, 'async_trait>( &'life0 mut self ) -> Pin<Box<dyn Future<Output = Result<JobStateCount, JobError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Returns the counts of jobs in different states
source§

fn list_jobs<'life0, 'life1, 'async_trait>( &'life0 mut self, status: &'life1 JobState, page: i32 ) -> Pin<Box<dyn Future<Output = Result<Vec<JobRequest<J>>, JobError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch jobs persisted from storage
source§

fn list_workers<'life0, 'async_trait>( &'life0 mut self ) -> Pin<Box<dyn Future<Output = Result<Vec<ExposedWorker>, JobError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

List all Workers that are working on a Job Stream
source§

impl<T> Storage for SqliteStorage<T>where T: Job + Serialize + DeserializeOwned + Send + 'static + Unpin + Sync,

source§

fn heartbeat<'life0, 'async_trait>( &'life0 mut self, pulse: StorageWorkerPulse ) -> Pin<Box<dyn Future<Output = StorageResult<bool>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Used for scheduling jobs via StorageWorkerPulse signals

source§

fn retry<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, worker_id: &'life1 WorkerId, job_id: &'life2 JobId ) -> Pin<Box<dyn Future<Output = StorageResult<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

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

§

type Output = T

The type of job that can be persisted
source§

fn push<'life0, 'async_trait>( &'life0 mut self, job: Self::Output ) -> Pin<Box<dyn Future<Output = StorageResult<JobId>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Pushes a job to a storage
source§

fn schedule<'life0, 'async_trait>( &'life0 mut self, job: Self::Output, on: DateTime<Utc> ) -> Pin<Box<dyn Future<Output = StorageResult<JobId>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Push a job into the scheduled set
source§

fn fetch_by_id<'life0, 'life1, 'async_trait>( &'life0 self, job_id: &'life1 JobId ) -> Pin<Box<dyn Future<Output = StorageResult<Option<JobRequest<Self::Output>>>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch a job given an id
source§

fn kill<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, worker_id: &'life1 WorkerId, job_id: &'life2 JobId ) -> Pin<Box<dyn Future<Output = StorageResult<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Kill a job
source§

fn consume( &mut self, worker_id: &WorkerId, interval: Duration, buffer_size: usize ) -> JobStreamResult<T>

Get the stream of jobs
source§

fn len<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = StorageResult<i64>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Return the number of pending jobs from the queue
source§

fn ack<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, worker_id: &'life1 WorkerId, job_id: &'life2 JobId ) -> Pin<Box<dyn Future<Output = StorageResult<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Acknowledge a job which returns Ok
source§

fn reschedule<'life0, 'life1, 'async_trait>( &'life0 mut self, job: &'life1 JobRequest<T>, wait: Duration ) -> Pin<Box<dyn Future<Output = StorageResult<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Reschedule a job
source§

fn update_by_id<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, job_id: &'life1 JobId, job: &'life2 JobRequest<Self::Output> ) -> Pin<Box<dyn Future<Output = StorageResult<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Update a job details
source§

fn keep_alive<'life0, 'life1, 'async_trait, Service>( &'life0 mut self, worker_id: &'life1 WorkerId ) -> Pin<Box<dyn Future<Output = StorageResult<()>> + Send + 'async_trait>>where Service: 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called by a Worker to keep the storage alive and prevent jobs from being deemed as orphaned
source§

fn reenqueue_active<'life0, 'life1, 'async_trait>( &'life0 mut self, _job_ids: Vec<&'life1 JobId> ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>where 'life0: 'async_trait, 'life1: 'async_trait, Self: Send + 'async_trait,

Used to recover jobs when a Worker shuts down.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for SqliteStorage<T>

§

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

§

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

§

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

§

impl<T> !UnwindSafe for SqliteStorage<T>

Blanket Implementations§

source§

impl<J, S> Ack<J> for Swhere S: Storage<Output = J> + Send + Sync, J: Send + Sync,

§

type Acknowledger = JobId

The data to fetch from context to allow acknowledgement
source§

fn ack<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, worker_id: &'life1 WorkerId, job_id: &'life2 JobId ) -> Pin<Box<dyn Future<Output = Result<(), AckError>> + Send + 'async_trait>>where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, S: 'async_trait,

Acknowledges successful processing of the given request
source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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 Twhere 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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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