1 // Copyright (C) 2023 Huawei Device Co., Ltd. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 use crate::error::ErrorCode; 15 use crate::info::State; 16 use crate::manage::database::RequestDb; 17 use crate::manage::TaskManager; 18 19 impl TaskManager { stop(&mut self, uid: u64, task_id: u32) -> ErrorCode20 pub(crate) fn stop(&mut self, uid: u64, task_id: u32) -> ErrorCode { 21 debug!("TaskManager stop, tid{}", task_id); 22 let db = RequestDb::get_instance(); 23 if let Some(info) = db.get_task_qos_info(task_id) { 24 if info.state == State::Running.repr 25 || info.state == State::Retrying.repr 26 || info.state == State::Waiting.repr 27 { 28 if let Some(count) = self.task_count.get_mut(&uid) { 29 let count = match info.mode { 30 1 => &mut count.0, 31 _ => &mut count.1, 32 }; 33 if *count > 0 { 34 *count -= 1; 35 } 36 } 37 } 38 } 39 40 match self.scheduler.stop_task(uid, task_id) { 41 Ok(_) => ErrorCode::ErrOk, 42 Err(e) => e, 43 } 44 } 45 } 46