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::config::{Action, Mode};
15 use crate::info::State;
16 use crate::task::reason::Reason;
17
start_task(task_id: u32) -> String18 pub(super) fn start_task(task_id: u32) -> String {
19 format!(
20 "UPDATE request_task SET state = {}, reason = {} where task_id = {} AND (state = {} OR state = {} OR (action = {} AND (state = {} OR state = {} )))",
21 State::Waiting.repr,
22 Reason::RunningTaskMeetLimits.repr,
23 task_id,
24 State::Initialized.repr,
25 State::Paused.repr,
26 Action::Download.repr,
27 State::Failed.repr,
28 State::Stopped.repr,
29 )
30 }
31
pause_task(task_id: u32) -> String32 pub(super) fn pause_task(task_id: u32) -> String {
33 format!(
34 "UPDATE request_task SET state = {}, reason = {} where task_id = {} AND (state = {} OR state = {} OR state = {})",
35 State::Paused.repr,
36 Reason::UserOperation.repr,
37 task_id,
38 State::Running.repr,
39 State::Retrying.repr,
40 State::Waiting.repr,
41 )
42 }
43
stop_task(task_id: u32) -> String44 pub(super) fn stop_task(task_id: u32) -> String {
45 format!(
46 "UPDATE request_task SET state = {}, reason = {} where task_id = {} AND (state = {} OR state = {} OR state = {})",
47 State::Stopped.repr,
48 Reason::UserOperation.repr,
49 task_id,
50 State::Running.repr,
51 State::Retrying.repr,
52 State::Waiting.repr,
53 )
54 }
55
remove_task(task_id: u32) -> String56 pub(super) fn remove_task(task_id: u32) -> String {
57 format!(
58 "UPDATE request_task SET state = {}, reason = {} where task_id = {}",
59 State::Removed.repr,
60 Reason::UserOperation.repr,
61 task_id,
62 )
63 }
64
task_set_mode(task_id: u32, mode: Mode) -> String65 pub(super) fn task_set_mode(task_id: u32, mode: Mode) -> String {
66 format!(
67 "UPDATE request_task SET mode = {} where task_id = {}",
68 mode.repr, task_id,
69 )
70 }
71
72 #[cfg(all(not(feature = "oh"), test))]
73 mod ut_sql {
74 include!("../../../tests/ut/manage/scheduler/ut_sql.rs");
75 }
76