Struct EnqueueOpts

Source
pub struct EnqueueOpts { /* private fields */ }

Implementations§

Source§

impl EnqueueOpts

Source

pub fn queue<S: Into<String>>(self, queue: S) -> Self

Examples found in repository?
examples/demo.rs (line 191)
114async fn main() -> Result<()> {
115    tracing_subscriber::fmt().with_max_level(Level::INFO).init();
116
117    // Redis
118    let manager = RedisConnectionManager::new("redis://127.0.0.1/")?;
119    let redis = Pool::builder().build(manager).await?;
120
121    tokio::spawn({
122        let redis = redis.clone();
123
124        async move {
125            loop {
126                PaymentReportWorker::perform_async(
127                    &redis,
128                    PaymentReportArgs {
129                        user_guid: "USR-123".into(),
130                    },
131                )
132                .await
133                .unwrap();
134
135                tokio::time::sleep(std::time::Duration::from_secs(1)).await;
136            }
137        }
138    });
139
140    // Enqueue a job with the worker! There are many ways to do this.
141    PaymentReportWorker::perform_async(
142        &redis,
143        PaymentReportArgs {
144            user_guid: "USR-123".into(),
145        },
146    )
147    .await?;
148
149    PaymentReportWorker::perform_in(
150        &redis,
151        std::time::Duration::from_secs(10),
152        PaymentReportArgs {
153            user_guid: "USR-123".into(),
154        },
155    )
156    .await?;
157
158    PaymentReportWorker::opts()
159        .queue("brolo")
160        .perform_async(
161            &redis,
162            PaymentReportArgs {
163                user_guid: "USR-123-EXPIRED".into(),
164            },
165        )
166        .await?;
167
168    sidekiq::perform_async(
169        &redis,
170        "PaymentReportWorker".into(),
171        "yolo".into(),
172        PaymentReportArgs {
173            user_guid: "USR-123".to_string(),
174        },
175    )
176    .await?;
177
178    // Enqueue a job
179    sidekiq::perform_async(
180        &redis,
181        "PaymentReportWorker".into(),
182        "yolo".into(),
183        PaymentReportArgs {
184            user_guid: "USR-123".to_string(),
185        },
186    )
187    .await?;
188
189    // Enqueue a job with options
190    sidekiq::opts()
191        .queue("yolo".to_string())
192        .perform_async(
193            &redis,
194            "PaymentReportWorker".into(),
195            PaymentReportArgs {
196                user_guid: "USR-123".to_string(),
197            },
198        )
199        .await?;
200
201    // Sidekiq server
202    let mut p = Processor::new(redis.clone(), vec!["yolo".to_string(), "brolo".to_string()]);
203
204    // Add known workers
205    p.register(HelloWorker);
206    p.register(PaymentReportWorker::new(redis.clone()));
207
208    // Custom Middlewares
209    p.using(FilterExpiredUsersMiddleware).await;
210
211    // Reset cron jobs
212    periodic::destroy_all(redis.clone()).await?;
213
214    // Cron jobs
215    periodic::builder("0 * * * * *")?
216        .name("Payment report processing for a user using json args")
217        .queue("yolo")
218        .args(json!({ "user_guid": "USR-123-PERIODIC-FROM-JSON-ARGS" }))?
219        .register(&mut p, PaymentReportWorker::new(redis.clone()))
220        .await?;
221
222    periodic::builder("0 * * * * *")?
223        .name("Payment report processing for a user using typed args")
224        .queue("yolo")
225        .args(PaymentReportArgs {
226            user_guid: "USR-123-PERIODIC-FROM-TYPED-ARGS".to_string(),
227        })?
228        .register(&mut p, PaymentReportWorker::new(redis.clone()))
229        .await?;
230
231    p.run().await;
232    Ok(())
233}
Source

pub fn retry<RO>(self, retry: RO) -> Self
where RO: Into<RetryOpts>,

Source

pub fn unique_for(self, unique_for: Duration) -> Self

Source

pub fn retry_queue(self, retry_queue: String) -> Self

Source

pub fn create_job(&self, class: String, args: impl Serialize) -> Result<Job>

Source

pub async fn perform_async( self, redis: &RedisPool, class: String, args: impl Serialize, ) -> Result<()>

Examples found in repository?
examples/demo.rs (lines 192-198)
114async fn main() -> Result<()> {
115    tracing_subscriber::fmt().with_max_level(Level::INFO).init();
116
117    // Redis
118    let manager = RedisConnectionManager::new("redis://127.0.0.1/")?;
119    let redis = Pool::builder().build(manager).await?;
120
121    tokio::spawn({
122        let redis = redis.clone();
123
124        async move {
125            loop {
126                PaymentReportWorker::perform_async(
127                    &redis,
128                    PaymentReportArgs {
129                        user_guid: "USR-123".into(),
130                    },
131                )
132                .await
133                .unwrap();
134
135                tokio::time::sleep(std::time::Duration::from_secs(1)).await;
136            }
137        }
138    });
139
140    // Enqueue a job with the worker! There are many ways to do this.
141    PaymentReportWorker::perform_async(
142        &redis,
143        PaymentReportArgs {
144            user_guid: "USR-123".into(),
145        },
146    )
147    .await?;
148
149    PaymentReportWorker::perform_in(
150        &redis,
151        std::time::Duration::from_secs(10),
152        PaymentReportArgs {
153            user_guid: "USR-123".into(),
154        },
155    )
156    .await?;
157
158    PaymentReportWorker::opts()
159        .queue("brolo")
160        .perform_async(
161            &redis,
162            PaymentReportArgs {
163                user_guid: "USR-123-EXPIRED".into(),
164            },
165        )
166        .await?;
167
168    sidekiq::perform_async(
169        &redis,
170        "PaymentReportWorker".into(),
171        "yolo".into(),
172        PaymentReportArgs {
173            user_guid: "USR-123".to_string(),
174        },
175    )
176    .await?;
177
178    // Enqueue a job
179    sidekiq::perform_async(
180        &redis,
181        "PaymentReportWorker".into(),
182        "yolo".into(),
183        PaymentReportArgs {
184            user_guid: "USR-123".to_string(),
185        },
186    )
187    .await?;
188
189    // Enqueue a job with options
190    sidekiq::opts()
191        .queue("yolo".to_string())
192        .perform_async(
193            &redis,
194            "PaymentReportWorker".into(),
195            PaymentReportArgs {
196                user_guid: "USR-123".to_string(),
197            },
198        )
199        .await?;
200
201    // Sidekiq server
202    let mut p = Processor::new(redis.clone(), vec!["yolo".to_string(), "brolo".to_string()]);
203
204    // Add known workers
205    p.register(HelloWorker);
206    p.register(PaymentReportWorker::new(redis.clone()));
207
208    // Custom Middlewares
209    p.using(FilterExpiredUsersMiddleware).await;
210
211    // Reset cron jobs
212    periodic::destroy_all(redis.clone()).await?;
213
214    // Cron jobs
215    periodic::builder("0 * * * * *")?
216        .name("Payment report processing for a user using json args")
217        .queue("yolo")
218        .args(json!({ "user_guid": "USR-123-PERIODIC-FROM-JSON-ARGS" }))?
219        .register(&mut p, PaymentReportWorker::new(redis.clone()))
220        .await?;
221
222    periodic::builder("0 * * * * *")?
223        .name("Payment report processing for a user using typed args")
224        .queue("yolo")
225        .args(PaymentReportArgs {
226            user_guid: "USR-123-PERIODIC-FROM-TYPED-ARGS".to_string(),
227        })?
228        .register(&mut p, PaymentReportWorker::new(redis.clone()))
229        .await?;
230
231    p.run().await;
232    Ok(())
233}
Source

pub async fn perform_in( &self, redis: &RedisPool, class: String, duration: Duration, args: impl Serialize, ) -> Result<()>

Trait Implementations§

Source§

impl<Args, W: Worker<Args>> From<&WorkerOpts<Args, W>> for EnqueueOpts

Source§

fn from(opts: &WorkerOpts<Args, W>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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

Source§

type Output = T

Should always be Self
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,