[MM-56074] mmctl job commands (#26855)
* add job list and update job status command to mmctl
Этот коммит содержится в:
@@ -24,6 +24,7 @@ func TestJobStore(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
t.Run("JobGetAllByTypeAndStatus", func(t *testing.T) { testJobGetAllByTypeAndStatus(t, rctx, ss) })
|
||||
t.Run("JobGetAllByTypePage", func(t *testing.T) { testJobGetAllByTypePage(t, rctx, ss) })
|
||||
t.Run("JobGetAllByTypesPage", func(t *testing.T) { testJobGetAllByTypesPage(t, rctx, ss) })
|
||||
t.Run("JobGetAllByTypeAndStatusPage", func(t *testing.T) { testJobGetAllByTypeAndStatusPage(t, rctx, ss) })
|
||||
t.Run("JobGetAllByStatus", func(t *testing.T) { testJobGetAllByStatus(t, rctx, ss) })
|
||||
t.Run("GetNewestJobByStatusAndType", func(t *testing.T) { testJobStoreGetNewestJobByStatusAndType(t, rctx, ss) })
|
||||
t.Run("GetNewestJobByStatusesAndType", func(t *testing.T) { testJobStoreGetNewestJobByStatusesAndType(t, rctx, ss) })
|
||||
@@ -259,6 +260,62 @@ func testJobGetAllByTypesPage(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
require.Equal(t, received[0].Id, jobs[1].Id, "should've received oldest job last")
|
||||
}
|
||||
|
||||
func testJobGetAllByTypeAndStatusPage(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
jobType := model.NewId()
|
||||
jobType2 := model.NewId()
|
||||
t0 := model.GetMillis()
|
||||
|
||||
jobs := []*model.Job{
|
||||
{
|
||||
Id: model.NewId(),
|
||||
Type: jobType,
|
||||
Status: model.JobStatusPending,
|
||||
CreateAt: t0,
|
||||
},
|
||||
{
|
||||
Id: model.NewId(),
|
||||
Type: jobType,
|
||||
Status: model.JobStatusPending,
|
||||
CreateAt: t0 + 1,
|
||||
},
|
||||
{
|
||||
Id: model.NewId(),
|
||||
Type: jobType2,
|
||||
Status: model.JobStatusCanceled,
|
||||
CreateAt: t0 + 2,
|
||||
},
|
||||
{
|
||||
Id: model.NewId(),
|
||||
Type: jobType2,
|
||||
Status: model.JobStatusCanceled,
|
||||
CreateAt: t0 + 3,
|
||||
},
|
||||
}
|
||||
|
||||
for _, job := range jobs {
|
||||
_, err := ss.Job().Save(job)
|
||||
require.NoError(t, err)
|
||||
defer ss.Job().Delete(job.Id)
|
||||
}
|
||||
|
||||
jobTypes := []string{jobType, jobType2}
|
||||
received, err := ss.Job().GetAllByTypeAndStatusPage(rctx, jobTypes, model.JobStatusPending, 0, 4)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, received, 2)
|
||||
require.Equal(t, received[0].Id, jobs[1].Id, "should've received newest job first")
|
||||
require.Equal(t, received[1].Id, jobs[0].Id, "should've received oldest job last")
|
||||
|
||||
received, err = ss.Job().GetAllByTypeAndStatusPage(rctx, jobTypes, model.JobStatusPending, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, received, 1)
|
||||
require.Equal(t, received[0].Id, jobs[0].Id, "should've received the oldest pending job")
|
||||
|
||||
received, err = ss.Job().GetAllByTypeAndStatusPage(rctx, []string{jobType2}, model.JobStatusCanceled, 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, received, 1)
|
||||
require.Equal(t, received[0].Id, jobs[2].Id, "should've received the oldest canceled job")
|
||||
}
|
||||
|
||||
func testJobGetAllByStatus(t *testing.T, rctx request.CTX, ss store.Store) {
|
||||
jobType := model.NewId()
|
||||
status := model.NewId()
|
||||
|
||||
@@ -181,6 +181,36 @@ func (_m *JobStore) GetAllByTypeAndStatus(c request.CTX, jobType string, status
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetAllByTypeAndStatusPage provides a mock function with given fields: c, jobType, status, offset, limit
|
||||
func (_m *JobStore) GetAllByTypeAndStatusPage(c request.CTX, jobType []string, status string, offset int, limit int) ([]*model.Job, error) {
|
||||
ret := _m.Called(c, jobType, status, offset, limit)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for GetAllByTypeAndStatusPage")
|
||||
}
|
||||
|
||||
var r0 []*model.Job
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, []string, string, int, int) ([]*model.Job, error)); ok {
|
||||
return rf(c, jobType, status, offset, limit)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, []string, string, int, int) []*model.Job); ok {
|
||||
r0 = rf(c, jobType, status, offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.Job)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(request.CTX, []string, string, int, int) error); ok {
|
||||
r1 = rf(c, jobType, status, offset, limit)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetAllByTypePage provides a mock function with given fields: c, jobType, offset, limit
|
||||
func (_m *JobStore) GetAllByTypePage(c request.CTX, jobType string, offset int, limit int) ([]*model.Job, error) {
|
||||
ret := _m.Called(c, jobType, offset, limit)
|
||||
|
||||
Ссылка в новой задаче
Block a user