Skip to content

Commit

Permalink
feat: fix progress update bug (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
Extheoisah authored Nov 27, 2024
1 parent c819109 commit 0631969
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 3 additions & 6 deletions src/app/progress/update_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,18 @@ pub async fn update_progress(soft_serve_url: &str, user_id: &Uuid) -> Result<Pro
}

// check progress.progress_details object for "current_step"
// if current_step is equal to module_count, then set status to completed
// else, set current_step to current_step + 1
// if new_current_step is equal to module_count, then set status to completed
let current_step = progress
.progress_details
.as_ref()
.and_then(|details| details["current_step"].as_i64())
.unwrap_or(0);
let mut new_status = Status::InProgress.to_str().to_string();
let mut new_current_step = current_step;
let new_current_step = current_step + 1;
let module_count = challenge.module_count as i64;

if current_step == module_count {
if new_current_step == module_count {
new_status = Status::Completed.to_str().to_string();
} else {
new_current_step = current_step + 1;
}

let updated_progress = Progress::update_progress(
Expand Down
12 changes: 10 additions & 2 deletions src/service/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use futures_util::StreamExt;
use lapin::{options::*, types::FieldTable, Connection, ConnectionProperties};
use log::error;
use serde::{Deserialize, Serialize};
use serde_json::json;

use crate::app::{
progress::update_progress::update_progress, repo::match_repo::match_repo_for_webhook,
Expand Down Expand Up @@ -173,8 +174,15 @@ async fn consume_test_queue(
return Err(anyhow::anyhow!("Failed to update progress"));
}
};
let combined_message =
serde_json::to_string(&(test_runner_payload, updated_progress))?;
let combined_payload = json!({
"event_type": test_runner_payload.event_type,
"repoUrl": test_runner_payload.repo_url,
"commitSha": test_runner_payload.commit_sha,
"success": test_runner_payload.success,
"output": test_runner_payload.output,
"progress": updated_progress
});
let combined_message = serde_json::to_string(&combined_payload)?;
if let Err(e) = manager_handle
.broadcast_to_session(&session.token, Message::Text(combined_message.into()))
.await
Expand Down

0 comments on commit 0631969

Please sign in to comment.