Struct apalis_sql::postgres::PostgresStorage

source ·
pub struct PostgresStorage<T, C = JsonCodec<Value>>
where C: Codec,
{ /* private fields */ }
Available on crate feature postgres only.
Expand description

Represents a Storage that persists to Postgres

Implementations§

source§

impl PostgresStorage<()>

source

pub fn migrations() -> Migrator

Get postgres migrations without running them

source

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

Do migrations for Postgres

source§

impl<T> PostgresStorage<T>

source

pub fn new(pool: PgPool) -> Self

New Storage from PgPool

source

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

New Storage from PgPool and custom config

source

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

Expose the pool for other functionality, eg custom migrations

source

pub fn config(&self) -> &Config

Expose the config

source§

impl<T, C: Codec> PostgresStorage<T, C>

source

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

Expose the codec

source§

impl<T, C: Codec> PostgresStorage<T, C>

source

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

Kill a job

source

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

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

source

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

Reenqueue jobs that have been abandoned by their workers

Trait Implementations§

source§

impl<T, Res, C> Ack<T, Res> for PostgresStorage<T, C>
where T: Sync + Send, Res: Serialize + Sync, C: Codec<Compact = Value> + Send,

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: &Result<Res, Error>, ) -> Result<(), Error>

Acknowledges successful processing of the given request
source§

impl<T, C, Res> Backend<Request<T>, Res> for PostgresStorage<T, C>
where T: Serialize + DeserializeOwned + Sync + Send + Unpin + 'static, C: Codec<Compact = Value> + Send + 'static,

source§

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

The stream to be produced by the backend
source§

type Layer = AckLayer<PostgresStorage<T, C>, T, Res>

Returns the final decoration of layers
source§

fn poll<Svc>(self, worker: WorkerId) -> Poller<Self::Stream, Self::Layer>

Returns a poller that is ready for streaming
source§

impl<T, C: Codec> Clone for PostgresStorage<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: Codec> Debug for PostgresStorage<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 PostgresStorage<T, C>
where T: Serialize + DeserializeOwned + Send + 'static + Unpin + Sync, C: Codec<Compact = Value> + Send + 'static,

source§

async fn push(&mut self, job: Self::Job) -> Result<TaskId, Error>

Push a job to Postgres Storage

§SQL Example
Select apalis.push_job(job_type::text, job::json);
source§

type Job = T

The type of job that can be persisted
source§

type Error = Error

The error produced by the storage
source§

type Identifier = TaskId

Jobs must have Ids.
source§

async fn schedule(&mut self, job: Self::Job, on: i64) -> Result<TaskId, Error>

Push a job into the scheduled set
source§

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

Fetch a job given an id
source§

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

Return the number of pending jobs from the queue
source§

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

Reschedule a job
source§

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

Update a job details
source§

async fn is_empty(&mut self) -> Result<bool, 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

Auto Trait Implementations§

§

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

§

impl<T, C = JsonCodec<Value>> !RefUnwindSafe for PostgresStorage<T, C>

§

impl<T, C> Send for PostgresStorage<T, C>
where T: Send, C: Send, <C as Codec>::Compact: Send,

§

impl<T, C> Sync for PostgresStorage<T, C>
where T: Sync, C: Sync, <C as Codec>::Compact: Send,

§

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

§

impl<T, C = JsonCodec<Value>> !UnwindSafe for PostgresStorage<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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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