Jonas Holzman f0fca60427 Tasks Table: Add Worker column (#104402)
Add a `Worker` column to the Job Tasks Table. This lets artists quickly
visualize on which machine a task is currently running, giving better
insights on worker utilization, as well as better expectations on how
long a task might take to finish when running Flamenco on a Renderfarm
made of different slow / fast workers.

Similarly to the Task Details panel for the "Assigned To"  field
`LinkWorker` Vue element, the cell element contains an hyperlink to the
corresponding worker in the Workers page. Since the Worker page also
contains a backlink to the currently running task, this lets user
quickly navigate between the two pages, as seen in the screen recording
demo below.

Reviewed-on: https://projects.blender.org/studio/flamenco/pulls/104402
Reviewed-by: Sybren A. Stüvel <sybren@blender.org>
2025-06-30 14:37:00 +02:00

65 lines
1.8 KiB
Go

// SPDX-License-Identifier: GPL-3.0-or-later
package persistence
import (
"context"
"github.com/rs/zerolog/log"
"projects.blender.org/studio/flamenco/internal/manager/persistence/sqlc"
"projects.blender.org/studio/flamenco/pkg/api"
)
type TaskSummary = sqlc.QueryJobTaskSummariesRow
// 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) ([]TaskSummary, error) {
logger := log.Ctx(ctx)
logger.Debug().Str("job", jobUUID).Msg("querying task summaries")
queries := db.queries()
summaries, err := queries.QueryJobTaskSummaries(ctx, jobUUID)
if err != nil {
return nil, err
}
result := make([]TaskSummary, len(summaries))
for index, task := range summaries {
result[index] = TaskSummary{
ID: task.ID,
UpdatedAt: task.UpdatedAt,
UUID: task.UUID,
Name: task.Name,
Type: task.Type,
IndexInJob: task.IndexInJob,
Priority: task.Priority,
Status: task.Status,
WorkerUUID: task.WorkerUUID,
}
}
return result, nil
}
// JobStatusCount is a mapping from job status to the number of jobs in that status.
type JobStatusCount map[api.JobStatus]int
func (db *DB) SummarizeJobStatuses(ctx context.Context) (JobStatusCount, error) {
logger := log.Ctx(ctx)
logger.Debug().Msg("database: summarizing job statuses")
queries := db.queries()
result, err := queries.SummarizeJobStatuses(ctx)
if err != nil {
return nil, jobError(err, "summarizing job statuses")
}
// Convert the array-of-structs to a map that's easier to handle by the caller.
statusCounts := make(JobStatusCount)
for _, singleStatusCount := range result {
statusCounts[api.JobStatus(singleStatusCount.Status)] = int(singleStatusCount.StatusCount)
}
return statusCounts, nil
}