Commit 62e81714 authored by Aljaž Srebrnič's avatar Aljaž Srebrnič

Don't panic if we lose the Redis pool

parent 8915dd16
......@@ -370,6 +370,7 @@ name = "mittelab-status"
version = "0.1.0"
dependencies = [
"env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"r2d2 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)",
"r2d2_redis 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"redis 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
......
......@@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
spaceapi-server = "*"
env_logger = "*"
log = "^0.4"
r2d2 = "0.8"
r2d2_redis = "0.9.0"
redis = "0.10"
use std::time::Duration;
extern crate spaceapi_server;
#[macro_use] extern crate log;
extern crate env_logger;
extern crate r2d2_redis;
......@@ -30,7 +31,14 @@ impl OpenStatusFromRedisModifier {
impl StatusModifier for OpenStatusFromRedisModifier {
fn modify(&self, status: &mut api::Status) {
let conn = self.pool.get().unwrap();
let conn = match self.pool.get() {
Err(e) => {
error!("Error getting redis pool: {:#?}", e);
return;
}
Ok(c) => c
};
let state : RedisResult<String> = conn.get("state_open");
status.state.open = match state {
Ok(v) => Some(v == "open"),
......@@ -53,7 +61,14 @@ impl KeymastersFromRedisModifier {
impl StatusModifier for KeymastersFromRedisModifier {
fn modify(&self, status: &mut api::Status) {
let conn = self.pool.get().unwrap(); // XXX Remove unwrap
let conn = match self.pool.get() {
Err(e) => {
error!("Error getting redis pool: {:#?}", e);
return;
}
Ok(c) => c
};
let km_redis : Vec<String> = conn.zrange("keys", 0, -1).unwrap();
let mut km : Vec<Keymaster> = Vec::new();
for k in km_redis {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment