Support pausing jobs #104313
@ -168,16 +168,17 @@ func (sm *StateMachine) jobStatusIfAThenB(
|
||||
|
||||
// isJobPausingComplete returns true when the job status is pause-requested and there are no more active tasks.
|
||||
func (sm *StateMachine) isJobPausingComplete(ctx context.Context, logger zerolog.Logger, job *persistence.Job) (bool, error) {
|
||||
if job.Status == api.JobStatusPauseRequested {
|
||||
numActive, _, err := sm.persist.CountTasksOfJobInStatus(ctx, job, api.TaskStatusActive)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if numActive == 0 {
|
||||
// There is no active task, and the job is in pause-requested status, so we can pause the job.
|
||||
logger.Info().Msg("No more active tasks, job is paused")
|
||||
return true, nil
|
||||
}
|
||||
if job.Status != api.JobStatusPauseRequested {
|
||||
return false, nil
|
||||
}
|
||||
numActive, _, err := sm.persist.CountTasksOfJobInStatus(ctx, job, api.TaskStatusActive)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if numActive == 0 {
|
||||
// There is no active task, and the job is in pause-requested status, so we can pause the job.
|
||||
logger.Info().Msg("No more active tasks, job is paused")
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user