Optimize task retention from 5 minutes to 30 seconds to reduce polling overhead since toast notifications are shown only once. Add conditional warehouse pricelist creation via checkbox. Fix category storage in warehouse pricelists to properly load from lot table. Replace SSE with task polling for all long operations. Add comprehensive logging for debugging while minimizing noise from polling endpoints. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package tasks
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// Handler provides HTTP endpoints for task status
|
|
type Handler struct {
|
|
manager *Manager
|
|
}
|
|
|
|
// NewHandler creates a new task handler
|
|
func NewHandler(manager *Manager) *Handler {
|
|
return &Handler{
|
|
manager: manager,
|
|
}
|
|
}
|
|
|
|
// List returns all active and recent tasks
|
|
func (h *Handler) List(c *gin.Context) {
|
|
tasks := h.manager.List()
|
|
// Only log if there are running tasks (not completed/error)
|
|
runningCount := 0
|
|
for _, task := range tasks {
|
|
if task.Status == TaskStatusRunning {
|
|
runningCount++
|
|
}
|
|
}
|
|
|
|
if runningCount > 0 {
|
|
fmt.Printf("[TaskHandler] Returning %d task(s), %d running\n", len(tasks), runningCount)
|
|
for _, task := range tasks {
|
|
if task.Status == TaskStatusRunning {
|
|
fmt.Printf("[TaskHandler] - Task %s: type=%s, status=%s, progress=%d%%, message=%s\n",
|
|
task.ID[:8], task.Type, task.Status, task.Progress, task.Message)
|
|
}
|
|
}
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"tasks": tasks})
|
|
}
|
|
|
|
// Get returns a single task by ID
|
|
func (h *Handler) Get(c *gin.Context) {
|
|
taskID := c.Param("id")
|
|
fmt.Printf("[TaskHandler] Get endpoint called for task %s\n", taskID)
|
|
task, err := h.manager.Get(taskID)
|
|
if err != nil {
|
|
fmt.Printf("[TaskHandler] Task %s not found: %v\n", taskID, err)
|
|
c.JSON(http.StatusNotFound, gin.H{"error": "task not found"})
|
|
return
|
|
}
|
|
fmt.Printf("[TaskHandler] Returning task %s: status=%s, progress=%d%%, message=%s\n",
|
|
taskID[:8], task.Status, task.Progress, task.Message)
|
|
c.JSON(http.StatusOK, task)
|
|
}
|