Manager: fix query for job tasks
This commit is contained in:
parent
cbc8600d90
commit
629c073ed7
@ -78,8 +78,8 @@ func (db *DB) QueryJobTaskSummaries(ctx context.Context, jobUUID string) ([]*Tas
|
|||||||
var result []*Task
|
var result []*Task
|
||||||
tx := db.gormDB.WithContext(ctx).Model(&Task{}).
|
tx := db.gormDB.WithContext(ctx).Model(&Task{}).
|
||||||
Select("tasks.id", "tasks.uuid", "tasks.name", "tasks.priority", "tasks.status", "tasks.type", "tasks.updated_at").
|
Select("tasks.id", "tasks.uuid", "tasks.name", "tasks.priority", "tasks.status", "tasks.type", "tasks.updated_at").
|
||||||
Joins("left join jobs on jobs.uuid = ?", jobUUID).
|
Joins("left join jobs on jobs.id = tasks.job_id").
|
||||||
// Where("jobs.uuid=?", jobUUID).
|
Where("jobs.uuid=?", jobUUID).
|
||||||
Scan(&result)
|
Scan(&result)
|
||||||
|
|
||||||
return result, tx.Error
|
return result, tx.Error
|
||||||
|
@ -6,6 +6,7 @@ package persistence
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"git.blender.org/flamenco/internal/manager/job_compilers"
|
"git.blender.org/flamenco/internal/manager/job_compilers"
|
||||||
@ -105,7 +106,7 @@ func TestQueryMetadata(t *testing.T) {
|
|||||||
assert.Equal(t, testJob.ID, result[1].ID, "status is %s", result[1].Status)
|
assert.Equal(t, testJob.ID, result[1].ID, "status is %s", result[1].Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFetchJobSummary(t *testing.T) {
|
func TestQueryJobTaskSummaries(t *testing.T) {
|
||||||
ctx, close, db, job, authoredJob := jobTasksTestFixtures(t)
|
ctx, close, db, job, authoredJob := jobTasksTestFixtures(t)
|
||||||
defer close()
|
defer close()
|
||||||
|
|
||||||
@ -117,11 +118,21 @@ func TestFetchJobSummary(t *testing.T) {
|
|||||||
// Create another test job, just to check we get the right tasks back.
|
// Create another test job, just to check we get the right tasks back.
|
||||||
otherAuthoredJob := createTestAuthoredJobWithTasks()
|
otherAuthoredJob := createTestAuthoredJobWithTasks()
|
||||||
otherAuthoredJob.Status = api.JobStatusActive
|
otherAuthoredJob.Status = api.JobStatusActive
|
||||||
otherAuthoredJob.Tasks = []job_compilers.AuthoredTask{}
|
for i := range otherAuthoredJob.Tasks {
|
||||||
|
otherAuthoredJob.Tasks[i].UUID = uuid.NewString()
|
||||||
|
otherAuthoredJob.Tasks[i].Dependencies = []*job_compilers.AuthoredTask{}
|
||||||
|
}
|
||||||
otherAuthoredJob.JobID = "138678c8-efd0-452b-ac05-397ff4c02b26"
|
otherAuthoredJob.JobID = "138678c8-efd0-452b-ac05-397ff4c02b26"
|
||||||
otherAuthoredJob.Metadata["project"] = "Other Project"
|
otherAuthoredJob.Metadata["project"] = "Other Project"
|
||||||
persistAuthoredJob(t, ctx, db, otherAuthoredJob)
|
persistAuthoredJob(t, ctx, db, otherAuthoredJob)
|
||||||
|
|
||||||
|
// Sanity check for the above code, there should be 6 tasks overall, 3 per job.
|
||||||
|
var numTasks int64
|
||||||
|
tx := db.gormDB.Model(&Task{}).Count(&numTasks)
|
||||||
|
assert.NoError(t, tx.Error)
|
||||||
|
assert.Equal(t, int64(6), numTasks)
|
||||||
|
|
||||||
|
// Get the task summaries of a particular job.
|
||||||
summaries, err := db.QueryJobTaskSummaries(ctx, job.UUID)
|
summaries, err := db.QueryJobTaskSummaries(ctx, job.UUID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user