Improve Task Display
This commit is contained in:
parent
1a46eaf51b
commit
1a181980a3
4 changed files with 49 additions and 18 deletions
|
@ -25,11 +25,24 @@ const SORT_ORDER_ASC_PARAM = "order_asc"
|
||||||
const QUERY_LIMIT_PARAM = "limit"
|
const QUERY_LIMIT_PARAM = "limit"
|
||||||
const QUERY_PAGE_PARAM = "page"
|
const QUERY_PAGE_PARAM = "page"
|
||||||
|
|
||||||
|
type TaskType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TASK_TYPE_HEALTHCHECK = iota
|
TASK_TYPE_HEALTHCHECK TaskType = iota
|
||||||
TASK_TYPE_TRANSCODE
|
TASK_TYPE_TRANSCODE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (s TaskType) String() string {
|
||||||
|
switch s {
|
||||||
|
case TASK_TYPE_HEALTHCHECK:
|
||||||
|
return "Healthcheck"
|
||||||
|
case TASK_TYPE_TRANSCODE:
|
||||||
|
return "Transcode"
|
||||||
|
default:
|
||||||
|
return fmt.Sprintf("%d", int(s))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type TaskStatus int
|
type TaskStatus int
|
||||||
|
|
||||||
// Non Append Changes Need Worker Version Bump
|
// Non Append Changes Need Worker Version Bump
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
type TasksData struct {
|
type TasksData struct {
|
||||||
Libraries []Library
|
Libraries []Library
|
||||||
FfmpegCommands []FfmpegCommand
|
FfmpegCommands []FfmpegCommand
|
||||||
Tasks []TaskDisplay
|
Tasks []TasksDisplay
|
||||||
Stats TaskStats
|
Stats TaskStats
|
||||||
OrderBy string
|
OrderBy string
|
||||||
OrderAsc bool
|
OrderAsc bool
|
||||||
|
@ -40,7 +40,7 @@ type TaskStats struct {
|
||||||
TotalCount int
|
TotalCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
type TaskDisplay struct {
|
type TasksDisplay struct {
|
||||||
ID int `db:"id"`
|
ID int `db:"id"`
|
||||||
Library int `db:"library"`
|
Library int `db:"library"`
|
||||||
Worker *string `db:"worker"`
|
Worker *string `db:"worker"`
|
||||||
|
@ -51,6 +51,17 @@ type TaskDisplay struct {
|
||||||
UpdatedAt string `db:"updated_at"`
|
UpdatedAt string `db:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TaskDisplay struct {
|
||||||
|
ID int
|
||||||
|
Library string
|
||||||
|
Worker string
|
||||||
|
Type string
|
||||||
|
Status string
|
||||||
|
Filename string
|
||||||
|
Log []string
|
||||||
|
UpdatedAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
type TaskDB struct {
|
type TaskDB struct {
|
||||||
ID int `db:"id"`
|
ID int `db:"id"`
|
||||||
Library int `db:"library"`
|
Library int `db:"library"`
|
||||||
|
@ -167,7 +178,7 @@ func handleTasks(w http.ResponseWriter, r *http.Request) {
|
||||||
data.Page = uint(page)
|
data.Page = uint(page)
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err = db.Query(r.Context(), "SELECT t.id AS id, l.id AS library, t.worker_id AS worker, t.type AS type, fc.name AS ffmpeg_command, t.status AS status, f.path AS file, t.updated_at AS updated_at FROM tasks t INNER JOIN files f ON f.id = t.file_id INNER JOIN libraries l ON l.id = f.library_id INNER JOIN ffmpeg_commands fc ON fc.id = t.ffmpeg_command_id "+fmt.Sprintf("ORDER BY %v %v LIMIT %d OFFSET %d", data.OrderBy, orderDir, data.Limit, data.Page*data.Limit))
|
rows, err = db.Query(r.Context(), "SELECT t.id AS id, l.id AS library, w.name AS worker, t.type AS type, fc.name AS ffmpeg_command, t.status AS status, f.path AS file, t.updated_at AS updated_at FROM tasks t INNER JOIN files f ON f.id = t.file_id INNER JOIN libraries l ON l.id = f.library_id INNER JOIN ffmpeg_commands fc ON fc.id = t.ffmpeg_command_id INNER JOIN workers w ON t.worker_id = w.id "+fmt.Sprintf("ORDER BY %v %v LIMIT %d OFFSET %d", data.OrderBy, orderDir, data.Limit, data.Page*data.Limit))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.ErrorContext(r.Context(), "Query Tasks", "err", err)
|
slog.ErrorContext(r.Context(), "Query Tasks", "err", err)
|
||||||
http.Error(w, "Error Query Tasks: "+err.Error(), http.StatusInternalServerError)
|
http.Error(w, "Error Query Tasks: "+err.Error(), http.StatusInternalServerError)
|
||||||
|
@ -180,7 +191,7 @@ func handleTasks(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for i := range tasks {
|
for i := range tasks {
|
||||||
data.Tasks = append(data.Tasks, TaskDisplay{
|
data.Tasks = append(data.Tasks, TasksDisplay{
|
||||||
ID: tasks[i].ID,
|
ID: tasks[i].ID,
|
||||||
Library: tasks[i].Library,
|
Library: tasks[i].Library,
|
||||||
Worker: tasks[i].Worker,
|
Worker: tasks[i].Worker,
|
||||||
|
@ -214,18 +225,18 @@ func handleTask(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var log []string
|
var typ constants.TaskType
|
||||||
err := db.QueryRow(r.Context(), "SELECT log FROM tasks WHERE id = $1", id).Scan(&log)
|
var status constants.TaskStatus
|
||||||
|
t := TaskDisplay{}
|
||||||
|
err := db.QueryRow(r.Context(), "SELECT t.id, l.name, w.name, t.type, t.status, f.path, t.log, t.updated_at FROM tasks t INNER JOIN workers w ON w.id = t.worker_id INNER JOIN files f ON f.id = t.file_id INNER JOIN libraries l ON l.id = f.library_id WHERE t.id = $1", id).Scan(&t.ID, &t.Library, &t.Worker, &typ, &status, &t.Filename, &t.Log, &t.UpdatedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.ErrorContext(r.Context(), "Query Tasks", "err", err)
|
slog.ErrorContext(r.Context(), "Query Tasks", "err", err)
|
||||||
http.Error(w, "Error Query Tasks: "+err.Error(), http.StatusInternalServerError)
|
http.Error(w, "Error Query Tasks: "+err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
t := types.Task{
|
t.Type = typ.String()
|
||||||
Log: log,
|
t.Status = status.String()
|
||||||
}
|
|
||||||
|
|
||||||
buf := bytes.Buffer{}
|
buf := bytes.Buffer{}
|
||||||
err = templates.ExecuteTemplate(&buf, constants.TASK_TEMPLATE_NAME, t)
|
err = templates.ExecuteTemplate(&buf, constants.TASK_TEMPLATE_NAME, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -311,7 +322,7 @@ func createTask(ctx context.Context, r *http.Request) error {
|
||||||
|
|
||||||
type QueuedTask struct {
|
type QueuedTask struct {
|
||||||
ID int
|
ID int
|
||||||
Type int
|
Type constants.TaskType
|
||||||
FileID int `json:"file_id"`
|
FileID int `json:"file_id"`
|
||||||
FileMD5 []byte `json:"file_md5" db:"md5"`
|
FileMD5 []byte `json:"file_md5" db:"md5"`
|
||||||
Data json.RawMessage
|
Data json.RawMessage
|
||||||
|
|
|
@ -24,7 +24,14 @@ window.onload = function(e){
|
||||||
checkReloading();
|
checkReloading();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<h2>Task {{.ID}}</h2>
|
<h2>Task: {{.ID}}</h2>
|
||||||
|
<p>Type: {{.Type}}</p>
|
||||||
|
<p>Status: {{.Status}}</p>
|
||||||
|
<p>Worker: {{.Worker}}</p>
|
||||||
|
<p>Library: {{.Library}}</p>
|
||||||
|
<p>Filename: {{.Filename}}</p>
|
||||||
|
<p>Updated At: {{.UpdatedAt}}</p>
|
||||||
|
<button type="button" onclick="window.scrollTo(0,document.body.scrollHeight);">Scroll to Bottom</button>
|
||||||
<div class="log">
|
<div class="log">
|
||||||
{{range $t := .Log}}
|
{{range $t := .Log}}
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -7,10 +7,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type TaskStart struct {
|
type TaskStart struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
FileID int `json:"file_id"`
|
FileID int `json:"file_id"`
|
||||||
FileMD5 []byte `json:"file_md5"`
|
FileMD5 []byte `json:"file_md5"`
|
||||||
Type int `json:"type"`
|
Type constants.TaskType `json:"type"`
|
||||||
Data json.RawMessage
|
Data json.RawMessage
|
||||||
FfmpegCommand FFmpegCommand `json:"ffmpeg_command"`
|
FfmpegCommand FFmpegCommand `json:"ffmpeg_command"`
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ type Task struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
FileID int `json:"file_id"`
|
FileID int `json:"file_id"`
|
||||||
FileMD5 []byte `json:"md5"`
|
FileMD5 []byte `json:"md5"`
|
||||||
Type int `json:"type"`
|
Type constants.TaskType `json:"type"`
|
||||||
Status constants.TaskStatus `json:"status"`
|
Status constants.TaskStatus `json:"status"`
|
||||||
FfmpegCommand FFmpegCommand `json:"ffmpeg_command"`
|
FfmpegCommand FFmpegCommand `json:"ffmpeg_command"`
|
||||||
Log []string `json:"log"`
|
Log []string `json:"log"`
|
||||||
|
|
Loading…
Add table
Reference in a new issue