upend/src/extractors/mod.rs

32 lines
750 B
Rust
Raw Normal View History

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