From 590a4719a8d6e04fbdb8cfe3cd2d125bd54a743a Mon Sep 17 00:00:00 2001 From: hunjixin <1084400399@qq.com> Date: Fri, 9 Aug 2024 11:21:43 +0000 Subject: [PATCH] fix: clippy --- .github/workflows/rust.yml | 18 ++++++++++++++++++ src/bin/jz-flow/job.rs | 10 +--------- src/dbrepo/job_db_mongo.rs | 3 +-- src/driver/kube.rs | 18 ++++++------------ src/job/job_mgr.rs | 10 +++------- 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2306614..6d8b692 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -17,6 +17,24 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: clippy rustfmt + + - name: Set up cargo cache + uses: actions/cache@v3 + continue-on-error: false + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + - name: Run Clippy run: cargo +nightly clippy --fix --workspace --exclude jiaozifs_client_rs --allow-dirty diff --git a/src/bin/jz-flow/job.rs b/src/bin/jz-flow/job.rs index 77fdd62..614100d 100644 --- a/src/bin/jz-flow/job.rs +++ b/src/bin/jz-flow/job.rs @@ -1,12 +1,4 @@ -use std::{ - io::{ - self, - stdout, - }, - iter, - os::linux::raw::stat, - str::FromStr, -}; +use std::str::FromStr; use crate::global::GlobalOptions; use anyhow::Result; diff --git a/src/dbrepo/job_db_mongo.rs b/src/dbrepo/job_db_mongo.rs index c0bca61..7be66cf 100644 --- a/src/dbrepo/job_db_mongo.rs +++ b/src/dbrepo/job_db_mongo.rs @@ -1,4 +1,3 @@ -use std::os::linux::raw::stat; use crate::{ core::db::{ @@ -259,7 +258,7 @@ impl DataRepo for MongoRunDbRepo { direction: Option<&Direction>, ) -> Result { let mut query = doc! {"node_name":node_name}; - if states.len() > 0 { + if !states.is_empty() { let states: Vec<&str> = states.iter().map(to_variant_name).try_collect()?; query.insert("state", doc! {"$in": states}); } diff --git a/src/driver/kube.rs b/src/driver/kube.rs index cc9c6e8..9b31805 100644 --- a/src/driver/kube.rs +++ b/src/driver/kube.rs @@ -39,12 +39,8 @@ use handlebars::{ RenderContext, RenderError, }; -use k8s_metrics::{ - v1beta1 as metricsv1, - QuantityExt, -}; -use k8s_openapi::{ - api::{ +use k8s_metrics::v1beta1 as metricsv1; +use k8s_openapi::api::{ apps::v1::StatefulSet, core::v1::{ Namespace, @@ -52,9 +48,7 @@ use k8s_openapi::{ Pod, Service, }, - }, - apimachinery::pkg::api::resource::Quantity, -}; + }; use kube::{ api::{ DeleteParams, @@ -145,7 +139,7 @@ where let mut node_status = NodeStatus { name: self.node_name.clone(), state: db_node.state, - data_count: data_count, + data_count, replicas: statefulset .spec .as_ref() @@ -280,7 +274,7 @@ where let mut node_status = NodeStatus { name: self.node_name.clone(), state: db_node.state, - data_count: data_count, + data_count, replicas: statefulset .spec .as_ref() @@ -373,7 +367,7 @@ where fn new(repo: R, client: Client,topo_sort_nodes: Vec) -> Self { Self { _db_repo: repo, - topo_sort_nodes:topo_sort_nodes, + topo_sort_nodes, _client: client, handlers: Default::default(), } diff --git a/src/job/job_mgr.rs b/src/job/job_mgr.rs index 52f0ed0..d3ca624 100644 --- a/src/job/job_mgr.rs +++ b/src/job/job_mgr.rs @@ -21,17 +21,13 @@ use crate::{ }; use anyhow::Result; use futures::future::try_join_all; -use k8s_openapi::api::node; use kube::Client; use mongodb::bson::oid::ObjectId; use serde::{ Deserialize, Serialize, }; -use std::{ - collections::HashMap, - marker::PhantomData, -}; +use std::marker::PhantomData; use tokio::task::JoinSet; use tokio_util::sync::CancellationToken; use tracing::{ @@ -177,7 +173,7 @@ where let namespace = format!("{}-{}", job.name, job.retry_number - 1); self.db .update( - &id, + id, &JobUpdateInfo { state: Some(JobState::Finish), }, @@ -186,7 +182,7 @@ where self.driver.clean(&namespace).await?; self.db .update( - &id, + id, &JobUpdateInfo { state: Some(JobState::Clean), },