Skip to content

Commit

Permalink
flow:fix timeout error (#752)
Browse files Browse the repository at this point in the history
* flow:fix timeout error

* flow: update
  • Loading branch information
ZzIsGod1019 authored May 24, 2024
1 parent 8c39ba5 commit 1beda71
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
9 changes: 2 additions & 7 deletions backend/middlewares/flow/src/api/cc/flow_cc_inst_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,8 @@ impl FlowCcInstApi {
ctx: TardisContextExtractor,
_request: &Request,
) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
let vars = HashMap::from([("current_assigned".to_string(), Value::String(modify_req.0.current_assigned))]);
FlowInstServ::modify_current_vars(&flow_inst_id.0, &vars, &funs, &ctx.0).await?;
funs.commit().await?;
FlowInstServ::modify_current_vars(&flow_inst_id.0, &vars, &ctx.0).await?;
TardisResp::ok(Void {})
}

Expand All @@ -172,9 +169,7 @@ impl FlowCcInstApi {
_request: &Request,
) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
FlowInstServ::modify_current_vars(&flow_inst_id.0, &modify_req.0.vars, &funs, &ctx.0).await?;
funs.commit().await?;
FlowInstServ::modify_current_vars(&flow_inst_id.0, &modify_req.0.vars, &ctx.0).await?;
TardisResp::ok(Void {})
}
}
10 changes: 3 additions & 7 deletions backend/middlewares/flow/src/api/ci/flow_ci_inst_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,10 @@ impl FlowCiInstApi {
mut ctx: TardisContextExtractor,
request: &Request,
) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
let funs = flow_constants::get_tardis_inst();
check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?;
funs.begin().await?;
let vars = HashMap::from([("assigned_to".to_string(), Value::String(modify_req.0.current_assigned))]);
FlowInstServ::modify_current_vars(&flow_inst_id.0, &vars, &funs, &ctx.0).await?;
funs.commit().await?;
FlowInstServ::modify_current_vars(&flow_inst_id.0, &vars, &ctx.0).await?;
TardisResp::ok(Void {})
}

Expand All @@ -140,11 +138,9 @@ impl FlowCiInstApi {
mut ctx: TardisContextExtractor,
request: &Request,
) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
let funs = flow_constants::get_tardis_inst();
check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?;
funs.begin().await?;
FlowInstServ::modify_current_vars(&flow_inst_id.0, &modify_req.0.vars, &funs, &ctx.0).await?;
funs.commit().await?;
TardisResp::ok(Void {})
}

Expand Down
11 changes: 7 additions & 4 deletions backend/middlewares/flow/src/serv/flow_inst_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,9 @@ impl FlowInstServ {
}
}

pub async fn modify_current_vars(flow_inst_id: &str, current_vars: &HashMap<String, Value>, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
pub async fn modify_current_vars(flow_inst_id: &str, current_vars: &HashMap<String, Value>, ctx: &TardisContext) -> TardisResult<()> {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
let flow_inst_detail = Self::get(flow_inst_id, funs, ctx).await?;
let mut new_vars: HashMap<String, Value> = HashMap::new();
if let Some(old_current_vars) = &flow_inst_detail.current_vars {
Expand All @@ -1116,7 +1118,9 @@ impl FlowInstServ {
..Default::default()
};
funs.db().update_one(flow_inst, ctx).await.unwrap();
funs.commit().await?;

let funs = flow_constants::get_tardis_inst();
if let Some(ws_client) = ws_flow_client().await {
ws_client
.publish_front_change(
Expand All @@ -1127,7 +1131,7 @@ impl FlowInstServ {
)
.await?;
} else {
FlowEventServ::do_front_change(flow_inst_id, ctx, funs).await?;
FlowEventServ::do_front_change(flow_inst_id, ctx, &funs).await?;
}

Ok(())
Expand Down Expand Up @@ -1214,7 +1218,6 @@ impl FlowInstServ {
Self::modify_current_vars(
&flow_inst.id,
&TardisFuns::json.json_to_obj::<HashMap<String, Value>>(new_vars).unwrap_or_default(),
funs,
&ctx,
)
.await?;
Expand All @@ -1228,7 +1231,7 @@ impl FlowInstServ {
let mut current_vars = Self::get(inst_id, funs, ctx).await?.current_vars;
if current_vars.is_none() || !current_vars.clone().unwrap_or_default().contains_key(key) {
let new_vars = Self::get_new_vars(inst_id, funs, ctx).await?;
Self::modify_current_vars(inst_id, &TardisFuns::json.json_to_obj::<HashMap<String, Value>>(new_vars).unwrap_or_default(), funs, ctx).await?;
Self::modify_current_vars(inst_id, &TardisFuns::json.json_to_obj::<HashMap<String, Value>>(new_vars).unwrap_or_default(), ctx).await?;
current_vars = Self::get(inst_id, funs, ctx).await?.current_vars;
}

Expand Down

0 comments on commit 1beda71

Please sign in to comment.