
As it was decided that the name "tags" would be better for the clarity of the feature, all files and code named "cluster" or "worker cluster" have been removed and replaced with "tag" and "worker tag". This is only a name change, no other features were touched. This addresses part of #104204. Reviewed-on: https://projects.blender.org/studio/flamenco/pulls/104223 As a note to anyone who already ran a pre-release version of Flamenco and configured some worker clusters, with the help of an SQLite client you can migrate the clusters to tags. First build Flamenco Manager and start it, to create the new database schema. Then run these SQL queries via an sqlite commandline client: ```sql insert into worker_tags (id, created_at, updated_at, uuid, name, description) select id, created_at, updated_at, uuid, name, description from worker_clusters; insert into worker_tag_membership (worker_tag_id, worker_id) select worker_cluster_id, worker_id from worker_cluster_membership; ```
89 lines
2.1 KiB
Go
89 lines
2.1 KiB
Go
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
package persistence
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"git.blender.org/flamenco/pkg/api"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func (db *DB) QueryJobs(ctx context.Context, apiQ api.JobsQuery) ([]*Job, error) {
|
|
logger := log.Ctx(ctx)
|
|
|
|
logger.Debug().Interface("q", apiQ).Msg("querying jobs")
|
|
|
|
q := db.gormDB.WithContext(ctx).Model(&Job{})
|
|
|
|
// WHERE
|
|
if apiQ.StatusIn != nil {
|
|
q = q.Where("status in ?", *apiQ.StatusIn)
|
|
}
|
|
if apiQ.Settings != nil {
|
|
for setting, value := range apiQ.Settings.AdditionalProperties {
|
|
q = q.Where("json_extract(metadata, ?) = ?", "$."+setting, value)
|
|
}
|
|
}
|
|
if apiQ.Metadata != nil {
|
|
for setting, value := range apiQ.Metadata.AdditionalProperties {
|
|
if strings.ContainsRune(value, '%') {
|
|
q = q.Where("json_extract(metadata, ?) like ?", "$."+setting, value)
|
|
} else {
|
|
q = q.Where("json_extract(metadata, ?) = ?", "$."+setting, value)
|
|
}
|
|
}
|
|
}
|
|
|
|
// OFFSET
|
|
if apiQ.Offset != nil {
|
|
q = q.Offset(*apiQ.Offset)
|
|
}
|
|
|
|
// LIMIT
|
|
if apiQ.Limit != nil {
|
|
q = q.Limit(*apiQ.Limit)
|
|
}
|
|
|
|
// ORDER BY
|
|
if apiQ.OrderBy != nil {
|
|
sqlOrder := ""
|
|
for _, order := range *apiQ.OrderBy {
|
|
if order == "" {
|
|
continue
|
|
}
|
|
switch order[0] {
|
|
case '-':
|
|
sqlOrder = order[1:] + " desc"
|
|
case '+':
|
|
sqlOrder = order[1:] + " asc"
|
|
default:
|
|
sqlOrder = order
|
|
}
|
|
q = q.Order(sqlOrder)
|
|
}
|
|
}
|
|
|
|
q.Preload("Tag")
|
|
|
|
result := []*Job{}
|
|
tx := q.Scan(&result)
|
|
return result, tx.Error
|
|
}
|
|
|
|
// QueryJobTaskSummaries retrieves all tasks of the job, but not all fields of those tasks.
|
|
// Fields are synchronised with api.TaskSummary.
|
|
func (db *DB) QueryJobTaskSummaries(ctx context.Context, jobUUID string) ([]*Task, error) {
|
|
logger := log.Ctx(ctx)
|
|
logger.Debug().Str("job", jobUUID).Msg("querying task summaries")
|
|
|
|
var result []*Task
|
|
tx := db.gormDB.WithContext(ctx).Model(&Task{}).
|
|
Select("tasks.id", "tasks.uuid", "tasks.name", "tasks.priority", "tasks.status", "tasks.type", "tasks.updated_at").
|
|
Joins("left join jobs on jobs.id = tasks.job_id").
|
|
Where("jobs.uuid=?", jobUUID).
|
|
Scan(&result)
|
|
|
|
return result, tx.Error
|
|
}
|