dbjobqueue: Add AllRootJobIDs implementation

Related: RHEL-60120
This commit is contained in:
Brian C. Lane 2024-05-30 16:44:14 -07:00 committed by Tomáš Hozza
parent d8285a0b74
commit 5cddc4223d
6 changed files with 64 additions and 14 deletions

View file

@ -307,7 +307,7 @@ func (h *apiHandlers) targetResultToUploadStatus(jobId uuid.UUID, t *target.Targ
// GetComposeList returns a list of the root job UUIDs
func (h *apiHandlers) GetComposeList(ctx echo.Context) error {
jobs, err := h.server.workers.AllRootJobIDs()
jobs, err := h.server.workers.AllRootJobIDs(ctx.Request().Context())
if err != nil {
return HTTPErrorWithInternal(ErrorGettingComposeList, err)
}

View file

@ -705,7 +705,7 @@ func jobMatchesCriteria(j *job, acceptedJobTypes []string, acceptedChannels []st
// AllRootJobIDs Return a list of all the top level(root) job uuids
// This only includes jobs without any Dependents set
func (q *fsJobQueue) AllRootJobIDs() ([]uuid.UUID, error) {
func (q *fsJobQueue) AllRootJobIDs(_ context.Context) ([]uuid.UUID, error) {
ids, err := q.db.List()
if err != nil {
return nil, err

View file

@ -1,6 +1,7 @@
package fsjobqueue_test
import (
"context"
"os"
"path"
"sort"
@ -82,7 +83,7 @@ func TestAllRootJobIDs(t *testing.T) {
rootJobs = append(rootJobs, jidRoot3)
sortUUIDs(rootJobs)
roots, err := q.AllRootJobIDs()
roots, err := q.AllRootJobIDs(context.TODO())
require.Nil(t, err)
require.Greater(t, len(roots), 0)
sortUUIDs(roots)
@ -101,7 +102,7 @@ func TestDeleteJob(t *testing.T) {
err = q.DeleteJob(context.TODO(), jidRoot1)
require.Nil(t, err)
jobs, err := q.AllRootJobIDs()
jobs, err := q.AllRootJobIDs(context.TODO())
require.Nil(t, err)
require.Equal(t, 0, len(jobs))
@ -122,7 +123,7 @@ func TestDeleteJob(t *testing.T) {
// This should only remove jidRoot2 and jid2, leaving jidRoot3, jid1, jid3
err = q.DeleteJob(context.TODO(), jidRoot2)
require.Nil(t, err)
jobs, err = q.AllRootJobIDs()
jobs, err = q.AllRootJobIDs(context.TODO())
require.Nil(t, err)
require.Equal(t, 1, len(jobs))
assert.Equal(t, []uuid.UUID{jidRoot3}, jobs)
@ -130,7 +131,7 @@ func TestDeleteJob(t *testing.T) {
// This should remove the rest
err = q.DeleteJob(context.TODO(), jidRoot3)
require.Nil(t, err)
jobs, err = q.AllRootJobIDs()
jobs, err = q.AllRootJobIDs(context.TODO())
require.Nil(t, err)
require.Equal(t, 0, len(jobs))
@ -156,7 +157,7 @@ func TestDeleteJob(t *testing.T) {
// Delete the koji job
err = q.DeleteJob(context.TODO(), kojiRoot)
require.Nil(t, err)
jobs, err = q.AllRootJobIDs()
jobs, err = q.AllRootJobIDs(context.TODO())
require.Nil(t, err)
require.Equal(t, 0, len(jobs))

View file

@ -349,8 +349,8 @@ func (s *Server) JobDependencyChainErrors(id uuid.UUID) (*clienterrors.Error, er
}
// AllRootJobIDs returns a list of top level job UUIDs that the worker knows about
func (s *Server) AllRootJobIDs() ([]uuid.UUID, error) {
return s.jobs.AllRootJobIDs()
func (s *Server) AllRootJobIDs(ctx context.Context) ([]uuid.UUID, error) {
return s.jobs.AllRootJobIDs(ctx)
}
func (s *Server) OSBuildJobInfo(id uuid.UUID, result *OSBuildJobResult) (*JobInfo, error) {