Skip to main content

Job

Struct Job 

Source
pub struct Job<M>
where M: Executable + Clone,
{ pub context: JobContext, pub data: M, }

Fields§

§context: JobContext§data: M

Implementations§

Source§

impl<M> Job<M>
where M: Executable + Clone,

Source

pub fn new(job: M) -> Job<M>

Create a new job.

#[derive(BackgroundJob, Serialize, Deserialize, Debug, Clone)]
pub struct Print {
   pub number: i32,
}

#[aj::async_trait]
impl Execute for Print {
    type Output = ();

    async fn execute(&mut self, _: &JobContext) -> Self::Output {
        println!("Hello, {}", self.number);
    }
}

let job = Job::new(Print {
    number: 1,
})
Source

pub fn id(&self) -> &str

Get Job Id

Source

pub fn set_id(self, id: String) -> Job<M>

Custom job id

Source

pub fn set_context(self, context: JobContext) -> Job<M>

Source

pub fn context(self, context: JobContext) -> Job<M>

Source

pub fn set_job_type(self, job_type: JobType) -> Job<M>

Set Job Type

Source

pub fn job_type(self, job_type: JobType) -> Job<M>

Source

pub fn schedule_at(self, schedule_at: DateTime<Utc>) -> Job<M>

Schedule job to run at specific time

job.schedule_at(get_now() + Duration::seconds(2));
Source

pub fn delay(self, after: TimeDelta) -> Job<M>

Schedule job to run after specific time

job.delay(Duration::seconds(2));
Source

pub fn cron(self, cron_expression: &str) -> Job<M>

Schedule job run by Cron Pattern

job.cron("* * * * * * *");
Source

pub fn set_retry(self, retry: Retry) -> Job<M>

Set Retry logic for job job.set_retry(aj::Retry::default())

Source

pub fn retry(self, retry: Retry) -> Job<M>

Source§

impl<M> Job<M>
where M: Executable + Clone + Serialize + Sync + Send + 'static,

Source

pub fn is_ready(&self) -> bool

Source

pub fn is_queued(&self) -> bool

Source

pub fn is_running(&self) -> bool

Source

pub fn is_cancelled(&self) -> bool

Source§

impl<M> Job<M>

Source

pub async fn run(self) -> Result<String, Error>

It will wait to WorkQueue received and insert job into backend

Source

pub fn just_run(self)

It will just send message to WorkQueue and no gurantee job is inserted to backend

Trait Implementations§

Source§

impl<M> Clone for Job<M>
where M: Clone + Executable,

Source§

fn clone(&self) -> Job<M>

Returns a duplicate 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<M> Debug for Job<M>
where M: Debug + Executable + Clone,

Source§

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

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

impl<'de, M> Deserialize<'de> for Job<M>
where M: Executable + Clone + Deserialize<'de>,

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Job<M>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<M> Serialize for Job<M>
where M: Executable + Clone + Serialize,

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<M> Freeze for Job<M>
where M: Freeze,

§

impl<M> RefUnwindSafe for Job<M>
where M: RefUnwindSafe,

§

impl<M> Send for Job<M>
where M: Send,

§

impl<M> Sync for Job<M>
where M: Sync,

§

impl<M> Unpin for Job<M>
where M: Unpin,

§

impl<M> UnwindSafe for Job<M>
where M: UnwindSafe,

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<A, T> DynMessage<A> for T
where A: Actor + Message<T>, T: Send + 'static,

Source§

fn handle_dyn( self: Box<T>, state: &mut A, actor_ref: ActorRef<A>, tx: Option<Sender<Result<Box<dyn Any + Send>, SendError<Box<dyn Any + Send>, Box<dyn Any + Send>>>>>, ) -> Pin<Box<dyn Future<Output = Option<Box<dyn Debug + Send>>> + Send + '_>>

Handles the dyn message with the provided actor state, ref, and reply sender.
Source§

fn as_any(self: Box<T>) -> Box<dyn Any>

Casts the type to a Box<dyn Any>.
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> 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<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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,