mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-24 23:57:38 +01:00
Basic implementation of TraceStorage
This commit is contained in:
parent
89ae390dfe
commit
e9b7ad9161
3 changed files with 60 additions and 1 deletions
|
@ -170,4 +170,4 @@ pub use storage::{RedisStorage, RedisStorageError};
|
||||||
#[cfg(feature = "sqlite-storage")]
|
#[cfg(feature = "sqlite-storage")]
|
||||||
pub use storage::{SqliteStorage, SqliteStorageError};
|
pub use storage::{SqliteStorage, SqliteStorageError};
|
||||||
|
|
||||||
pub use storage::{serializer, InMemStorage, Serializer, Storage};
|
pub use storage::{serializer, InMemStorage, Serializer, Storage, TraceStorage};
|
||||||
|
|
|
@ -2,6 +2,8 @@ pub mod serializer;
|
||||||
|
|
||||||
mod in_mem_storage;
|
mod in_mem_storage;
|
||||||
|
|
||||||
|
mod trace_storage;
|
||||||
|
|
||||||
#[cfg(feature = "redis-storage")]
|
#[cfg(feature = "redis-storage")]
|
||||||
mod redis_storage;
|
mod redis_storage;
|
||||||
|
|
||||||
|
@ -11,6 +13,8 @@ mod sqlite_storage;
|
||||||
use futures::future::BoxFuture;
|
use futures::future::BoxFuture;
|
||||||
|
|
||||||
pub use in_mem_storage::InMemStorage;
|
pub use in_mem_storage::InMemStorage;
|
||||||
|
pub use trace_storage::TraceStorage;
|
||||||
|
|
||||||
#[cfg(feature = "redis-storage")]
|
#[cfg(feature = "redis-storage")]
|
||||||
// FIXME(waffle): use `docsrs` here when issue with combine is resolved <https://github.com/teloxide/teloxide/pull/305#issuecomment-716172103>
|
// FIXME(waffle): use `docsrs` here when issue with combine is resolved <https://github.com/teloxide/teloxide/pull/305#issuecomment-716172103>
|
||||||
#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "redis-storage")))]
|
#[cfg_attr(all(teloxide_docsrs, feature = "nightly"), doc(cfg(feature = "redis-storage")))]
|
||||||
|
|
55
src/dispatching/dialogue/storage/trace_storage.rs
Normal file
55
src/dispatching/dialogue/storage/trace_storage.rs
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
use std::{fmt::Debug, sync::Arc};
|
||||||
|
|
||||||
|
use futures::future::BoxFuture;
|
||||||
|
use log::trace;
|
||||||
|
|
||||||
|
use super::Storage;
|
||||||
|
|
||||||
|
/// Storage wrapper for logging purposes
|
||||||
|
///
|
||||||
|
/// Reports about any dialogue update or removal action on `trace` level
|
||||||
|
pub struct TraceStorage<S> {
|
||||||
|
inner: Arc<S>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S> TraceStorage<S> {
|
||||||
|
#[must_use]
|
||||||
|
pub fn new(inner: Arc<S>) -> Arc<Self> {
|
||||||
|
Arc::new(Self { inner })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn into_inner(self) -> Arc<S> {
|
||||||
|
self.inner
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S, D> Storage<D> for TraceStorage<S>
|
||||||
|
where
|
||||||
|
D: Debug,
|
||||||
|
S: Storage<D>,
|
||||||
|
{
|
||||||
|
type Error = <S as Storage<D>>::Error;
|
||||||
|
|
||||||
|
fn remove_dialogue(
|
||||||
|
self: Arc<Self>,
|
||||||
|
chat_id: i64,
|
||||||
|
) -> BoxFuture<'static, Result<Option<D>, Self::Error>>
|
||||||
|
where
|
||||||
|
D: Send + 'static,
|
||||||
|
{
|
||||||
|
trace!("Removing dialogue with {}", chat_id);
|
||||||
|
<S as Storage<D>>::remove_dialogue(self.inner.clone(), chat_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_dialogue(
|
||||||
|
self: Arc<Self>,
|
||||||
|
chat_id: i64,
|
||||||
|
dialogue: D,
|
||||||
|
) -> BoxFuture<'static, Result<Option<D>, Self::Error>>
|
||||||
|
where
|
||||||
|
D: Send + 'static,
|
||||||
|
{
|
||||||
|
trace!("Updating dialogue with {}: {:#?}", chat_id, dialogue);
|
||||||
|
<S as Storage<D>>::update_dialogue(self.inner.clone(), chat_id, dialogue)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue