pub struct InventoryManager { /* private fields */ }Expand description
In-memory manager of inventory configs and last-run timestamps.
Implementations§
Source§impl InventoryManager
impl InventoryManager
pub fn new() -> Self
Sourcepub fn put(&self, config: InventoryConfig)
pub fn put(&self, config: InventoryConfig)
Insert / overwrite a configuration. Resets the matching last_run
(so the next due() call returns true, matching AWS behaviour
where a freshly-PUT inventory config triggers an inventory at the
next scheduler tick).
Sourcepub fn get(&self, bucket: &str, id: &str) -> Option<InventoryConfig>
pub fn get(&self, bucket: &str, id: &str) -> Option<InventoryConfig>
Fetch a clone of the configuration. None when not present.
Sourcepub fn list_for_bucket(&self, bucket: &str) -> Vec<InventoryConfig>
pub fn list_for_bucket(&self, bucket: &str) -> Vec<InventoryConfig>
All configurations attached to bucket (any id). The returned
vector is sorted by id for stable list responses.
Sourcepub fn list_all(&self) -> Vec<InventoryConfig>
pub fn list_all(&self) -> Vec<InventoryConfig>
Every (bucket, id, config) triple known to this manager, sorted by
(bucket, id) so the v0.7 #46 scanner walks them in deterministic
order across runs (= test reproducibility, plus stable log lines).
Used by run_scan_once; the existing
Self::list_for_bucket helper stays for the per-bucket
ListBucketInventoryConfigurations handler.
Sourcepub fn delete(&self, bucket: &str, id: &str)
pub fn delete(&self, bucket: &str, id: &str)
Drop a config + its last_run (idempotent — missing keys are OK).
Sourcepub fn due(&self, bucket: &str, id: &str, now: DateTime<Utc>) -> bool
pub fn due(&self, bucket: &str, id: &str, now: DateTime<Utc>) -> bool
true when the configuration exists and either has never run, or its
last_run + frequency_hours has elapsed by now. false when the
configuration is missing (no config = nothing to do).
Sourcepub fn mark_run(&self, bucket: &str, id: &str, when: DateTime<Utc>)
pub fn mark_run(&self, bucket: &str, id: &str, when: DateTime<Utc>)
Stamp (bucket, id) -> when so due will say “false” until the
next interval boundary.
Sourcepub fn to_json(&self) -> Result<String, Error>
pub fn to_json(&self) -> Result<String, Error>
Snapshot to JSON (operators can persist via --inventory-state-file).
Sourcepub fn from_json(s: &str) -> Result<Self, Error>
pub fn from_json(s: &str) -> Result<Self, Error>
Restore from JSON snapshot. Unknown keys (= without the separator) are silently dropped so a malformed entry can’t poison startup.
Sourcepub fn run_once_for_test<I, F>(
&self,
bucket: &str,
id: &str,
rows: I,
now: DateTime<Utc>,
write_object: F,
) -> Result<Vec<String>, RunError>
pub fn run_once_for_test<I, F>( &self, bucket: &str, id: &str, rows: I, now: DateTime<Utc>, write_object: F, ) -> Result<Vec<String>, RunError>
Run a single inventory cycle for (bucket, id) against rows,
invoking write_object(dst_bucket, dst_key, body) once for the CSV
and once for the manifest. Stamps last_run on success. Returns the
destination keys of the artefacts written ([csv_key, manifest_key]).
This is the synchronous path the unit tests + the E2E test use, and
it is what the future background scheduler in main.rs will call
after walking the source bucket. Keeping the row source as an
iterator means the inventory module never needs a back-reference to
S4Service, which sidesteps the circular dependency between the
service handler and a scheduler that lives outside S4Service.