• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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::manage::TaskManager;
15 use crate::task::info::{DumpAllEachInfo, DumpAllInfo, DumpOneInfo};
16 
17 impl TaskManager {
query_one_task(&self, task_id: u32) -> Option<DumpOneInfo>18     pub(crate) fn query_one_task(&self, task_id: u32) -> Option<DumpOneInfo> {
19         self.scheduler
20             .tasks()
21             .find(|task| task.task_id() == task_id)
22             .map(|task| {
23                 let status = task.status.lock().unwrap();
24                 DumpOneInfo {
25                     task_id: task.conf.common_data.task_id,
26                     action: task.conf.common_data.action,
27                     state: status.state,
28                     reason: status.reason,
29                 }
30             })
31     }
32 
query_all_task(&self) -> DumpAllInfo33     pub(crate) fn query_all_task(&self) -> DumpAllInfo {
34         DumpAllInfo {
35             vec: self
36                 .scheduler
37                 .tasks()
38                 .map(|task| {
39                     let status = task.status.lock().unwrap();
40                     DumpAllEachInfo {
41                         task_id: task.conf.common_data.task_id,
42                         action: task.conf.common_data.action,
43                         state: status.state,
44                         reason: status.reason,
45                     }
46                 })
47                 .collect(),
48         }
49     }
50 }
51