pub struct EnqueueOpts { /* private fields */ }
Implementations§
Source§impl EnqueueOpts
impl EnqueueOpts
Sourcepub fn queue<S: Into<String>>(self, queue: S) -> Self
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}
pub fn retry<RO>(self, retry: RO) -> Self
pub fn unique_for(self, unique_for: Duration) -> Self
pub fn retry_queue(self, retry_queue: String) -> Self
pub fn create_job(&self, class: String, args: impl Serialize) -> Result<Job>
Sourcepub async fn perform_async(
self,
redis: &RedisPool,
class: String,
args: impl Serialize,
) -> Result<()>
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}
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
impl<Args, W: Worker<Args>> From<&WorkerOpts<Args, W>> for EnqueueOpts
Source§fn from(opts: &WorkerOpts<Args, W>) -> Self
fn from(opts: &WorkerOpts<Args, W>) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for EnqueueOpts
impl RefUnwindSafe for EnqueueOpts
impl Send for EnqueueOpts
impl Sync for EnqueueOpts
impl Unpin for EnqueueOpts
impl UnwindSafe for EnqueueOpts
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more