Struct please::PleaseHandle

source ·
pub struct PleaseHandle<P: ConnectionProvider> { /* private fields */ }
Expand description

This handle identifies a long-running operation using a unique integer.

Implementations§

Construct a new handle using the specified connection provider.

The connection provider is typically a connection pool of some kind, or it may be implemented by establishing a new connection each time.

The title is used as a human-readable name to identify this handle. This is useful if you are inspecting the database, or for logging expired handles.

Convenience constructor.

Equivalent to calling perform_cleanup followed by new. If you wish to handle expired handles (eg. record them to a log) then call the methods individually.

Constructor to use from within an existing transaction.

Allows conditionally creating a handle without losing the atomicity of a single transaction.

Explicitly clean up old handles. It is recommended to call this before creating a new handle.

This function returns the expired handles (if any) so that you can log them or use them for debugging.

Run a transaction as part of the operation this handle represents.

After beginning the transaction, this method validates that the handle has not expired, whilst also refreshing the expiry and taking a lock on the row, to prevent it being expired by another thread whilst this transaction is in progress.

The callback is passed two arguments: a reference to the connection, and the integer ID of this handle. Currently this is the only way to access the handle’s ID as it is not recommended to use this ID outside of a transaction.

Refreshes the handle, resetting the time before it will be automatically closed.

This is equivalent to running an empty transaction.

Expire the handle. Future operations on this handle will fail with the error Expired.

Useful for testing.

Close the handle, allowing any errors to be handled.

This is automatically called when a handle is dropped, but in that case errors are silently ignored.

Get the ID of this handle.

A good rule of thumb is to never use this outside of a transaction, as in that case it may not have been recently validated.

Trait Implementations§

Formats the value using the given formatter. Read more

Closes the handle, ignoring any errors that might have occurred.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Convert self to an expression for Diesel’s query builder. Read more
Convert &self to an expression for Diesel’s query builder. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.