Support pausing jobs #104313
@ -166,7 +166,8 @@ func (sm *StateMachine) jobStatusIfAThenB(
|
||||
return sm.JobStatusChange(ctx, job, thenStatus, reason)
|
||||
}
|
||||
|
||||
func (sm *StateMachine) shouldJobBePaused(ctx context.Context, logger zerolog.Logger, job *persistence.Job) (bool, error) {
|
||||
// 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 {
|
||||
@ -196,7 +197,7 @@ func (sm *StateMachine) updateJobOnTaskStatusCanceled(ctx context.Context, logge
|
||||
}
|
||||
|
||||
// Deal with the special case when the job is in pause-requested status.
|
||||
toBePaused, err := sm.shouldJobBePaused(ctx, logger, job)
|
||||
toBePaused, err := sm.isJobPausingComplete(ctx, logger, job)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -230,7 +231,7 @@ func (sm *StateMachine) updateJobOnTaskStatusFailed(ctx context.Context, logger
|
||||
failLogger.Info().Msg("task failed, but not enough to fail the job")
|
||||
|
||||
// Deal with the special case when the job is in pause-requested status.
|
||||
toBePaused, err := sm.shouldJobBePaused(ctx, logger, job)
|
||||
toBePaused, err := sm.isJobPausingComplete(ctx, logger, job)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -254,7 +255,7 @@ func (sm *StateMachine) updateJobOnTaskStatusCompleted(ctx context.Context, logg
|
||||
}
|
||||
|
||||
// Deal with the special case when the job is in pause-requested status.
|
||||
toBePaused, err := sm.shouldJobBePaused(ctx, logger, job)
|
||||
toBePaused, err := sm.isJobPausingComplete(ctx, logger, job)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -509,7 +510,7 @@ func (sm *StateMachine) pauseTasks(
|
||||
}
|
||||
|
||||
// If pausing was requested, it has now happened, so the job can transition.
|
||||
toBePaused, err := sm.shouldJobBePaused(ctx, logger, job)
|
||||
toBePaused, err := sm.isJobPausingComplete(ctx, logger, job)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error when accessing number of active tasks")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user