Cleanup: Manager, clarify some function names of the task state machine

Rename functions `onTaskStatusX` to `updateJobOnTaskStatusX` to clarify
their responsibility is to update the job in reaction to a task status
change.

No functional changes.
This commit is contained in:
Sybren A. Stüvel 2022-06-17 11:01:41 +02:00
parent 8764f8f7c1
commit b991e5f446

View File

@ -113,10 +113,10 @@ func (sm *StateMachine) updateJobAfterTaskStatusChange(
return nil return nil
case api.TaskStatusCanceled: case api.TaskStatusCanceled:
return sm.onTaskStatusCanceled(ctx, logger, job) return sm.updateJobOnTaskStatusCanceled(ctx, logger, job)
case api.TaskStatusFailed: case api.TaskStatusFailed:
return sm.onTaskStatusFailed(ctx, logger, job) return sm.updateJobOnTaskStatusFailed(ctx, logger, job)
case api.TaskStatusActive, api.TaskStatusSoftFailed: case api.TaskStatusActive, api.TaskStatusSoftFailed:
switch job.Status { switch job.Status {
@ -130,7 +130,7 @@ func (sm *StateMachine) updateJobAfterTaskStatusChange(
} }
case api.TaskStatusCompleted: case api.TaskStatusCompleted:
return sm.onTaskStatusCompleted(ctx, logger, job) return sm.updateJobOnTaskStatusCompleted(ctx, logger, job)
default: default:
logger.Warn().Msg("task obtained status that Flamenco did not expect") logger.Warn().Msg("task obtained status that Flamenco did not expect")
@ -156,8 +156,8 @@ func (sm *StateMachine) jobStatusIfAThenB(
return sm.JobStatusChange(ctx, job, thenStatus, reason) return sm.JobStatusChange(ctx, job, thenStatus, reason)
} }
// onTaskStatusCanceled conditionally escalates the cancellation of a task to cancel the job. // updateJobOnTaskStatusCanceled conditionally escalates the cancellation of a task to cancel the job.
func (sm *StateMachine) onTaskStatusCanceled(ctx context.Context, logger zerolog.Logger, job *persistence.Job) error { func (sm *StateMachine) updateJobOnTaskStatusCanceled(ctx context.Context, logger zerolog.Logger, job *persistence.Job) error {
// If no more tasks can run, cancel the job. // If no more tasks can run, cancel the job.
numRunnable, _, err := sm.persist.CountTasksOfJobInStatus(ctx, job, numRunnable, _, err := sm.persist.CountTasksOfJobInStatus(ctx, job,
api.TaskStatusActive, api.TaskStatusQueued, api.TaskStatusSoftFailed) api.TaskStatusActive, api.TaskStatusQueued, api.TaskStatusSoftFailed)
@ -173,8 +173,8 @@ func (sm *StateMachine) onTaskStatusCanceled(ctx context.Context, logger zerolog
return nil return nil
} }
// onTaskStatusFailed conditionally escalates the failure of a task to fail the entire job. // updateJobOnTaskStatusFailed conditionally escalates the failure of a task to fail the entire job.
func (sm *StateMachine) onTaskStatusFailed(ctx context.Context, logger zerolog.Logger, job *persistence.Job) error { func (sm *StateMachine) updateJobOnTaskStatusFailed(ctx context.Context, logger zerolog.Logger, job *persistence.Job) error {
// Count the number of failed tasks. If it is over the threshold, fail the job. // Count the number of failed tasks. If it is over the threshold, fail the job.
numFailed, numTotal, err := sm.persist.CountTasksOfJobInStatus(ctx, job, api.TaskStatusFailed) numFailed, numTotal, err := sm.persist.CountTasksOfJobInStatus(ctx, job, api.TaskStatusFailed)
if err != nil { if err != nil {
@ -198,8 +198,8 @@ func (sm *StateMachine) onTaskStatusFailed(ctx context.Context, logger zerolog.L
"task failed, but not enough to fail the job") "task failed, but not enough to fail the job")
} }
// onTaskStatusCompleted conditionally escalates the completion of a task to complete the entire job. // updateJobOnTaskStatusCompleted conditionally escalates the completion of a task to complete the entire job.
func (sm *StateMachine) onTaskStatusCompleted(ctx context.Context, logger zerolog.Logger, job *persistence.Job) error { func (sm *StateMachine) updateJobOnTaskStatusCompleted(ctx context.Context, logger zerolog.Logger, job *persistence.Job) error {
numComplete, numTotal, err := sm.persist.CountTasksOfJobInStatus(ctx, job, api.TaskStatusCompleted) numComplete, numTotal, err := sm.persist.CountTasksOfJobInStatus(ctx, job, api.TaskStatusCompleted)
if err != nil { if err != nil {
return err return err