Avoid internal error in the UI when reset a schedule (#17946)

fixes #17926

Signed-off-by: stonezdj <daojunz@vmware.com>

Signed-off-by: stonezdj <daojunz@vmware.com>
This commit is contained in:
stonezdj(Daojun Zhang) 2022-12-08 20:43:44 +08:00 committed by GitHub
parent c678d6cc76
commit ceb130e617
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -196,7 +196,13 @@ func (s *scheduler) UnScheduleByID(ctx context.Context, id int64) error {
executionID := executions[0].ID
// stop the execution
if err = s.execMgr.StopAndWait(ctx, executionID, 10*time.Second); err != nil {
return err
if err == task.ErrTimeOut {
// Avoid return this error to the UI, log time out error and continue
// the execution will be finally stopped by jobservice
log.Debugf("time out when stopping the execution %d, but the execution will be stopped eventually", executionID)
} else {
return err
}
}
// delete execution
if err = s.execMgr.Delete(ctx, executionID); err != nil {

View File

@ -17,7 +17,6 @@ package task
import (
"context"
"encoding/json"
"fmt"
"sync"
"time"
@ -34,6 +33,7 @@ var (
// ExecMgr is a global execution manager instance
ExecMgr = NewExecutionManager()
executionSweeperCount = map[string]uint8{}
ErrTimeOut = errors.New("stopping the execution timeout")
)
// ExecutionManager manages executions.
@ -333,7 +333,7 @@ func (e *executionManager) StopAndWait(ctx context.Context, id int64, timeout ti
lock.Lock()
overtime = true
lock.Unlock()
return fmt.Errorf("stopping the execution %d timeout", id)
return ErrTimeOut
case err := <-errChan:
return err
}