mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2025-07-05 02:14:17 +00:00
moved store saving to main
This commit is contained in:
parent
fda61c1a5a
commit
39746f59f7
@ -44,14 +44,8 @@ impl IDStore {
|
|||||||
|
|
||||||
/// Add a new id for the current day
|
/// Add a new id for the current day
|
||||||
/// Returns false if ID is already present at the current day.
|
/// Returns false if ID is already present at the current day.
|
||||||
/// Can fail because the store will be saved to a file.
|
pub fn add_id(&mut self, id: TallyID) -> bool {
|
||||||
pub fn add_id(&mut self, id: TallyID) -> Result<bool, Box<dyn Error>> {
|
self.get_current_day().add_id(id)
|
||||||
if self.get_current_day().add_id(id) {
|
|
||||||
self.export_json("./data.json")?;
|
|
||||||
return Ok(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the `AttendanceDay` of the current day
|
/// Get the `AttendanceDay` of the current day
|
||||||
|
17
src/main.rs
17
src/main.rs
@ -67,20 +67,17 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let channel_store = store.clone();
|
let channel_store = store.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Some(tally_id_string) = rx.recv().await {
|
while let Some(tally_id_string) = rx.recv().await {
|
||||||
match channel_store
|
if channel_store
|
||||||
.lock()
|
.lock()
|
||||||
.await
|
.await
|
||||||
.add_id(id_store::TallyID(tally_id_string))
|
.add_id(id_store::TallyID(tally_id_string))
|
||||||
{
|
{
|
||||||
Ok(added) => {
|
info!("Added new id to current day");
|
||||||
if added {
|
// TODO: trigger the buzzer
|
||||||
debug!("~Beep~ Added new ID");
|
|
||||||
// TODO: Add buzzer here
|
if let Err(e) = channel_store.lock().await.export_json(STORE_PATH) {
|
||||||
}
|
error!("Failed to save id store to file: {}", e);
|
||||||
}
|
// TODO: How to handle a failure to save ?
|
||||||
Err(e) => {
|
|
||||||
error!("Failed to save id to the store: {}", e);
|
|
||||||
// TODO: What to do if the ID could not be saved ?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user