@@ -540,34 +540,6 @@ pub async fn user_get_task_suite_by_uuid(
540540 } )
541541}
542542
543- /// Set a suite `Open → Closed`. Idempotency is enforced by the `state = Open` filter.
544- pub ( crate ) async fn close_task_suite < C > (
545- db : & C ,
546- task_suite_id : i64 ,
547- now : TimeDateTimeWithTimeZone ,
548- ) -> Result < ( ) >
549- where
550- C : ConnectionTrait ,
551- {
552- let updated = TaskSuites :: Entity :: update_many ( )
553- . col_expr (
554- TaskSuites :: Column :: State ,
555- Expr :: value ( TaskSuiteState :: Closed ) ,
556- )
557- . col_expr ( TaskSuites :: Column :: UpdatedAt , Expr :: value ( now) )
558- . filter ( TaskSuites :: Column :: Id . eq ( task_suite_id) )
559- . filter ( TaskSuites :: Column :: State . eq ( TaskSuiteState :: Open ) )
560- . exec ( db)
561- . await ?;
562-
563- if updated. rows_affected != 1 {
564- return Err ( Error :: ApiError ( ApiError :: NotFound (
565- "Task suite not found or already closed" . to_string ( ) ,
566- ) ) ) ;
567- }
568- Ok ( ( ) )
569- }
570-
571543/// Close a suite (`Open → Closed`). `Closed` is only an idle marker — the suite
572544/// still accepts and runs tasks, and a new task reopens it. Requires Write/Admin
573545/// in the suite's group.
@@ -600,7 +572,11 @@ pub async fn user_close_task_suite(user_id: i64, pool: &InfraPool, suite_uuid: U
600572 ) ) ) ) ;
601573 }
602574
603- close_task_suite ( txn, suite. id , now) . await
575+ let mut suite: TaskSuites :: ActiveModel = suite. into ( ) ;
576+ suite. state = Set ( TaskSuiteState :: Closed ) ;
577+ suite. updated_at = Set ( now) ;
578+ suite. update ( txn) . await ?;
579+ Ok ( ( ) )
604580 } )
605581 } )
606582 . await ?;
@@ -631,7 +607,7 @@ pub async fn user_cancel_task_suite(
631607 . one ( txn)
632608 . await ?
633609 . ok_or ( Error :: ApiError ( ApiError :: NotFound ( format ! (
634- "Task suite with uuid {suite_uuid}"
610+ "Task suite with uuid {suite_uuid} not found "
635611 ) ) ) ) ?;
636612
637613 UserGroup :: Entity :: find ( )
@@ -718,23 +694,11 @@ pub async fn user_cancel_task_suite(
718694 . await ?;
719695 }
720696
721- let updated = TaskSuites :: Entity :: update_many ( )
722- . col_expr (
723- TaskSuites :: Column :: State ,
724- Expr :: value ( TaskSuiteState :: Cancelled ) ,
725- )
726- . col_expr ( TaskSuites :: Column :: UpdatedAt , Expr :: value ( now) )
727- . col_expr ( TaskSuites :: Column :: CompletedAt , Expr :: value ( now) )
728- . filter ( TaskSuites :: Column :: Id . eq ( suite. id ) )
729- . exec ( txn)
730- . await ?;
731-
732- if updated. rows_affected != 1 {
733- return Err ( Error :: ApiError ( ApiError :: InvalidRequest (
734- "Failed to update task suite state. Maybe due to concurrent state update"
735- . to_string ( ) ,
736- ) ) ) ;
737- }
697+ let mut suite: TaskSuites :: ActiveModel = suite. into ( ) ;
698+ suite. state = Set ( TaskSuiteState :: Cancelled ) ;
699+ suite. updated_at = Set ( now) ;
700+ suite. completed_at = Set ( Some ( now) ) ;
701+ suite. update ( txn) . await ?;
738702
739703 Ok ( cancelled_count)
740704 } )
0 commit comments