Ниже показан английский оригинал.
max_lease
max_lease is how long the client keeps extending the lease of one unsettled delivery, an hour by default, and the budget of retry_after.
After a delivery has been held this long, the client stops extending its lease. The lease then runs out, and Pub/Sub redelivers the message, possibly to another consumer. A handler that may run longer than an hour needs a longer lease.
retry_after(delay) holds the delivery in the process for the delay, under this same lease.
A delay longer than max_lease is refused with PubSubError::DelayBeyondLease, and the delivery comes back at once.
The refusal keeps the delivery from coming back before the delay is over, from a lease that ran out.
Example
An invoice that is not ready comes back in ninety minutes, inside a lease of two hours. The tests advance the clock past the ninety minutes, and show that a delay of three hours comes back at once.
- Macros
- Manual
/// An invoice that is not ready comes back in ninety minutes, inside a lease of two hours.
#[subscriber(
GooglePubSub::new("flow-invoices-workers")
.create_with_topic("flow-invoices")
.max_lease(Duration::from_hours(2))
)]
async fn send(invoice: &Invoice) -> HandlerOutcome {
if !invoice.ready {
return HandlerOutcome::retry_after(NOT_READY);
}
tracing::info!(invoice.id, "invoice sent");
HandlerOutcome::ack()
}
/// An invoice that is not ready comes back in ninety minutes, inside a lease of two hours.
struct Send;
impl Handle<Invoice> for Send {
fn handle(
&self,
invoice: &Invoice,
_outs: &(),
_ctx: &mut Context<'_>,
) -> impl Future<Output = Result<(), HandlerOutcome>> {
if !invoice.ready {
return ready(Err(HandlerOutcome::retry_after(NOT_READY)));
}
tracing::info!(invoice.id, "invoice sent");
ready(Ok(()))
}
}
fn invoices() -> GooglePubSub {
GooglePubSub::new("flow-invoices-workers")
.create_with_topic("flow-invoices")
.max_lease(Duration::from_hours(2))
}