-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store auction with liquidity #2663
Changes from 4 commits
40e8098
d6e1313
ecbc9b7
70fd46d
5a7f087
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use { | ||
crate::{domain::competition::auction::Id, infra::solver::Config}, | ||
serde::Deserialize, | ||
std::sync::Arc, | ||
tracing::Instrument, | ||
}; | ||
|
||
#[derive(Clone, Debug, Default, Deserialize)] | ||
#[serde(rename_all = "kebab-case", deny_unknown_fields)] | ||
m-lord-renkse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub struct S3 { | ||
/// The s3_instance_upload_* arguments configure how auction instances | ||
/// should be uploaded to AWS S3. | ||
/// They must either all be set or all not set. | ||
m-lord-renkse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub bucket: String, | ||
|
||
/// Prepended to the auction id to form the final instance filename on S3. | ||
/// Something like "staging/mainnet/" | ||
pub prefix: String, | ||
} | ||
|
||
impl From<S3> for s3::Config { | ||
fn from(value: S3) -> Self { | ||
Self { | ||
bucket: value.bucket, | ||
filename_prefix: value.prefix, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Persistence { | ||
s3: Option<Arc<s3::Uploader>>, | ||
} | ||
|
||
impl Persistence { | ||
pub async fn build(config: &Config) -> Self { | ||
if let Some(s3) = &config.s3 { | ||
Self { | ||
s3: Some(Arc::new(s3::Uploader::new(s3.clone().into()).await)), | ||
} | ||
} else { | ||
Self { s3: None } | ||
} | ||
} | ||
|
||
/// Saves the given auction with liquidity with fire and forget mentality | ||
/// (non-blocking operation) | ||
pub fn archive_auction(&self, auction_id: Option<Id>, body: &str) { | ||
let Some(uploader) = self.s3.clone() else { | ||
return; | ||
}; | ||
let Some(id) = auction_id else { | ||
return; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deciding that auctions without ids (i.e. quote requests) should not be uploaded seems like a domain decision to me. If Also there should be a comment somewhere explaining why we only store auctions which have an id. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! I'll move it to the domain logic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, that's right. Those are the quote requests which don't really make sense to store. |
||
let body = body.to_string(); | ||
tokio::spawn( | ||
async move { | ||
match uploader.upload(id.to_string(), body).await { | ||
Ok(key) => { | ||
tracing::info!(?key, "uploaded auction to s3"); | ||
m-lord-renkse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
Err(err) => { | ||
tracing::warn!(?err, "failed to upload auction to s3"); | ||
} | ||
} | ||
} | ||
.instrument(tracing::Span::current()), | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like this is needed.