Skip to content

Commit

Permalink
flow: fix bug (sync search error) (#891)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzIsGod1019 authored Jan 2, 2025
1 parent 1525521 commit 826587f
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 64 deletions.
15 changes: 15 additions & 0 deletions backend/middlewares/flow/src/api/cc/flow_cc_inst_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ impl FlowCcInstApi {
TardisResp::ok(result)
}

/// Start Instance(Return Instance ID)
///
/// 批量启动实例(返回实例ID)
#[oai(path = "/batch_start", method = "post")]
async fn batch_start(&self, add_batch_req: Json<Vec<FlowInstStartReq>>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
let mut funs = flow_constants::get_tardis_inst();
funs.begin().await?;
for add_req in &add_batch_req.0 {
FlowInstServ::start(add_req, None, &funs, &ctx.0).await?;
}
funs.commit().await?;
ctx.0.execute_task().await?;
TardisResp::ok(Void {})
}

/// Abort Instance
///
/// 终止实例
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl FlowCcModelVersionApi {
///
/// 获取模型使用全局owner
#[oai(path = "/:flow_version_id/global", method = "get")]
async fn gloabl_get(&self, flow_version_id: Path<String>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<FlowModelVersionDetailResp> {
async fn global_get(&self, flow_version_id: Path<String>, ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<FlowModelVersionDetailResp> {
let funs = flow_constants::get_tardis_inst();
let result = FlowModelVersionServ::get_item(
&flow_version_id.0,
Expand Down
9 changes: 9 additions & 0 deletions backend/middlewares/flow/src/dto/flow_external_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ pub struct FlowExternalReq {
///
/// 请求是否触发通知
pub notify: Option<bool>,
/// Whether the request triggers a notification
///
/// 是否人工操作
pub manual_op: Option<bool>,
/// Whether the request triggers a notification
///
/// 操作人
pub operator: Option<String>,
pub sys_time: Option<i64>,
/// 扩展字段
///
/// Extended params
Expand Down
4 changes: 3 additions & 1 deletion backend/middlewares/flow/src/dto/flow_inst_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tardis::{

use super::{
flow_model_dto::FlowModelRelTransitionExt,
flow_state_dto::{FlowStateKind, FlowStateOperatorKind, FlowStateRelModelExt, FlowStateVar, FlowSysStateKind},
flow_state_dto::{FlowGuardConf, FlowStateKind, FlowStateOperatorKind, FlowStateRelModelExt, FlowStateVar, FlowSysStateKind},
flow_transition_dto::FlowTransitionDoubleCheckInfo,
flow_var_dto::FlowVarInfo,
};
Expand Down Expand Up @@ -223,13 +223,15 @@ pub struct FLowInstStateConf {
#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object)]
pub struct FLowInstStateFormConf {
pub form_vars_collect_conf: HashMap<String, FlowStateVar>,
pub form_referral_guard_custom_conf: Option<FlowGuardConf>,
}

// 状态审批配置
#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object)]
pub struct FLowInstStateApprovalConf {
pub approval_vars_collect_conf: Option<HashMap<String, FlowStateVar>>,
pub form_vars_collect: HashMap<String, Value>,
pub approval_referral_guard_custom_conf: Option<FlowGuardConf>,
}

// 流程实例中对应的数据存储
Expand Down
4 changes: 2 additions & 2 deletions backend/middlewares/flow/src/serv/clients/search_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ impl FlowSearchClient {
kv_disable: None,
};
if let Some(_topic) = get_topic(&SPI_RPC_TOPIC) {
EventCenterClient { topic_code: SPI_RPC_TOPIC }.modify_item_and_name(SEARCH_MODEL_TAG, &key, &modify_req, funs, ctx).await?;
EventCenterClient { topic_code: SPI_RPC_TOPIC }.modify_item_and_name(SEARCH_INSTANCE_TAG, &key, &modify_req, funs, ctx).await?;
} else {
SpiSearchClient::modify_item_and_name(SEARCH_MODEL_TAG, &key, &modify_req, funs, ctx).await?;
SpiSearchClient::modify_item_and_name(SEARCH_INSTANCE_TAG, &key, &modify_req, funs, ctx).await?;
}
} else {
let add_req = SearchItemAddReq {
Expand Down
4 changes: 4 additions & 0 deletions backend/middlewares/flow/src/serv/flow_event_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ impl FlowEventServ {
&rel_bus_obj_id,
&inst_id,
Some(FlowExternalCallbackOp::PostAction),
Some(false),
None,
Some(next_flow_state.name.clone()),
Some(next_flow_state.sys_state.clone()),
Some(prev_flow_state.name.clone()),
Expand Down Expand Up @@ -398,6 +400,8 @@ impl FlowEventServ {
&flow_inst_detail.rel_business_obj_id,
&flow_inst_detail.id,
Some(FlowExternalCallbackOp::PostAction),
Some(true),
None,
Some(next_flow_state.name.clone()),
Some(next_flow_state.sys_state.clone()),
Some(prev_flow_state.name.clone()),
Expand Down
19 changes: 16 additions & 3 deletions backend/middlewares/flow/src/serv/flow_external_serv.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use bios_sdk_invoke::{clients::spi_kv_client::SpiKvClient, invoke_constants::TARDIS_CONTEXT};
use itertools::Itertools;
use tardis::{
basic::{dto::TardisContext, result::TardisResult},
log::debug,
tokio, TardisFuns, TardisFunsInst,
basic::{dto::TardisContext, result::TardisResult}, chrono::Utc, log::debug, tokio, TardisFuns, TardisFunsInst
};

use crate::{
Expand Down Expand Up @@ -47,6 +45,7 @@ impl FlowExternalServ {
changed_kind: None,
})
.collect_vec(),
sys_time: Some(Utc::now().timestamp_millis()),
..Default::default()
};
debug!("do_fetch_rel_obj body: {:?}", body);
Expand All @@ -66,12 +65,15 @@ impl FlowExternalServ {
}
}

#[allow(clippy::too_many_arguments)]
pub async fn do_async_modify_field(
tag: &str,
transition_detail: Option<FlowTransitionDetailResp>,
rel_business_obj_id: &str,
inst_id: &str,
callback_op: Option<FlowExternalCallbackOp>,
manual_op: Option<bool>,
operator: Option<String>,
target_state: Option<String>,
target_sys_state: Option<FlowSysStateKind>,
original_state: Option<String>,
Expand All @@ -93,6 +95,8 @@ impl FlowExternalServ {
&rel_business_obj_id,
&inst_id,
callback_op,
manual_op,
operator,
target_state,
target_sys_state,
original_state,
Expand All @@ -109,12 +113,15 @@ impl FlowExternalServ {
Ok(())
}

#[allow(clippy::too_many_arguments)]
pub async fn do_modify_field(
tag: &str,
transition_detail: Option<FlowTransitionDetailResp>,
rel_business_obj_id: &str,
inst_id: &str,
callback_op: Option<FlowExternalCallbackOp>,
manual_op: Option<bool>,
operator: Option<String>,
target_state: Option<String>,
target_sys_state: Option<FlowSysStateKind>,
original_state: Option<String>,
Expand Down Expand Up @@ -147,6 +154,8 @@ impl FlowExternalServ {
let body = FlowExternalReq {
kind: FlowExternalKind::ModifyField,
callback_op,
manual_op,
operator,
inst_id: inst_id.to_string(),
curr_tag: tag.to_string(),
curr_bus_obj_id: rel_business_obj_id.to_string(),
Expand All @@ -156,6 +165,7 @@ impl FlowExternalServ {
original_sys_state,
notify: transition_detail.clone().map(|tran| tran.is_notify),
transition_name: transition_detail.map(|tran| tran.name),
sys_time: Some(Utc::now().timestamp_millis()),
params,
..Default::default()
};
Expand Down Expand Up @@ -208,6 +218,7 @@ impl FlowExternalServ {
original_sys_state: Some(original_sys_state),
transition_name: Some(transition_name),
notify: Some(is_notify),
sys_time: Some(Utc::now().timestamp_millis()),
..Default::default()
};
debug!("do_notify_changes body: {:?}", body);
Expand Down Expand Up @@ -247,6 +258,7 @@ impl FlowExternalServ {
curr_bus_obj_id: "".to_string(),
owner_paths: own_paths.to_string(),
obj_ids: rel_business_obj_ids,
sys_time: Some(Utc::now().timestamp_millis()),
..Default::default()
};
debug!("do_query_field body: {:?}", body);
Expand Down Expand Up @@ -278,6 +290,7 @@ impl FlowExternalServ {
inst_id: inst_id.to_string(),
curr_tag: tag.to_string(),
curr_bus_obj_id: rel_business_obj_id.to_string(),
sys_time: Some(Utc::now().timestamp_millis()),
..Default::default()
};
debug!("do_delete_rel_obj body: {:?}", body);
Expand Down
Loading

0 comments on commit 826587f

Please sign in to comment.