mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-22 14:57:56 +01:00
Simple machine lmdb interface
This commit is contained in:
parent
4fde079986
commit
13e784cf7a
@ -16,6 +16,8 @@ use capnp::Error;
|
|||||||
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use lmdb::{Transaction, RwTransaction};
|
||||||
|
|
||||||
/// Status of a Machine
|
/// Status of a Machine
|
||||||
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
|
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||||
pub enum Status {
|
pub enum Status {
|
||||||
@ -167,10 +169,10 @@ impl MachineDB {
|
|||||||
Self { db }
|
Self { db }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_machine<T: Transaction>(&self, txn: &T, machine_id: MachineIdentifier)
|
pub fn get_machine<T: Transaction>(&self, txn: &T, uuid: Uuid)
|
||||||
-> Result<Option<Machine>>
|
-> Result<Option<Machine>>
|
||||||
{
|
{
|
||||||
match txn.get(self.db, &machine_id.to_ne_bytes()) {
|
match txn.get(self.db, &uuid.as_bytes()) {
|
||||||
Ok(bytes) => {
|
Ok(bytes) => {
|
||||||
Ok(Some(flexbuffers::from_slice(bytes)?))
|
Ok(Some(flexbuffers::from_slice(bytes)?))
|
||||||
},
|
},
|
||||||
@ -178,6 +180,15 @@ impl MachineDB {
|
|||||||
Err(e) => { Err(e.into()) },
|
Err(e) => { Err(e.into()) },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn put_machine( &self, txn: &mut RwTransaction, uuid: Uuid, machine: Machine)
|
||||||
|
-> Result<()>
|
||||||
|
{
|
||||||
|
let bytes = flexbuffers::to_vec(machine)?;
|
||||||
|
txn.put(self.db, &uuid.as_bytes(), &bytes, lmdb::WriteFlags::empty())?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn init(log: Logger, config: &Settings) -> Result<MachinesProvider> {
|
pub async fn init(log: Logger, config: &Settings) -> Result<MachinesProvider> {
|
||||||
|
Loading…
Reference in New Issue
Block a user