Implement store-unload hooks
This commit is contained in:
parent
2e80c29f47
commit
2ad5cb48aa
4 changed files with 31 additions and 2 deletions
|
@ -117,7 +117,10 @@ pub fn config_is_valid(config: &Option<Value>) -> bool {
|
|||
}
|
||||
|
||||
match *config {
|
||||
Some(Value::Table(ref t)) => { has_key_with_string_ary(t, "pre-create-hook-aspects") &&
|
||||
Some(Value::Table(ref t)) => {
|
||||
has_key_with_string_ary(t, "store-unload-hook-aspects") &&
|
||||
|
||||
has_key_with_string_ary(t, "pre-create-hook-aspects") &&
|
||||
has_key_with_string_ary(t, "post-create-hook-aspects") &&
|
||||
has_key_with_string_ary(t, "pre-retrieve-hook-aspects") &&
|
||||
has_key_with_string_ary(t, "post-retrieve-hook-aspects") &&
|
||||
|
@ -143,6 +146,10 @@ pub fn config_is_valid(config: &Option<Value>) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_store_unload_aspect_names(value: &Option<Value>) -> Vec<String> {
|
||||
get_aspect_names_for_aspect_position("store-unload-hook-aspects", value)
|
||||
}
|
||||
|
||||
pub fn get_pre_create_aspect_names(value: &Option<Value>) -> Vec<String> {
|
||||
get_aspect_names_for_aspect_position("pre-create-hook-aspects", value)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#[derive(Debug, Clone)]
|
||||
pub enum HookPosition {
|
||||
StoreUnload,
|
||||
|
||||
PreCreate,
|
||||
PostCreate,
|
||||
PreRetrieve,
|
||||
|
|
|
@ -171,6 +171,8 @@ pub struct Store {
|
|||
* Registered hooks
|
||||
*/
|
||||
|
||||
store_unload_aspects : Arc<Mutex<Vec<Aspect>>>,
|
||||
|
||||
pre_create_aspects : Arc<Mutex<Vec<Aspect>>>,
|
||||
post_create_aspects : Arc<Mutex<Vec<Aspect>>>,
|
||||
pre_retrieve_aspects : Arc<Mutex<Vec<Aspect>>>,
|
||||
|
@ -216,6 +218,12 @@ impl Store {
|
|||
return Err(SE::new(SEK::StorePathExists, None));
|
||||
}
|
||||
|
||||
let store_unload_aspects = get_store_unload_aspect_names(&store_config)
|
||||
.into_iter().map(|n| {
|
||||
let cfg = AspectConfig::get_for(&store_config, n.clone());
|
||||
Aspect::new(n, cfg)
|
||||
}).collect();
|
||||
|
||||
let pre_create_aspects = get_pre_create_aspect_names(&store_config)
|
||||
.into_iter().map(|n| {
|
||||
let cfg = AspectConfig::get_for(&store_config, n.clone());
|
||||
|
@ -265,8 +273,11 @@ impl Store {
|
|||
}).collect();
|
||||
|
||||
let store = Store {
|
||||
location: location,
|
||||
location: location.clone(),
|
||||
configuration: store_config,
|
||||
|
||||
store_unload_aspects : Arc::new(Mutex::new(store_unload_aspects)),
|
||||
|
||||
pre_create_aspects : Arc::new(Mutex::new(pre_create_aspects)),
|
||||
post_create_aspects : Arc::new(Mutex::new(post_create_aspects)),
|
||||
pre_retrieve_aspects : Arc::new(Mutex::new(pre_retrieve_aspects)),
|
||||
|
@ -544,6 +555,8 @@ impl Store {
|
|||
debug!(" with aspect: {:?}", aspect_name);
|
||||
|
||||
let guard = match position {
|
||||
HookPosition::StoreUnload => self.store_unload_aspects.clone(),
|
||||
|
||||
HookPosition::PreCreate => self.pre_create_aspects.clone(),
|
||||
HookPosition::PostCreate => self.post_create_aspects.clone(),
|
||||
HookPosition::PreRetrieve => self.pre_retrieve_aspects.clone(),
|
||||
|
@ -649,6 +662,12 @@ impl Drop for Store {
|
|||
* TODO: Unlock them
|
||||
*/
|
||||
fn drop(&mut self) {
|
||||
let store_id = StoreId::from(self.location.clone());
|
||||
if let Err(e) = self.execute_hooks_for_id(self.store_unload_aspects.clone(), &store_id) {
|
||||
debug!("Store-load hooks execution failed. Cannot create store object.");
|
||||
warn!("Store Unload Hook error: {:?}", e);
|
||||
}
|
||||
|
||||
debug!("Dropping store");
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ impl HookDataAccessorProvider for DebugHook {
|
|||
use libimagstore::hook::accessor::HookDataAccessor as HDA;
|
||||
|
||||
match self.position {
|
||||
HP::StoreUnload |
|
||||
HP::PreCreate |
|
||||
HP::PreRetrieve |
|
||||
HP::PreDelete |
|
||||
|
|
Loading…
Reference in a new issue