Skip to content

Commit

Permalink
fix not counted progress
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdaGastan committed Jul 29, 2024
1 parent 1862904 commit e1ce143
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docker2fl/src/docker2fl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ impl DockerImageToFlist {
.await
.context("failed to pack flist")?;

log::info!("flist has been created successfully");
Ok(())
}

pub async fn convert<S: Store>(&mut self, store: S, sender: Option<Sender<i32>>) -> Result<()> {
self.prepare().await?;
self.pack(store, sender).await?;

log::info!("flist has been created successfully");
Ok(())
}
}
Expand Down
28 changes: 15 additions & 13 deletions fl-server/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub enum FlistState {
#[derive(Debug, Clone, Serialize)]
pub struct FlistStateInfo {
msg: String,
progress: usize,
progress: f32,
}

#[utoipa::path(
Expand Down Expand Up @@ -221,9 +221,7 @@ pub async fn create_flist_handler(
);

let res = docker_to_fl.prepare().await;
// remove the file created with the writer if fl creation failed
if res.is_err() {
let _ = tokio::fs::remove_file(&fl_path).await;
state.jobs_state.lock().unwrap().insert(
job.id.clone(),
FlistState::Failed(format!("flist preparing '{}' has failed", fl_name)),
Expand All @@ -232,17 +230,21 @@ pub async fn create_flist_handler(
}

let files_count = docker_to_fl.files_count();
let st = state.clone();
let job_id = job.id.clone();
tokio::spawn(async move {
for _ in 0..files_count {
let step = rx.recv().unwrap() as usize;
// state.jobs_state.lock().unwrap().insert(
// job.id.clone(),
// FlistState::InProgress(FlistStateInfo {
// msg: "flist is in progress".to_string(),
// progress: step / files_count * 100,
// }),
// ); //TODO:
log::info!("val '{}'", step / files_count * 100);
let mut progress: f32 = 0.0;

for _ in 0..files_count - 1 {
let step = rx.recv().unwrap() as f32;
progress += step;
st.jobs_state.lock().unwrap().insert(
job_id.clone(),
FlistState::InProgress(FlistStateInfo {
msg: "flist is in progress".to_string(),
progress: progress / files_count as f32 * 100.0,
}),
);
}
});

Expand Down
2 changes: 1 addition & 1 deletion rfs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn pack(opts: PackOptions) -> Result<()> {
rt.block_on(async move {
let store = store::parse_router(opts.store.as_slice()).await?;
let meta = fungi::Writer::new(opts.meta).await?;
rfs::pack(meta, store, opts.target, !opts.no_strip_password).await?;
rfs::pack(meta, store, opts.target, !opts.no_strip_password, None).await?;

Ok(())
})
Expand Down
16 changes: 8 additions & 8 deletions rfs/src/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ async fn pack_one<S: Store>(
let meta = child.metadata().await?;
let child_path = path.join(&name);

if sender.is_some() {
sender
.clone()
.unwrap()
.send(1)
.context("failed to send progress")?;
}

// if this child a directory we add to the tail of the list
if meta.is_dir() {
list.push_back(Item(current, child_path.clone(), name, meta));
Expand Down Expand Up @@ -178,14 +186,6 @@ async fn pack_one<S: Store>(
worker
.send((child_ino, child_path))
.context("failed to schedule file upload")?;

if sender.is_some() {
sender
.clone()
.unwrap()
.send(1)
.context("failed to send progress")?;
}
}
Ok(())
}
Expand Down

0 comments on commit e1ce143

Please sign in to comment.