Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into download-restart
Browse files Browse the repository at this point in the history
  • Loading branch information
Devdutt Shenoi committed Apr 2, 2024
2 parents aa46feb + 155fbaa commit a075ef2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
2 changes: 0 additions & 2 deletions uplink/src/base/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ pub struct Action {
// action id
#[serde(alias = "id")]
pub action_id: String,
// determines if action is a process
pub kind: String,
// action name
pub name: String,
// action payload. json. can be args/payload. depends on the invoked command
Expand Down
10 changes: 0 additions & 10 deletions uplink/src/base/bridge/actions_lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,6 @@ mod tests {

let action_1 = Action {
action_id: "1".to_string(),
kind: "test".to_string(),
name: "route_1".to_string(),
payload: "test".to_string(),
deadline: None,
Expand All @@ -584,7 +583,6 @@ mod tests {

let action_2 = Action {
action_id: "2".to_string(),
kind: "test".to_string(),
name: "route_2".to_string(),
payload: "test".to_string(),
deadline: None,
Expand Down Expand Up @@ -628,7 +626,6 @@ mod tests {

let action_1 = Action {
action_id: "1".to_string(),
kind: "test".to_string(),
name: "test".to_string(),
payload: "test".to_string(),
deadline: None,
Expand All @@ -643,7 +640,6 @@ mod tests {

let action_2 = Action {
action_id: "2".to_string(),
kind: "test".to_string(),
name: "test".to_string(),
payload: "test".to_string(),
deadline: None,
Expand Down Expand Up @@ -684,7 +680,6 @@ mod tests {

let action = Action {
action_id: "1".to_string(),
kind: "test".to_string(),
name: "test".to_string(),
payload: "test".to_string(),
deadline: None,
Expand Down Expand Up @@ -749,7 +744,6 @@ mod tests {

let action = Action {
action_id: "1".to_string(),
kind: "test".to_string(),
name: "test".to_string(),
payload: "test".to_string(),
deadline: None,
Expand Down Expand Up @@ -819,7 +813,6 @@ mod tests {

let action = Action {
action_id: "1".to_string(),
kind: "tunshell".to_string(),
name: "launch_shell".to_string(),
payload: "test".to_string(),
deadline: None,
Expand All @@ -830,7 +823,6 @@ mod tests {

let action = Action {
action_id: "2".to_string(),
kind: "test".to_string(),
name: "test".to_string(),
payload: "test".to_string(),
deadline: None,
Expand Down Expand Up @@ -910,7 +902,6 @@ mod tests {

let action = Action {
action_id: "1".to_string(),
kind: "test".to_string(),
name: "test".to_string(),
payload: "test".to_string(),
deadline: None,
Expand All @@ -921,7 +912,6 @@ mod tests {

let action = Action {
action_id: "2".to_string(),
kind: "tunshell".to_string(),
name: "launch_shell".to_string(),
payload: "test".to_string(),
deadline: None,
Expand Down
27 changes: 14 additions & 13 deletions uplink/src/collector/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ impl FileDownloader {

// Forward progress as action response to bridge
async fn forward_progress(&mut self, progress: u8) {
let status = ActionResponse::progress(&self.action_id, "Downloading", progress);
let status = status.set_sequence(self.sequence());
let status = ActionResponse::progress(&self.action_id, "Downloading", progress)
.set_sequence(self.sequence());
self.bridge_tx.send_action_response(status).await;
}

Expand All @@ -214,13 +214,11 @@ impl FileDownloader {
let deadline = *state.current.action.deadline.as_ref().unwrap();

select! {
o = timeout_at(deadline, self.continuous_retry(&mut state)) => {
// NOTE: if download has timedout don't do anything
match o {
Ok(r) => r?,
Err(_) => error!("Last download has timedout"),
}
}
// NOTE: if download has timedout don't do anything
o = timeout_at(deadline, self.continuous_retry(&mut state)) => match o {
Ok(r) => r?,
Err(_) => error!("Last download has timedout"),
},

_ = shutdown_rx.recv_async() => {
if let Err(e) = state.save(&self.config) {
Expand Down Expand Up @@ -259,11 +257,17 @@ impl FileDownloader {
};
let chunk = match item {
Ok(c) => c,
Err(e) => {
Err(e) if !e.is_status() => {
let status =
ActionResponse::progress(&self.action_id, "Download Failed", 0)
.set_sequence(self.sequence())
.add_error(e.to_string());
self.bridge_tx.send_action_response(status).await;
error!("Download failed: {e}");
tokio::time::sleep(Duration::from_secs(1)).await;
continue 'outer;
}
Err(e) => return Err(Error::Reqwest(e)),
};
if let Some(percentage) = state.write_bytes(&chunk)? {
self.forward_progress(percentage).await;
Expand Down Expand Up @@ -607,7 +611,6 @@ mod test {
expected_forward.download_path = Some(downloader_path);
let download_action = Action {
action_id: "1".to_string(),
kind: "firmware_update".to_string(),
name: "firmware_update".to_string(),
payload: json!(download_update).to_string(),
deadline: Some(Instant::now() + Duration::from_secs(60)),
Expand Down Expand Up @@ -670,7 +673,6 @@ mod test {
};
let correct_action = Action {
action_id: "1".to_string(),
kind: "firmware_update".to_string(),
name: "firmware_update".to_string(),
payload: json!(correct_update).to_string(),
deadline: Some(Instant::now() + Duration::from_secs(100)),
Expand Down Expand Up @@ -709,7 +711,6 @@ mod test {
};
let wrong_action = Action {
action_id: "1".to_string(),
kind: "firmware_update".to_string(),
name: "firmware_update".to_string(),
payload: json!(wrong_update).to_string(),
deadline: Some(Instant::now() + Duration::from_secs(100)),
Expand Down
2 changes: 0 additions & 2 deletions uplink/src/collector/script_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ mod tests {
actions_tx
.send(Action {
action_id: "1".to_string(),
kind: "1".to_string(),
name: "test".to_string(),
payload: "".to_string(),
deadline: None,
Expand All @@ -200,7 +199,6 @@ mod tests {
actions_tx
.send(Action {
action_id: "1".to_string(),
kind: "1".to_string(),
name: "test".to_string(),
payload: "{\"url\": \"...\", \"content_length\": 0,\"file_name\": \"...\"}"
.to_string(),
Expand Down

0 comments on commit a075ef2

Please sign in to comment.