Use database status and health, calculate md5
This commit is contained in:
parent
806f6e7e61
commit
78d818b8d1
7 changed files with 112 additions and 37 deletions
|
@ -141,7 +141,7 @@ func createTask(ctx context.Context, r *http.Request) error {
|
|||
typ := r.FormValue("type")
|
||||
slog.Info("Got Task Create", "library", library, "type", typ)
|
||||
|
||||
rows, err := db.Query(r.Context(), "SELECT id, path, size, missing FROM files where library_id = $1 AND missing = $2", library, false)
|
||||
rows, err := db.Query(r.Context(), "SELECT id, path, size, status, health, md5 FROM files where library_id = $1 AND status = $2", library, constants.FILE_STATUS_EXISTS)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Query Files: %w", err)
|
||||
}
|
||||
|
@ -183,14 +183,15 @@ func createTask(ctx context.Context, r *http.Request) error {
|
|||
}
|
||||
|
||||
type QueuedTask struct {
|
||||
ID int
|
||||
Type int
|
||||
FileID int `json:"file_id"`
|
||||
Data json.RawMessage
|
||||
ID int
|
||||
Type int
|
||||
FileID int `json:"file_id"`
|
||||
FileMD5 []byte `json:"file_md5" db:"md5"`
|
||||
Data json.RawMessage
|
||||
}
|
||||
|
||||
func assignQueuedTasks(ctx context.Context) error {
|
||||
rows, err := db.Query(ctx, "SELECT id, type, file_id, data FROM tasks WHERE status = $1", constants.TASK_STATUS_QUEUED)
|
||||
rows, err := db.Query(ctx, "SELECT t.id as id, t.type as type, t.file_id as file_id, f.md5 as md5, t.data as data FROM tasks t INNER JOIN files f ON f.id = t.file_id WHERE t.status = $1", constants.TASK_STATUS_QUEUED)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Query Queued Tasks: %w", err)
|
||||
}
|
||||
|
@ -238,10 +239,11 @@ func assignQueuedTasks(ctx context.Context) error {
|
|||
}
|
||||
|
||||
taskStart := types.TaskStart{
|
||||
ID: queuedTasks[lastAssigned].ID,
|
||||
Type: queuedTasks[lastAssigned].Type,
|
||||
FileID: queuedTasks[lastAssigned].FileID,
|
||||
Data: queuedTasks[lastAssigned].Data,
|
||||
ID: queuedTasks[lastAssigned].ID,
|
||||
Type: queuedTasks[lastAssigned].Type,
|
||||
FileID: queuedTasks[lastAssigned].FileID,
|
||||
FileMD5: queuedTasks[lastAssigned].FileMD5,
|
||||
Data: queuedTasks[lastAssigned].Data,
|
||||
}
|
||||
|
||||
_, err = rpcServer.Call(ctx, Workers[i].Conn, "task-start", taskStart, nil)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue