2022-02-15 13:32:46 +01:00
|
|
|
use crate::{
|
|
|
|
addressing::Address,
|
|
|
|
database::{entry::Entry, UpEndConnection},
|
|
|
|
util::jobs::JobContainer,
|
|
|
|
};
|
|
|
|
use anyhow::Result;
|
|
|
|
use std::sync::{Arc, RwLock};
|
2022-02-10 11:38:45 +01:00
|
|
|
|
|
|
|
#[cfg(feature = "extractors-web")]
|
|
|
|
pub mod web;
|
2022-02-15 13:32:46 +01:00
|
|
|
|
|
|
|
pub trait Extractor {
|
2022-02-28 20:36:16 +01:00
|
|
|
fn get(
|
|
|
|
&self,
|
|
|
|
address: &Address,
|
|
|
|
job_container: Arc<RwLock<JobContainer>>,
|
|
|
|
) -> Result<Vec<Entry>>;
|
|
|
|
|
|
|
|
fn is_needed(&self, _address: &Address, _connection: &UpEndConnection) -> Result<bool> {
|
|
|
|
Ok(true)
|
|
|
|
}
|
2022-02-15 13:32:46 +01:00
|
|
|
|
2022-02-28 19:49:42 +01:00
|
|
|
fn insert_info(
|
2022-02-15 13:32:46 +01:00
|
|
|
&self,
|
2022-02-28 20:36:16 +01:00
|
|
|
address: &Address,
|
|
|
|
connection: &UpEndConnection,
|
2022-02-15 13:32:46 +01:00
|
|
|
job_container: Arc<RwLock<JobContainer>>,
|
|
|
|
) -> Result<()> {
|
2022-02-28 20:36:16 +01:00
|
|
|
if self.is_needed(address, connection)? {
|
|
|
|
let entries = self.get(address, job_container)?;
|
2022-02-15 13:32:46 +01:00
|
|
|
|
2022-02-28 20:36:16 +01:00
|
|
|
connection.transaction(|| {
|
|
|
|
for entry in entries {
|
|
|
|
connection.insert_entry(entry)?;
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
} else {
|
2022-02-28 19:49:42 +01:00
|
|
|
Ok(())
|
2022-02-28 20:36:16 +01:00
|
|
|
}
|
2022-02-15 13:32:46 +01:00
|
|
|
}
|
|
|
|
}
|