replace tape library body layout
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -42,9 +43,9 @@ func NewHandler(db *database.DB, log *logger.Logger) *Handler {
|
||||
}
|
||||
}
|
||||
|
||||
// ListDisks lists all physical disks
|
||||
// ListDisks lists all physical disks from database
|
||||
func (h *Handler) ListDisks(c *gin.Context) {
|
||||
disks, err := h.diskService.DiscoverDisks(c.Request.Context())
|
||||
disks, err := h.diskService.ListDisksFromDatabase(c.Request.Context())
|
||||
if err != nil {
|
||||
h.logger.Error("Failed to list disks", "error", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to list disks"})
|
||||
@@ -70,15 +71,19 @@ func (h *Handler) SyncDisks(c *gin.Context) {
|
||||
|
||||
// Run sync in background
|
||||
go func() {
|
||||
ctx := c.Request.Context()
|
||||
// Create new context for background task (don't use request context which may expire)
|
||||
ctx := context.Background()
|
||||
h.taskEngine.StartTask(ctx, taskID)
|
||||
h.taskEngine.UpdateProgress(ctx, taskID, 50, "Discovering disks...")
|
||||
h.logger.Info("Starting disk sync", "task_id", taskID)
|
||||
|
||||
if err := h.diskService.SyncDisksToDatabase(ctx); err != nil {
|
||||
h.logger.Error("Disk sync failed", "task_id", taskID, "error", err)
|
||||
h.taskEngine.FailTask(ctx, taskID, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
h.logger.Info("Disk sync completed", "task_id", taskID)
|
||||
h.taskEngine.UpdateProgress(ctx, taskID, 100, "Disk sync completed")
|
||||
h.taskEngine.CompleteTask(ctx, taskID, "Disks synchronized successfully")
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user