cache: add bindings for SharedCache
This is a simple, cache implementation which can be accessed from multiple processes. It also supports storing a range of historical values. Signed-off-by: Lukas Wagner <l.wagner@proxmox.com> [wb: also update pmg-rs/Cargo.toml and both d/control files] Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
9a91594ee6
commit
ea4d87816b
@ -24,6 +24,7 @@ PERLMOD_PACKAGES := \
|
||||
Proxmox::RS::APT::Repositories \
|
||||
Proxmox::RS::CalendarEvent \
|
||||
Proxmox::RS::Notify \
|
||||
Proxmox::RS::SharedCache \
|
||||
Proxmox::RS::Subscription
|
||||
|
||||
PERLMOD_PACKAGE_FILES := $(addsuffix .pm,$(subst ::,/,$(PERLMOD_PACKAGES)))
|
||||
|
@ -2,4 +2,5 @@ pub mod apt;
|
||||
mod calendar_event;
|
||||
pub mod logger;
|
||||
pub mod notify;
|
||||
pub mod shared_cache;
|
||||
mod subscription;
|
||||
|
67
common/src/shared_cache.rs
Normal file
67
common/src/shared_cache.rs
Normal file
@ -0,0 +1,67 @@
|
||||
#[perlmod::package(name = "Proxmox::RS::SharedCache")]
|
||||
mod export {
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::Error;
|
||||
use nix::sys::stat::Mode;
|
||||
use perlmod::Value;
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value as JSONValue;
|
||||
|
||||
use proxmox_shared_cache::SharedCache;
|
||||
use proxmox_sys::fs::CreateOptions;
|
||||
|
||||
pub struct CacheWrapper(SharedCache);
|
||||
|
||||
perlmod::declare_magic!(Box<CacheWrapper> : &CacheWrapper as "Proxmox::RS::SharedCache");
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Params {
|
||||
path: String,
|
||||
owner: u32,
|
||||
group: u32,
|
||||
entry_mode: u32,
|
||||
keep_old: u32,
|
||||
}
|
||||
|
||||
#[export(raw_return)]
|
||||
fn new(#[raw] class: Value, params: Params) -> Result<Value, Error> {
|
||||
let options = CreateOptions::new()
|
||||
.owner(params.owner.into())
|
||||
.group(params.group.into())
|
||||
.perm(Mode::from_bits_truncate(params.entry_mode));
|
||||
|
||||
Ok(perlmod::instantiate_magic!(&class, MAGIC => Box::new(
|
||||
CacheWrapper (
|
||||
SharedCache::new(params.path, options, params.keep_old)?
|
||||
)
|
||||
)))
|
||||
}
|
||||
|
||||
#[export]
|
||||
fn set(
|
||||
#[try_from_ref] this: &CacheWrapper,
|
||||
value: JSONValue,
|
||||
lock_timeout: u64,
|
||||
) -> Result<(), Error> {
|
||||
this.0.set(&value, Duration::from_secs(lock_timeout))
|
||||
}
|
||||
|
||||
#[export]
|
||||
fn get(#[try_from_ref] this: &CacheWrapper) -> Result<Option<JSONValue>, Error> {
|
||||
this.0.get()
|
||||
}
|
||||
|
||||
#[export]
|
||||
fn get_last(
|
||||
#[try_from_ref] this: &CacheWrapper,
|
||||
number_of_old_entries: u32,
|
||||
) -> Result<Vec<JSONValue>, Error> {
|
||||
this.0.get_last(number_of_old_entries)
|
||||
}
|
||||
|
||||
#[export]
|
||||
fn delete(#[try_from_ref] this: &CacheWrapper, lock_timeout: u64) -> Result<(), Error> {
|
||||
this.0.delete(Duration::from_secs(lock_timeout))
|
||||
}
|
||||
}
|
@ -37,6 +37,7 @@ proxmox-http = { version = "0.9", features = ["client-sync", "client-trait"] }
|
||||
proxmox-http-error = "0.1.0"
|
||||
proxmox-log = "0.2"
|
||||
proxmox-notify = "0.4"
|
||||
proxmox-shared-cache = "0.1.0"
|
||||
proxmox-subscription = "0.4"
|
||||
proxmox-sys = "0.6"
|
||||
proxmox-tfa = { version = "5", features = ["api"] }
|
||||
|
@ -27,6 +27,7 @@ Build-Depends: cargo:native <!nocheck>,
|
||||
librust-proxmox-http-error-0.1+default-dev,
|
||||
librust-proxmox-log-0.2+default-dev,
|
||||
librust-proxmox-notify-0.4+default-dev,
|
||||
librust-proxmox-shared-cache-0.1+default-dev,
|
||||
librust-proxmox-subscription-0.4+default-dev,
|
||||
librust-proxmox-sys-0.6+default-dev,
|
||||
librust-proxmox-tfa-5+api-dev,
|
||||
|
@ -40,6 +40,7 @@ proxmox-log = "0.2"
|
||||
proxmox-notify = { version = "0.4", features = ["pve-context"] }
|
||||
proxmox-openid = "0.10"
|
||||
proxmox-resource-scheduling = "0.3.0"
|
||||
proxmox-shared-cache = "0.1.0"
|
||||
proxmox-subscription = "0.4"
|
||||
proxmox-sys = "0.6"
|
||||
proxmox-tfa = { version = "5", features = ["api"] }
|
||||
|
@ -28,6 +28,7 @@ Build-Depends: cargo:native <!nocheck>,
|
||||
librust-proxmox-notify-0.4+pve-context-dev,
|
||||
librust-proxmox-openid-0.10+default-dev,
|
||||
librust-proxmox-resource-scheduling-0.3+default-dev,
|
||||
librust-proxmox-shared-cache-0.1+default-dev,
|
||||
librust-proxmox-subscription-0.4+default-dev,
|
||||
librust-proxmox-sys-0.6+default-dev,
|
||||
librust-proxmox-tfa-5+api-dev,
|
||||
|
Loading…
Reference in New Issue
Block a user