fix: add custom logging handler (elucidate db locked errors?)

feat/type-attributes
Tomáš Mládek 2022-10-23 13:46:42 +02:00
parent 74d35e4065
commit b5b05ed852
2 changed files with 13 additions and 2 deletions

View File

@ -35,7 +35,7 @@ use std::fs;
use std::path::{Path, PathBuf};
use std::sync::{Arc, RwLock};
use std::time::Duration;
use tracing::{debug, trace};
use tracing::{debug, error, trace};
#[derive(Debug)]
pub struct ConnectionOptions {
@ -72,6 +72,15 @@ impl diesel::r2d2::CustomizeConnection<SqliteConnection, diesel::r2d2::Error>
type DbPool = r2d2::Pool<ConnectionManager<SqliteConnection>>;
#[derive(Debug)]
pub struct LoggingHandler {}
impl diesel::r2d2::HandleError<diesel::r2d2::Error> for LoggingHandler {
fn handle_error(&self, error: diesel::r2d2::Error) {
error!("{}", error);
}
}
pub struct OpenResult {
pub db: UpEndDatabase,
pub new: bool,
@ -112,6 +121,7 @@ impl UpEndDatabase {
enable_foreign_keys: true,
busy_timeout: Some(Duration::from_secs(30)),
}))
.error_handler(Box::new(LoggingHandler {}))
.build(manager)?;
trace!("Pool created.");

View File

@ -10,7 +10,7 @@ use crate::database::entry::{Entry, InvariantEntry};
use crate::database::hierarchies::{
resolve_path, resolve_path_cached, ResolveCache, UHierPath, UNode,
};
use crate::database::{UpEndConnection, UpEndDatabase, UPEND_SUBDIR};
use crate::database::{LoggingHandler, UpEndConnection, UpEndDatabase, UPEND_SUBDIR};
use crate::util::hash::{b58_encode, Hash, Hashable};
use crate::util::jobs::{JobContainer, JobHandle};
use anyhow::{anyhow, Error, Result};
@ -122,6 +122,7 @@ impl FsStore {
let pool = r2d2::Pool::builder()
.connection_customizer(Box::new(ConnectionOptions {}))
.error_handler(Box::new(LoggingHandler {}))
.build(manager)?;
let lock = Arc::new(RwLock::new(()));