-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement client artifact pusher that uses github
- Loading branch information
Showing
7 changed files
with
130 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
crates/maelstrom-client-process/src/artifact_pusher/github.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use crate::artifact_pusher::{construct_upload_name, start_task_inner, Receiver}; | ||
use crate::progress::{ProgressTracker, UploadProgressReader}; | ||
use anyhow::Result; | ||
use maelstrom_base::Sha256Digest; | ||
use maelstrom_github::{FileStreamBuilder, GitHubClient, SeekableStream}; | ||
use maelstrom_util::async_fs::Fs; | ||
use std::{path::PathBuf, sync::Arc}; | ||
use tokio::task::JoinSet; | ||
|
||
pub async fn push_one_artifact( | ||
github_client: Arc<GitHubClient>, | ||
upload_tracker: ProgressTracker, | ||
path: PathBuf, | ||
digest: Sha256Digest, | ||
success_callback: Box<dyn FnOnce() + Send + Sync>, | ||
) -> Result<()> { | ||
let fs = Fs::new(); | ||
let file = fs.open_file(&path).await?; | ||
let size = file.metadata().await?.len(); | ||
|
||
let upload_name = construct_upload_name(&digest, &path); | ||
let prog = upload_tracker.new_task(&upload_name, size); | ||
|
||
let artifact_name = format!("maelstrom-cache-sha256-{digest}"); | ||
let file_stream = FileStreamBuilder::new(file.into_inner()).build().await?; | ||
let stream = Box::new(UploadProgressReader::new(prog, file_stream)) as Box<dyn SeekableStream>; | ||
github_client.upload(&artifact_name, stream).await?; | ||
|
||
success_callback(); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[expect(dead_code)] | ||
pub fn start_task( | ||
join_set: &mut JoinSet<Result<()>>, | ||
receiver: Receiver, | ||
github_client: Arc<GitHubClient>, | ||
upload_tracker: ProgressTracker, | ||
) { | ||
start_task_inner( | ||
join_set, | ||
receiver, | ||
move |_, path, digest, success_callback| { | ||
let upload_tracker = upload_tracker.clone(); | ||
let github_client = github_client.clone(); | ||
async move { | ||
push_one_artifact( | ||
github_client, | ||
upload_tracker, | ||
path, | ||
digest, | ||
success_callback, | ||
) | ||
.await | ||
.map(|()| ((), ())) | ||
} | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters