Quay, splits, QoL
This commit is contained in:
parent
1d408f0734
commit
3faa1e5712
11 changed files with 1120 additions and 101 deletions
50
src/rollback.rs
Normal file
50
src/rollback.rs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Opaque reference to a pre-mutation snapshot owned by the workspace
|
||||
/// executor. Reef stores this reference as workflow metadata; it must never
|
||||
/// contain a host path or the snapshot bytes.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct RollbackReference {
|
||||
pub reference_id: Uuid,
|
||||
pub execution_id: Uuid,
|
||||
pub workspace_lease_id: Uuid,
|
||||
pub workspace_id: Uuid,
|
||||
pub project_id: Uuid,
|
||||
pub expires_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
impl RollbackReference {
|
||||
pub fn is_expired(&self, now: DateTime<Utc>) -> bool {
|
||||
self.expires_at <= now
|
||||
}
|
||||
|
||||
pub fn validates_execution(&self, execution_id: Uuid) -> bool {
|
||||
self.execution_id == execution_id && self.reference_id != Uuid::nil()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn reference() -> RollbackReference {
|
||||
RollbackReference {
|
||||
reference_id: Uuid::new_v4(),
|
||||
execution_id: Uuid::new_v4(),
|
||||
workspace_lease_id: Uuid::new_v4(),
|
||||
workspace_id: Uuid::new_v4(),
|
||||
project_id: Uuid::new_v4(),
|
||||
expires_at: Utc::now() + chrono::Duration::minutes(1),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reference_is_opaque_and_execution_bound() {
|
||||
let reference = reference();
|
||||
assert!(reference.validates_execution(reference.execution_id));
|
||||
assert!(!reference.validates_execution(Uuid::new_v4()));
|
||||
assert!(!reference.is_expired(Utc::now()));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue