Skip to content

Commit

Permalink
activity: use bytesize for Volume size & preallocate
Browse files Browse the repository at this point in the history
  • Loading branch information
kamirr committed Aug 20, 2024
1 parent 9fe951f commit c74a2b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
7 changes: 4 additions & 3 deletions model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ with-diesel = ['diesel']
sgx = ['secp256k1', 'openssl', 'hex', 'secp256k1/serde']

[dependencies]
bigdecimal = { version = "0.2", features = ["serde"]}
chrono = { version = "0.4", features = ["serde"]}
bigdecimal = { version = "0.2", features = ["serde"] }
bytesize = { version = "1.3.0", features = ["serde"] }
chrono = { version = "0.4", features = ["serde"] }
derive_more = "0.99"
rand = "0.8"
serde = { version = "1.0.146", features = ["derive"] }
Expand All @@ -27,7 +28,7 @@ strum_macros = "0.24.3"
thiserror = "1.0"

diesel = { version = "1.4", optional = true }
hex = { version = "0.4", optional = true}
hex = { version = "0.4", optional = true }
secp256k1 = { workspace = true, optional = true }
openssl = { version = "0.10", optional = true }

Expand Down
21 changes: 12 additions & 9 deletions model/src/activity/exe_script_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

use crate::activity::ExeScriptCommandState;
use bytesize::ByteSize;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

Expand Down Expand Up @@ -52,15 +53,15 @@ pub enum VolumeMount {
Ram {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
size: Option<String>,
size: Option<ByteSize>,
},
Storage {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
size: Option<String>,
size: Option<ByteSize>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
preallocate: Option<String>,
preallocate: Option<ByteSize>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
errors: Option<String>,
Expand Down Expand Up @@ -215,6 +216,8 @@ impl From<ExeScriptCommand> for ExeScriptCommandState {

#[cfg(test)]
mod test {
use bytesize::ByteSize;

use super::Volumes;
use crate::activity::exe_script_command::{VolumeInfo, VolumeMount};
use std::collections::HashMap;
Expand Down Expand Up @@ -280,13 +283,13 @@ mod test {
"/golem/output": {},
"/storage": {
"storage": {
"size": "10g",
"preallocate": "2g"
"size": "10GiB",
"preallocate": "2GiB"
}
},
"/": {
"ram": {
"size": "1g"
"size": "1024MiB"
}
}
}"#;
Expand All @@ -302,15 +305,15 @@ mod test {
map.insert(
"/storage".to_string(),
VolumeInfo::Mount(VolumeMount::Storage {
size: Some("10g".to_string()),
preallocate: Some("2g".to_string()),
size: Some(ByteSize::gib(10)),
preallocate: Some(ByteSize::gib(2)),
errors: None,
}),
);
map.insert(
"/".to_string(),
VolumeInfo::Mount(VolumeMount::Ram {
size: Some("1g".to_string()),
size: Some(ByteSize::b(1073741824)),
}),
);
map
Expand Down

0 comments on commit c74a2b3

Please sign in to comment.