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 19:49:42 +01:00
|
|
|
fn get(&self, address: Address, job_container: Arc<RwLock<JobContainer>>)
|
|
|
|
-> Result<Vec<Entry>>;
|
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,
|
|
|
|
address: Address,
|
|
|
|
connection: UpEndConnection,
|
|
|
|
job_container: Arc<RwLock<JobContainer>>,
|
|
|
|
) -> Result<()> {
|
2022-02-28 19:49:42 +01:00
|
|
|
let entries = self.get(address, job_container)?;
|
2022-02-15 13:32:46 +01:00
|
|
|
|
2022-02-28 19:49:42 +01:00
|
|
|
connection.transaction(|| {
|
|
|
|
for entry in entries {
|
|
|
|
connection.insert_entry(entry)?;
|
|
|
|
}
|
|
|
|
Ok(())
|
2022-02-15 13:32:46 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|