Skip to content

Commit

Permalink
Update to tardis 0.1.0 rc.2 (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
4t145 authored Oct 26, 2023
1 parent 7e4c668 commit 2edfe69
Show file tree
Hide file tree
Showing 97 changed files with 395 additions and 354 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ lazy_static = { version = "1" }
itertools = { version = "0" }
fancy-regex = { version = "0" }
run_script = { version = "0.10" }
testcontainers-modules = { version = "0.1"}
strum ={ version = "0.25", features = ["derive"] }
# tardis
tardis = { version = "=0.1.0-beta.12" }
tardis = { version = "=0.1.0-rc.2" }
# tardis = { path = "../tardis/tardis" }
# tardis = { git = "https://github.com/ideal-world/tardis.git", rev = "9424e16" }

#spacegate
spacegate-kernel = { git = "https://github.com/ideal-world/spacegate.git", rev = "aac2989e48b6064c31db4dedcc30b3c4135b399d",features = [
spacegate-kernel = { git = "https://github.com/ideal-world/spacegate.git", rev = "ed34d33",features = [
"ws",
"cache",
"k8s",
Expand Down
1 change: 1 addition & 0 deletions basic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ itertools.workspace = true
fancy-regex.workspace = true
tardis = { workspace = true, optional = true }
strum = { workspace = true }
testcontainers-modules ={ workspace = true }
[dev-dependencies]
tardis = { workspace = true, features = ["test"] }

Expand Down
14 changes: 7 additions & 7 deletions basic/src/process/task_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl TaskProcessor {

pub async fn init_task(cache_key: &str, cache_client: &TardisCacheClient) -> TardisResult<i64> {
//todo change to SnowFlake or other distributed ID generator
let task_id = Local::now().timestamp_nanos();
let task_id = Local::now().timestamp_nanos_opt().expect("maybe in 23rd centery");
let max: i64 = u32::MAX.into();
let task_id_split1: usize = (task_id / max).try_into()?;
let task_id_split2: usize = (task_id % max).try_into()?;
Expand Down Expand Up @@ -97,13 +97,13 @@ impl TaskProcessor {
P: FnOnce(i64) -> T + Send + Sync + 'static,
T: Future<Output = TardisResult<()>> + Send + 'static,
{
let task_id = TaskProcessor::init_task(cache_key, funs.cache()).await?;
let task_id = TaskProcessor::init_task(cache_key, &funs.cache()).await?;
let cache_client = funs.cache();
let cache_key = cache_key.to_string();
let handle = tardis::tokio::spawn(async move {
let result = process(task_id).await;
match result {
Ok(_) => match TaskProcessor::set_status(&cache_key, task_id, true, cache_client).await {
Ok(_) => match TaskProcessor::set_status(&cache_key, task_id, true, &cache_client).await {
Ok(_) => {}
Err(e) => log::error!("Asynchronous task [{}] process error:{:?}", task_id, e),
},
Expand All @@ -117,7 +117,7 @@ impl TaskProcessor {
}

pub async fn execute_task_external(cache_key: &str, funs: &TardisFunsInst) -> TardisResult<i64> {
let task_id = TaskProcessor::init_task(cache_key, funs.cache()).await?;
let task_id = TaskProcessor::init_task(cache_key, &funs.cache()).await?;
Ok(task_id)
}

Expand All @@ -136,7 +136,7 @@ impl TaskProcessor {
}

pub async fn stop_task(cache_key: &str, task_id: i64, funs: &TardisFunsInst) -> TardisResult<()> {
if TaskProcessor::check_status(cache_key, task_id, funs.cache()).await? {
if TaskProcessor::check_status(cache_key, task_id, &funs.cache()).await? {
TASK_HANDLE.write().await.remove(&task_id);
} else {
funs.mq()
Expand All @@ -155,7 +155,7 @@ impl TaskProcessor {
}

pub async fn stop_task_external(cache_key: &str, task_id: i64, funs: &TardisFunsInst) -> TardisResult<()> {
match TaskProcessor::set_status(cache_key, task_id, true, funs.cache()).await {
match TaskProcessor::set_status(cache_key, task_id, true, &funs.cache()).await {
Ok(_) => {}
Err(e) => log::error!("Asynchronous task [{}] stop error:{:?}", task_id, e),
}
Expand All @@ -166,7 +166,7 @@ impl TaskProcessor {
match TASK_HANDLE.write().await.remove(&task_id) {
Some(handle) => {
handle.abort();
match TaskProcessor::set_status(cache_key, task_id, true, funs.cache()).await {
match TaskProcessor::set_status(cache_key, task_id, true, &funs.cache()).await {
Ok(_) => {}
Err(e) => log::error!("Asynchronous task [{}] stop error:{:?}", task_id, e),
}
Expand Down
2 changes: 1 addition & 1 deletion basic/src/rbum/dto/rbum_safe_dto.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde::{Deserialize, Serialize};
use serde::{Serialize};
#[cfg(feature = "default")]
use tardis::db::sea_orm;
use tardis::{
Expand Down
26 changes: 13 additions & 13 deletions basic/src/rbum/rbum_initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ pub async fn init(code: &str, config: RbumConfig) -> TardisResult<()> {
}
tx.begin().await?;
TardisFuns::dict.add("__RBUM_INIT__", "", "", &tx).await?;
tx.init(rbum_domain::ActiveModel::init(db_kind, Some("update_time"), compatible_type.clone())).await?;
tx.init(rbum_kind::ActiveModel::init(db_kind, Some("update_time"), compatible_type.clone())).await?;
tx.init(rbum_item::ActiveModel::init(db_kind, Some("update_time"), compatible_type.clone())).await?;
tx.init(rbum_kind_attr::ActiveModel::init(db_kind, Some("update_time"), compatible_type.clone())).await?;
tx.init(rbum_item_attr::ActiveModel::init(db_kind, Some("update_time"), compatible_type.clone())).await?;
tx.init(rbum_rel::ActiveModel::init(db_kind, Some("update_time"), compatible_type.clone())).await?;
tx.init(rbum_rel_attr::ActiveModel::init(db_kind, Some("update_time"), compatible_type.clone())).await?;
tx.init(rbum_rel_env::ActiveModel::init(db_kind, Some("update_time"), compatible_type.clone())).await?;
tx.init(rbum_cert_conf::ActiveModel::init(db_kind, Some("update_time"), compatible_type.clone())).await?;
tx.init(rbum_cert::ActiveModel::init(db_kind, Some("update_time"), compatible_type.clone())).await?;
tx.init(rbum_set::ActiveModel::init(db_kind, Some("update_time"), compatible_type.clone())).await?;
tx.init(rbum_set_cate::ActiveModel::init(db_kind, Some("update_time"), compatible_type.clone())).await?;
tx.init(rbum_set_item::ActiveModel::init(db_kind, Some("update_time"), compatible_type.clone())).await?;
tx.init(rbum_domain::ActiveModel::init(db_kind, Some("update_time"), compatible_type)).await?;
tx.init(rbum_kind::ActiveModel::init(db_kind, Some("update_time"), compatible_type)).await?;
tx.init(rbum_item::ActiveModel::init(db_kind, Some("update_time"), compatible_type)).await?;
tx.init(rbum_kind_attr::ActiveModel::init(db_kind, Some("update_time"), compatible_type)).await?;
tx.init(rbum_item_attr::ActiveModel::init(db_kind, Some("update_time"), compatible_type)).await?;
tx.init(rbum_rel::ActiveModel::init(db_kind, Some("update_time"), compatible_type)).await?;
tx.init(rbum_rel_attr::ActiveModel::init(db_kind, Some("update_time"), compatible_type)).await?;
tx.init(rbum_rel_env::ActiveModel::init(db_kind, Some("update_time"), compatible_type)).await?;
tx.init(rbum_cert_conf::ActiveModel::init(db_kind, Some("update_time"), compatible_type)).await?;
tx.init(rbum_cert::ActiveModel::init(db_kind, Some("update_time"), compatible_type)).await?;
tx.init(rbum_set::ActiveModel::init(db_kind, Some("update_time"), compatible_type)).await?;
tx.init(rbum_set_cate::ActiveModel::init(db_kind, Some("update_time"), compatible_type)).await?;
tx.init(rbum_set_item::ActiveModel::init(db_kind, Some("update_time"), compatible_type)).await?;
tx.commit().await?;
Ok(())
}
Expand Down
14 changes: 7 additions & 7 deletions basic/src/rbum/serv/rbum_cert_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ impl RbumCrudOperation<rbum_cert_conf::ActiveModel, RbumCertConfAddReq, RbumCert
Query::select()
.column(rbum_cert_conf::Column::Id)
.from(rbum_cert_conf::Entity)
.and_where(Expr::col(rbum_cert_conf::Column::Kind).eq(add_req.kind.0.as_str()))
.and_where(Expr::col(rbum_cert_conf::Column::Supplier).eq(add_req.supplier.as_ref().unwrap_or(&TrimString("".to_string())).0.as_str()))
.and_where(Expr::col(rbum_cert_conf::Column::Kind).eq(add_req.kind.as_str()))
.and_where(Expr::col(rbum_cert_conf::Column::Supplier).eq(add_req.supplier.as_ref().unwrap_or(&TrimString("".to_string())).as_str()))
.and_where(Expr::col(rbum_cert_conf::Column::RelRbumDomainId).eq(add_req.rel_rbum_domain_id.as_str()))
.and_where(Expr::col(rbum_cert_conf::Column::RelRbumItemId).eq(add_req.rel_rbum_item_id.as_ref().unwrap_or(&"".to_string()).as_str())),
)
Expand Down Expand Up @@ -437,7 +437,7 @@ impl RbumCrudOperation<rbum_cert::ActiveModel, RbumCertAddReq, RbumCertModifyReq
// Encrypt Sk
if rbum_cert_conf.sk_encrypted {
if let Some(sk) = &add_req.sk {
let sk = Self::encrypt_sk(&sk.0, &add_req.ak.0, rel_rbum_cert_conf_id)?;
let sk = Self::encrypt_sk(sk, &add_req.ak, rel_rbum_cert_conf_id)?;
add_req.sk = Some(TrimString(sk));
}
}
Expand Down Expand Up @@ -510,7 +510,7 @@ impl RbumCrudOperation<rbum_cert::ActiveModel, RbumCertAddReq, RbumCertModifyReq
}
}
if let Some(vcode) = &add_req.vcode {
Self::add_vcode_to_cache(add_req.ak.0.as_str(), vcode.0.as_str(), &ctx.own_paths, funs).await?;
Self::add_vcode_to_cache(add_req.ak.as_str(), vcode.as_str(), &ctx.own_paths, funs).await?;
}
Ok(())
}
Expand Down Expand Up @@ -581,7 +581,7 @@ impl RbumCrudOperation<rbum_cert::ActiveModel, RbumCertAddReq, RbumCertModifyReq
return Err(funs.err().conflict(&Self::get_obj_name(), "modify", "sk cannot be empty", "409-rbum-cert-ak-duplicate"));
}
if let Some(sk) = &modify_req.sk {
let sk = Self::encrypt_sk(&sk.0, modify_req.ak.as_ref().unwrap_or(&TrimString(rbum_cert.ak)).as_ref(), rel_rbum_cert_conf_id)?;
let sk = Self::encrypt_sk(sk, modify_req.ak.as_ref().unwrap_or(&TrimString(rbum_cert.ak)).as_ref(), rel_rbum_cert_conf_id)?;
modify_req.sk = Some(TrimString(sk));
}
}
Expand Down Expand Up @@ -1201,7 +1201,7 @@ impl RbumCertServ {
.column(rbum_cert::Column::Id)
.from(rbum_cert::Entity)
.and_where(Expr::col(rbum_cert::Column::RelRbumKind).eq(add_req.rel_rbum_kind.to_int()))
.and_where(Expr::col(rbum_cert::Column::Ak).eq(add_req.ak.0.as_str()))
.and_where(Expr::col(rbum_cert::Column::Ak).eq(add_req.ak.as_str()))
.and_where(Expr::col(rbum_cert::Column::RelRbumCertConfId).eq(add_req.rel_rbum_cert_conf_id.clone()))
.and_where(Expr::col(rbum_cert::Column::OwnPaths).like(format!("{}%", ctx.own_paths).as_str())),
)
Expand Down Expand Up @@ -1260,7 +1260,7 @@ impl RbumCertServ {
Query::select()
.column(rbum_cert::Column::Id)
.from(rbum_cert::Entity)
.and_where(Expr::col(rbum_cert::Column::Ak).eq(modify_req.ak.as_ref().unwrap().0.as_str()))
.and_where(Expr::col(rbum_cert::Column::Ak).eq(modify_req.ak.as_ref().unwrap().as_str()))
.and_where(Expr::col(rbum_cert::Column::RelRbumCertConfId).eq(rbum_cert_conf.id.clone()))
.and_where(Expr::col(rbum_cert::Column::OwnPaths).like(format!("{}%", ctx.own_paths).as_str()))
.and_where(Expr::col(rbum_cert::Column::Id).ne(id.to_string().as_str())),
Expand Down
4 changes: 2 additions & 2 deletions basic/src/rbum/serv/rbum_domain_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ impl RbumCrudOperation<rbum_domain::ActiveModel, RbumDomainAddReq, RbumDomainMod
}

async fn before_add_rbum(add_req: &mut RbumDomainAddReq, funs: &TardisFunsInst, _: &TardisContext) -> TardisResult<()> {
if !R_URL_PART_CODE.is_match(add_req.code.0.as_str()) {
if !R_URL_PART_CODE.is_match(add_req.code.as_str()) {
return Err(funs.err().bad_request(&Self::get_obj_name(), "add", &format!("code {} is invalid", add_req.code), "400-rbum-*-code-illegal"));
}
if funs
.db()
.count(Query::select().column(rbum_domain::Column::Id).from(rbum_domain::Entity).and_where(Expr::col(rbum_domain::Column::Code).eq(add_req.code.0.as_str())))
.count(Query::select().column(rbum_domain::Column::Id).from(rbum_domain::Entity).and_where(Expr::col(rbum_domain::Column::Code).eq(add_req.code.as_str())))
.await?
> 0
{
Expand Down
8 changes: 4 additions & 4 deletions basic/src/rbum/serv/rbum_item_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl RbumCrudOperation<rbum_item::ActiveModel, RbumItemAddReq, RbumItemKernelMod
}

async fn package_add(add_req: &RbumItemAddReq, funs: &TardisFunsInst, _: &TardisContext) -> TardisResult<rbum_item::ActiveModel> {
let id = if let Some(id) = &add_req.id { id.0.clone() } else { TardisFuns::field.nanoid() };
let id = if let Some(id) = &add_req.id { id.to_string() } else { TardisFuns::field.nanoid() };
let code = if let Some(code) = &add_req.code {
if funs
.db()
Expand All @@ -64,14 +64,14 @@ impl RbumCrudOperation<rbum_item::ActiveModel, RbumItemAddReq, RbumItemKernelMod
rbum_kind::Entity,
Expr::col((rbum_kind::Entity, rbum_kind::Column::Id)).equals((rbum_item::Entity, rbum_item::Column::RelRbumKindId)),
)
.and_where(Expr::col((rbum_item::Entity, rbum_item::Column::Code)).eq(code.0.as_str())),
.and_where(Expr::col((rbum_item::Entity, rbum_item::Column::Code)).eq(code.as_str())),
)
.await?
> 0
{
return Err(funs.err().conflict(&Self::get_obj_name(), "add", &format!("code {code} already exists"), "409-rbum-*-code-exist"));
}
code.0.clone()
code.to_string()
} else {
id.clone()
};
Expand Down Expand Up @@ -113,7 +113,7 @@ impl RbumCrudOperation<rbum_item::ActiveModel, RbumItemAddReq, RbumItemKernelMod
rbum_kind::Entity,
Expr::col((rbum_kind::Entity, rbum_kind::Column::Id)).equals((rbum_item::Entity, rbum_item::Column::RelRbumKindId)),
)
.and_where(Expr::col((rbum_item::Entity, rbum_item::Column::Code)).eq(code.0.as_str()))
.and_where(Expr::col((rbum_item::Entity, rbum_item::Column::Code)).eq(code.as_str()))
.and_where(Expr::col((rbum_item::Entity, rbum_item::Column::Id)).ne(id)),
)
.await?
Expand Down
8 changes: 4 additions & 4 deletions basic/src/rbum/serv/rbum_kind_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ impl RbumCrudOperation<rbum_kind::ActiveModel, RbumKindAddReq, RbumKindModifyReq
}

async fn before_add_rbum(add_req: &mut RbumKindAddReq, funs: &TardisFunsInst, _: &TardisContext) -> TardisResult<()> {
if !R_URL_PART_CODE.is_match(add_req.code.0.as_str()) {
if !R_URL_PART_CODE.is_match(add_req.code.as_str()) {
return Err(funs.err().bad_request(&Self::get_obj_name(), "add", &format!("code {} is invalid", add_req.code), "400-rbum-*-code-illegal"));
}
if funs.db().count(Query::select().column(rbum_kind::Column::Id).from(rbum_kind::Entity).and_where(Expr::col(rbum_kind::Column::Code).eq(add_req.code.0.as_str()))).await?
if funs.db().count(Query::select().column(rbum_kind::Column::Id).from(rbum_kind::Entity).and_where(Expr::col(rbum_kind::Column::Code).eq(add_req.code.as_str()))).await?
> 0
{
return Err(funs.err().conflict(&Self::get_obj_name(), "add", &format!("code {} already exists", add_req.code), "409-rbum-*-code-exist"));
Expand Down Expand Up @@ -188,8 +188,8 @@ impl RbumCrudOperation<rbum_kind_attr::ActiveModel, RbumKindAttrAddReq, RbumKind
Query::select()
.column(rbum_kind_attr::Column::Id)
.from(rbum_kind_attr::Entity)
.and_where(Expr::col(rbum_kind_attr::Column::Name).eq(add_req.name.0.as_str()))
.and_where(Expr::col(rbum_kind_attr::Column::Module).eq(add_req.module.as_ref().unwrap_or(&TrimString("".to_string())).0.as_str()))
.and_where(Expr::col(rbum_kind_attr::Column::Name).eq(add_req.name.as_str()))
.and_where(Expr::col(rbum_kind_attr::Column::Module).eq(add_req.module.as_ref().unwrap_or(&TrimString("".to_string())).as_str()))
.and_where(Expr::col(rbum_kind_attr::Column::RelRbumKindId).eq(add_req.rel_rbum_kind_id.as_str()))
.and_where(Expr::col(rbum_kind_attr::Column::OwnPaths).like(format!("{}%", ctx.own_paths).as_str())),
)
Expand Down
4 changes: 2 additions & 2 deletions basic/src/spi/serv/spi_bs_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ impl SpiBsServ {
)
.await?
{
let attrs = attrs.unwrap_or(vec![]);
let envs = envs.unwrap_or(vec![]);
let attrs = attrs.unwrap_or_default();
let envs = envs.unwrap_or_default();
RbumRelServ::add_rel(
&mut RbumRelAggAddReq {
rel: RbumRelAddReq {
Expand Down
19 changes: 10 additions & 9 deletions basic/src/spi/spi_initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub mod common_pg {

use tardis::{
basic::{dto::TardisContext, error::TardisError, result::TardisResult},
config::config_dto::DBModuleConfig,
db::{
reldb_client::{TardisRelDBClient, TardisRelDBlConnection},
sea_orm::Value,
Expand Down Expand Up @@ -170,14 +171,14 @@ pub mod common_pg {
pub async fn init(bs_cert: &SpiBsCertResp, ctx: &TardisContext, mgr: bool) -> TardisResult<SpiBsInst> {
let ext = TardisFuns::json.str_to_json(&bs_cert.ext)?;
let compatible_type = TardisFuns::json.json_to_obj(ext.get("compatible_type").unwrap_or(&tardis::serde_json::Value::String("None".to_string())).clone())?;
let client = TardisRelDBClient::init(
&bs_cert.conn_uri,
ext.get("max_connections").unwrap().as_u64().unwrap() as u32,
ext.get("min_connections").unwrap().as_u64().unwrap() as u32,
None,
None,
let client = TardisRelDBClient::init(&DBModuleConfig {
url: bs_cert.conn_uri.parse().expect("invalid url"),
max_connections: ext.get("max_connections").unwrap().as_u64().unwrap() as u32,
min_connections: ext.get("min_connections").unwrap().as_u64().unwrap() as u32,
connect_timeout_sec: None,
idle_timeout_sec: None,
compatible_type,
)
})
.await?;
let mut ext = HashMap::new();
let schema_name = if bs_cert.private {
Expand Down Expand Up @@ -206,7 +207,7 @@ pub mod common_pg {
primary_keys: Option<Vec<&str>>,
update_time_field: Option<&str>,
) -> TardisResult<(TardisRelDBlConnection, String)> {
let tag = tag.map(|t| format!("_{t}")).unwrap_or_else(|| "".to_string());
let tag = tag.map(|t| format!("_{t}")).unwrap_or_default();
let conn = bs_inst.0.conn();
let schema_name = get_schema_name_from_ext(bs_inst.1).unwrap();
if check_table_exit(&format!("{table_flag}{tag}"), &conn, ctx).await? {
Expand Down Expand Up @@ -236,7 +237,7 @@ pub mod common_pg {
update_time_field: Option<&str>,
ctx: &TardisContext,
) -> TardisResult<()> {
let tag = tag.map(|t| format!("_{t}")).unwrap_or_else(|| "".to_string());
let tag = tag.map(|t| format!("_{t}")).unwrap_or_default();
let schema_name = get_schema_name_from_context(ctx);
do_init_table(&schema_name, conn, &tag, table_flag, table_create_content, indexes, primary_keys, update_time_field).await
}
Expand Down
4 changes: 2 additions & 2 deletions basic/src/test/init_rbum_test_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::env;
use tardis::basic::result::TardisResult;
use tardis::test::test_container::TardisTestContainer;
use tardis::testcontainers::clients::Cli;
use tardis::testcontainers::images::generic::GenericImage;
use tardis::testcontainers::images::redis::Redis;
use tardis::testcontainers::GenericImage;
use testcontainers_modules::redis::Redis;
use tardis::testcontainers::Container;
use tardis::TardisFuns;

Expand Down
Loading

0 comments on commit 2edfe69

Please sign in to comment.