@@ -5,7 +5,10 @@ use uuid::Uuid;
55use crate :: {
66 config:: client:: parse_resources,
77 entity:: state:: { TaskExecState , TaskState } ,
8- schema:: { ChangeTaskReq , RemoteResourceDownload , TaskSpec , TasksQueryReq , UpdateTaskLabelsReq } ,
8+ schema:: {
9+ ChangeTaskReq , RemoteResourceDownload , TaskSpec , TasksCancelByFilterReq , TasksQueryReq ,
10+ UpdateTaskLabelsReq ,
11+ } ,
912} ;
1013
1114use super :: { parse_key_val, parse_watch_task, ArtifactsArgs } ;
@@ -26,6 +29,8 @@ pub enum TasksCommands {
2629 Query ( QueryTasksArgs ) ,
2730 /// Cancel a task
2831 Cancel ( CancelTaskArgs ) ,
32+ /// Cancel multiple tasks subject to the filter
33+ CancelMany ( CancelTasksArgs ) ,
2934 /// Replace labels of a task
3035 UpdateLabels ( UpdateTaskLabelsArgs ) ,
3136 /// Update the spec of a task
@@ -117,6 +122,31 @@ pub struct CancelTaskArgs {
117122 pub uuid : Uuid ,
118123}
119124
125+ #[ derive( Serialize , Debug , Deserialize , Args , Clone ) ]
126+ pub struct CancelTasksArgs {
127+ /// The username of the creator who submitted the tasks
128+ #[ arg( short, long, num_args = 0 .., value_delimiter = ',' ) ]
129+ pub creators : Vec < String > ,
130+ /// The name of the group the tasks belong to
131+ #[ arg( short, long) ]
132+ pub group : Option < String > ,
133+ /// The tags of the tasks
134+ #[ arg( short, long, num_args = 0 .., value_delimiter = ',' ) ]
135+ pub tags : Vec < String > ,
136+ /// The labels of the tasks
137+ #[ arg( short, long, num_args = 0 .., value_delimiter = ',' ) ]
138+ pub labels : Vec < String > ,
139+ /// The state of the tasks
140+ #[ arg( short, long, num_args = 0 .., value_delimiter = ',' ) ]
141+ pub state : Vec < TaskState > ,
142+ /// The exit status of the tasks, support operators like `=`(default), `!=`, `<`, `<=`, `>`, `>=`
143+ #[ arg( short, long) ]
144+ pub exit_status : Option < String > ,
145+ /// The priority of the tasks, support operators like `=`(default), `!=`, `<`, `<=`, `>`, `>=`
146+ #[ arg( short, long) ]
147+ pub priority : Option < String > ,
148+ }
149+
120150#[ derive( Serialize , Debug , Deserialize , Args , Clone ) ]
121151pub struct UpdateTaskLabelsArgs {
122152 /// The UUID of the task
@@ -222,3 +252,33 @@ impl From<UpdateTaskLabelsArgs> for UpdateTaskLabelsReq {
222252 }
223253 }
224254}
255+
256+ impl From < CancelTasksArgs > for TasksCancelByFilterReq {
257+ fn from ( args : CancelTasksArgs ) -> Self {
258+ Self {
259+ creator_usernames : if args. creators . is_empty ( ) {
260+ None
261+ } else {
262+ Some ( args. creators . into_iter ( ) . collect ( ) )
263+ } ,
264+ group_name : args. group ,
265+ tags : if args. tags . is_empty ( ) {
266+ None
267+ } else {
268+ Some ( args. tags . into_iter ( ) . collect ( ) )
269+ } ,
270+ labels : if args. labels . is_empty ( ) {
271+ None
272+ } else {
273+ Some ( args. labels . into_iter ( ) . collect ( ) )
274+ } ,
275+ states : if args. state . is_empty ( ) {
276+ None
277+ } else {
278+ Some ( args. state . into_iter ( ) . collect ( ) )
279+ } ,
280+ exit_status : args. exit_status ,
281+ priority : args. priority ,
282+ }
283+ }
284+ }
0 commit comments