Refactor: rename RequeueTasksOfWorker
to RequeueActiveTasksOfWorker
Soon there will be another function to requeue tasks of workers by other criteria, so being clear in the name helps. No functional changes.
This commit is contained in:
parent
fd31a85bcd
commit
b95bed1f96
@ -74,7 +74,7 @@ type TaskStateMachine interface {
|
||||
// JobStatusChange gives a Job a new status, and handles the resulting status changes on its tasks.
|
||||
JobStatusChange(ctx context.Context, job *persistence.Job, newJobStatus api.JobStatus, reason string) error
|
||||
|
||||
RequeueTasksOfWorker(ctx context.Context, worker *persistence.Worker, reason string) error
|
||||
RequeueActiveTasksOfWorker(ctx context.Context, worker *persistence.Worker, reason string) error
|
||||
}
|
||||
|
||||
// TaskStateMachine should be a subset of task_state_machine.StateMachine.
|
||||
|
@ -665,18 +665,18 @@ func (mr *MockTaskStateMachineMockRecorder) JobStatusChange(arg0, arg1, arg2, ar
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "JobStatusChange", reflect.TypeOf((*MockTaskStateMachine)(nil).JobStatusChange), arg0, arg1, arg2, arg3)
|
||||
}
|
||||
|
||||
// RequeueTasksOfWorker mocks base method.
|
||||
func (m *MockTaskStateMachine) RequeueTasksOfWorker(arg0 context.Context, arg1 *persistence.Worker, arg2 string) error {
|
||||
// RequeueActiveTasksOfWorker mocks base method.
|
||||
func (m *MockTaskStateMachine) RequeueActiveTasksOfWorker(arg0 context.Context, arg1 *persistence.Worker, arg2 string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "RequeueTasksOfWorker", arg0, arg1, arg2)
|
||||
ret := m.ctrl.Call(m, "RequeueActiveTasksOfWorker", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// RequeueTasksOfWorker indicates an expected call of RequeueTasksOfWorker.
|
||||
func (mr *MockTaskStateMachineMockRecorder) RequeueTasksOfWorker(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
// RequeueActiveTasksOfWorker indicates an expected call of RequeueActiveTasksOfWorker.
|
||||
func (mr *MockTaskStateMachineMockRecorder) RequeueActiveTasksOfWorker(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RequeueTasksOfWorker", reflect.TypeOf((*MockTaskStateMachine)(nil).RequeueTasksOfWorker), arg0, arg1, arg2)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RequeueActiveTasksOfWorker", reflect.TypeOf((*MockTaskStateMachine)(nil).RequeueActiveTasksOfWorker), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// TaskStatusChange mocks base method.
|
||||
|
@ -177,7 +177,7 @@ func (f *Flamenco) SignOff(e echo.Context) error {
|
||||
_ = f.workerSeen(ctx, logger, w)
|
||||
|
||||
// Re-queue all tasks (should be only one) this worker is now working on.
|
||||
err = f.stateMachine.RequeueTasksOfWorker(ctx, w, "worker signed off")
|
||||
err = f.stateMachine.RequeueActiveTasksOfWorker(ctx, w, "worker signed off")
|
||||
if err != nil {
|
||||
return sendAPIError(e, http.StatusInternalServerError, "error re-queueing your tasks")
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ func TestWorkerSignoffTaskRequeue(t *testing.T) {
|
||||
expectCtx := gomock.Not(gomock.Eq(echo.Request().Context()))
|
||||
|
||||
// Expect worker's tasks to be re-queued.
|
||||
mf.stateMachine.EXPECT().RequeueTasksOfWorker(expectCtx, &worker, "worker signed off").Return(nil)
|
||||
mf.stateMachine.EXPECT().RequeueActiveTasksOfWorker(expectCtx, &worker, "worker signed off").Return(nil)
|
||||
mf.persistence.EXPECT().WorkerSeen(expectCtx, &worker)
|
||||
|
||||
// Expect worker to be saved as 'offline'.
|
||||
@ -251,7 +251,7 @@ func TestWorkerSignoffStatusChangeRequest(t *testing.T) {
|
||||
savedWorker.StatusChangeClear()
|
||||
mf.persistence.EXPECT().SaveWorkerStatus(gomock.Any(), &savedWorker).Return(nil)
|
||||
|
||||
mf.stateMachine.EXPECT().RequeueTasksOfWorker(gomock.Any(), &worker, "worker signed off").Return(nil)
|
||||
mf.stateMachine.EXPECT().RequeueActiveTasksOfWorker(gomock.Any(), &worker, "worker signed off").Return(nil)
|
||||
mf.persistence.EXPECT().WorkerSeen(gomock.Any(), &worker)
|
||||
|
||||
// Perform the request
|
||||
|
@ -11,10 +11,10 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// RequeueTasksOfWorker re-queues all active tasks (should be max one) of this worker.
|
||||
// RequeueActiveTasksOfWorker re-queues all active tasks (should be max one) of this worker.
|
||||
//
|
||||
// `reason`: a string that can be appended to text like "Task requeued because "
|
||||
func (sm *StateMachine) RequeueTasksOfWorker(
|
||||
func (sm *StateMachine) RequeueActiveTasksOfWorker(
|
||||
ctx context.Context,
|
||||
worker *persistence.Worker,
|
||||
reason string,
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRequeueTasksOfWorker(t *testing.T) {
|
||||
func TestRequeueActiveTasksOfWorker(t *testing.T) {
|
||||
mockCtrl, ctx, sm, mocks := taskStateMachineTestFixtures(t)
|
||||
defer mockCtrl.Finish()
|
||||
|
||||
@ -59,6 +59,6 @@ func TestRequeueTasksOfWorker(t *testing.T) {
|
||||
Updated: task2.UpdatedAt,
|
||||
})
|
||||
|
||||
err := sm.RequeueTasksOfWorker(ctx, &worker, "worker had to test")
|
||||
err := sm.RequeueActiveTasksOfWorker(ctx, &worker, "worker had to test")
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ var _ PersistenceService = (*persistence.DB)(nil)
|
||||
type TaskStateMachine interface {
|
||||
// TaskStatusChange gives a Task a new status, and handles the resulting status changes on the job.
|
||||
TaskStatusChange(ctx context.Context, task *persistence.Task, newStatus api.TaskStatus) error
|
||||
RequeueTasksOfWorker(ctx context.Context, worker *persistence.Worker, reason string) error
|
||||
RequeueActiveTasksOfWorker(ctx context.Context, worker *persistence.Worker, reason string) error
|
||||
}
|
||||
|
||||
var _ TaskStateMachine = (*task_state_machine.StateMachine)(nil)
|
||||
|
@ -105,18 +105,18 @@ func (m *MockTaskStateMachine) EXPECT() *MockTaskStateMachineMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// RequeueTasksOfWorker mocks base method.
|
||||
func (m *MockTaskStateMachine) RequeueTasksOfWorker(arg0 context.Context, arg1 *persistence.Worker, arg2 string) error {
|
||||
// RequeueActiveTasksOfWorker mocks base method.
|
||||
func (m *MockTaskStateMachine) RequeueActiveTasksOfWorker(arg0 context.Context, arg1 *persistence.Worker, arg2 string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "RequeueTasksOfWorker", arg0, arg1, arg2)
|
||||
ret := m.ctrl.Call(m, "RequeueActiveTasksOfWorker", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// RequeueTasksOfWorker indicates an expected call of RequeueTasksOfWorker.
|
||||
func (mr *MockTaskStateMachineMockRecorder) RequeueTasksOfWorker(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
// RequeueActiveTasksOfWorker indicates an expected call of RequeueActiveTasksOfWorker.
|
||||
func (mr *MockTaskStateMachineMockRecorder) RequeueActiveTasksOfWorker(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RequeueTasksOfWorker", reflect.TypeOf((*MockTaskStateMachine)(nil).RequeueTasksOfWorker), arg0, arg1, arg2)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RequeueActiveTasksOfWorker", reflect.TypeOf((*MockTaskStateMachine)(nil).RequeueActiveTasksOfWorker), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// TaskStatusChange mocks base method.
|
||||
|
@ -54,7 +54,7 @@ func (ttc *TimeoutChecker) timeoutWorker(ctx context.Context, worker *persistenc
|
||||
logger.Error().Err(err).Msg("TimeoutChecker: error saving timed-out worker to database")
|
||||
}
|
||||
|
||||
err = ttc.taskStateMachine.RequeueTasksOfWorker(ctx, worker, "worker timed out")
|
||||
err = ttc.taskStateMachine.RequeueActiveTasksOfWorker(ctx, worker, "worker timed out")
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("TimeoutChecker: error re-queueing tasks of timed-out worker")
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ func TestWorkerTimeout(t *testing.T) {
|
||||
Return([]*persistence.Worker{&worker}, nil)
|
||||
|
||||
// Expect all tasks assigned to the worker to get requeued.
|
||||
mocks.taskStateMachine.EXPECT().RequeueTasksOfWorker(mocks.ctx, &worker, "worker timed out")
|
||||
mocks.taskStateMachine.EXPECT().RequeueActiveTasksOfWorker(mocks.ctx, &worker, "worker timed out")
|
||||
|
||||
persistedWorker := worker
|
||||
persistedWorker.Status = api.WorkerStatusError
|
||||
|
Loading…
x
Reference in New Issue
Block a user