Pool creation error handling.
This commit is contained in:
parent
c6124b9084
commit
43ec55fe9a
@ -1,4 +1,5 @@
|
|||||||
use super::{error::ViewResult, Args, Result};
|
use super::{error::ViewResult, Args, Result};
|
||||||
|
use crate::adm::result::Error;
|
||||||
use crate::dbopt::{PgPool, PooledPg};
|
use crate::dbopt::{PgPool, PooledPg};
|
||||||
use crate::fetch_places::OverpassOpt;
|
use crate::fetch_places::OverpassOpt;
|
||||||
use crate::photosdir::PhotosDir;
|
use crate::photosdir::PhotosDir;
|
||||||
@ -17,10 +18,10 @@ pub type ContextFilter = BoxedFilter<(Context,)>;
|
|||||||
type MemcachePool = Pool<MemcacheConnectionManager>;
|
type MemcachePool = Pool<MemcacheConnectionManager>;
|
||||||
type PooledMemcache = PooledConnection<MemcacheConnectionManager>;
|
type PooledMemcache = PooledConnection<MemcacheConnectionManager>;
|
||||||
|
|
||||||
pub fn create_session_filter(args: &Args) -> ContextFilter {
|
pub fn create_session_filter(args: &Args) -> Result<ContextFilter, Error> {
|
||||||
let global = Arc::new(GlobalContext::new(args));
|
let global = Arc::new(GlobalContext::new(args)?);
|
||||||
let g1 = global.clone();
|
let g1 = global.clone();
|
||||||
warp::any()
|
Ok(warp::any()
|
||||||
.and(path::full())
|
.and(path::full())
|
||||||
.and(
|
.and(
|
||||||
cookie::cookie("EXAUTH")
|
cookie::cookie("EXAUTH")
|
||||||
@ -38,7 +39,7 @@ pub fn create_session_filter(args: &Args) -> ContextFilter {
|
|||||||
let global = global.clone();
|
let global = global.clone();
|
||||||
Context { global, path, user }
|
Context { global, path, user }
|
||||||
})
|
})
|
||||||
.boxed()
|
.boxed())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Does _not_ derive debug, copy or clone, since it contains the jwt
|
// Does _not_ derive debug, copy or clone, since it contains the jwt
|
||||||
@ -52,19 +53,18 @@ struct GlobalContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl GlobalContext {
|
impl GlobalContext {
|
||||||
fn new(args: &Args) -> Self {
|
fn new(args: &Args) -> Result<Self, Error> {
|
||||||
let mc_manager =
|
let mc_manager =
|
||||||
MemcacheConnectionManager::new(args.cache.memcached_url.as_ref());
|
MemcacheConnectionManager::new(args.cache.memcached_url.as_ref());
|
||||||
GlobalContext {
|
Ok(GlobalContext {
|
||||||
db_pool: args.db.create_pool().expect("Posgresql pool"),
|
db_pool: args.db.create_pool()?,
|
||||||
photosdir: PhotosDir::new(&args.photos.photos_dir),
|
photosdir: PhotosDir::new(&args.photos.photos_dir),
|
||||||
memcache_pool: Pool::builder()
|
memcache_pool: Pool::builder()
|
||||||
.connection_timeout(Duration::from_secs(1))
|
.connection_timeout(Duration::from_secs(1))
|
||||||
.build(mc_manager)
|
.build(mc_manager)?,
|
||||||
.expect("Memcache pool"),
|
|
||||||
jwt_secret: args.jwt_key.clone(),
|
jwt_secret: args.jwt_key.clone(),
|
||||||
overpass: args.overpass.clone(),
|
overpass: args.overpass.clone(),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_key(&self, jwtstr: &str) -> Result<String, String> {
|
fn verify_key(&self, jwtstr: &str) -> Result<String, String> {
|
||||||
|
@ -75,7 +75,7 @@ pub async fn run(args: &Args) -> Result<(), Error> {
|
|||||||
if let Some(pidfile) = &args.pidfile {
|
if let Some(pidfile) = &args.pidfile {
|
||||||
handle_pid_file(pidfile, args.replace)?;
|
handle_pid_file(pidfile, args.replace)?;
|
||||||
}
|
}
|
||||||
let session_filter = create_session_filter(args);
|
let session_filter = create_session_filter(args)?;
|
||||||
let s = move || session_filter.clone();
|
let s = move || session_filter.clone();
|
||||||
use warp::filters::query::query;
|
use warp::filters::query::query;
|
||||||
use warp::path::{end, param};
|
use warp::path::{end, param};
|
||||||
|
Loading…
Reference in New Issue
Block a user