pub struct ProcessError { /* private fields */ }Expand description
A processor failure. Mark it unrecoverable to skip retries and enter DLQ.
Implementations§
Source§impl ProcessError
impl ProcessError
Sourcepub fn retryable(message: impl Into<String>) -> Self
pub fn retryable(message: impl Into<String>) -> Self
Examples found in repository?
examples/conformance_driver.rs (line 160)
148 fn process_until(&mut self, request: &Json) -> bunqueue_client::Result<()> {
149 let queue_name = text(request, "queue").to_owned();
150 let behavior = text(request, "behavior").to_owned();
151 let result = json_to_value(request["result"].clone());
152 let failed_once = Arc::new(Mutex::new(HashSet::new()));
153 let seen = failed_once.clone();
154 let processor = move |job: Job| match behavior.as_str() {
155 "unrecoverable" => Err(ProcessError::unrecoverable("conformance poison")),
156 "deepThrow" => deep_error(25),
157 "failOnce" => {
158 let mut seen = seen.lock().expect("seen mutex poisoned");
159 if seen.insert(job.id()) {
160 Err(ProcessError::retryable("conformance transient"))
161 } else {
162 Ok(result.clone())
163 }
164 }
165 _ => Ok(result.clone()),
166 };
167 let worker = Worker::new(
168 queue_name.clone(),
169 processor,
170 WorkerOptions {
171 connection: self.options.clone(),
172 batch_size: number(request, "batchSize", 10) as usize,
173 poll_timeout_ms: 300,
174 ..Default::default()
175 },
176 );
177 let runner = worker.clone();
178 let handle = thread::spawn(move || runner.run());
179 let deadline =
180 Instant::now() + Duration::from_millis(number(request, "timeoutMs", 20_000) as u64);
181 let until = &request["until"];
182 while Instant::now() < deadline {
183 let counts = self.queue(&queue_name).get_job_counts().unwrap_or_default();
184 let completed = count(&counts, "completed") >= until["completed"].as_i64().unwrap_or(0);
185 let failed = count(&counts, "failed") >= until["failed"].as_i64().unwrap_or(0);
186 let dlq = self
187 .queue(&queue_name)
188 .get_dlq(None)
189 .map(|v| v.len())
190 .unwrap_or(0)
191 >= until["dlq"].as_u64().unwrap_or(0) as usize;
192 if completed && failed && dlq {
193 worker.stop();
194 let _ = handle.join();
195 return Ok(());
196 }
197 thread::sleep(Duration::from_millis(100));
198 }
199 worker.stop();
200 let _ = handle.join();
201 Err(bunqueue_client::Error::Timeout(
202 "until condition not reached".into(),
203 ))
204 }
205}
206
207fn options(value: &Json) -> JobOptions {
208 JobOptions {
209 delay: value["delay"].as_i64(),
210 attempts: value["attempts"].as_i64(),
211 backoff: value["backoff"]
212 .as_i64()
213 .map(bunqueue_client::Backoff::Milliseconds),
214 job_id: value["jobId"].as_str().map(str::to_owned),
215 ..Default::default()
216 }
217}
218
219fn job_view(job: Option<Job>) -> Json {
220 job.map(|job| {
221 json!({
222 "id": job.id(),
223 "name": job.name(),
224 "data": value_to_json(&job.data()),
225 "stacktrace": job.stacktrace()
226 })
227 })
228 .unwrap_or(Json::Null)
229}
230
231fn deep_error(depth: usize) -> Result<Value, ProcessError> {
232 if depth == 0 {
233 Err(ProcessError::retryable("BOOM-CONFORMANCE"))
234 } else {
235 deep_error(depth - 1)
236 }
237}Sourcepub fn unrecoverable(message: impl Into<String>) -> Self
pub fn unrecoverable(message: impl Into<String>) -> Self
Examples found in repository?
examples/conformance_driver.rs (line 155)
148 fn process_until(&mut self, request: &Json) -> bunqueue_client::Result<()> {
149 let queue_name = text(request, "queue").to_owned();
150 let behavior = text(request, "behavior").to_owned();
151 let result = json_to_value(request["result"].clone());
152 let failed_once = Arc::new(Mutex::new(HashSet::new()));
153 let seen = failed_once.clone();
154 let processor = move |job: Job| match behavior.as_str() {
155 "unrecoverable" => Err(ProcessError::unrecoverable("conformance poison")),
156 "deepThrow" => deep_error(25),
157 "failOnce" => {
158 let mut seen = seen.lock().expect("seen mutex poisoned");
159 if seen.insert(job.id()) {
160 Err(ProcessError::retryable("conformance transient"))
161 } else {
162 Ok(result.clone())
163 }
164 }
165 _ => Ok(result.clone()),
166 };
167 let worker = Worker::new(
168 queue_name.clone(),
169 processor,
170 WorkerOptions {
171 connection: self.options.clone(),
172 batch_size: number(request, "batchSize", 10) as usize,
173 poll_timeout_ms: 300,
174 ..Default::default()
175 },
176 );
177 let runner = worker.clone();
178 let handle = thread::spawn(move || runner.run());
179 let deadline =
180 Instant::now() + Duration::from_millis(number(request, "timeoutMs", 20_000) as u64);
181 let until = &request["until"];
182 while Instant::now() < deadline {
183 let counts = self.queue(&queue_name).get_job_counts().unwrap_or_default();
184 let completed = count(&counts, "completed") >= until["completed"].as_i64().unwrap_or(0);
185 let failed = count(&counts, "failed") >= until["failed"].as_i64().unwrap_or(0);
186 let dlq = self
187 .queue(&queue_name)
188 .get_dlq(None)
189 .map(|v| v.len())
190 .unwrap_or(0)
191 >= until["dlq"].as_u64().unwrap_or(0) as usize;
192 if completed && failed && dlq {
193 worker.stop();
194 let _ = handle.join();
195 return Ok(());
196 }
197 thread::sleep(Duration::from_millis(100));
198 }
199 worker.stop();
200 let _ = handle.join();
201 Err(bunqueue_client::Error::Timeout(
202 "until condition not reached".into(),
203 ))
204 }pub fn message(&self) -> &str
pub fn is_unrecoverable(&self) -> bool
Trait Implementations§
Source§impl Debug for ProcessError
impl Debug for ProcessError
Source§impl Display for ProcessError
impl Display for ProcessError
Source§impl Error for ProcessError
impl Error for ProcessError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Auto Trait Implementations§
impl Forget for ProcessError
impl Freeze for ProcessError
impl Move for ProcessError
impl RefUnwindSafe for ProcessError
impl Send for ProcessError
impl Sync for ProcessError
impl Unpin for ProcessError
impl UnsafeUnpin for ProcessError
impl UnwindSafe for ProcessError
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