feat: optimize background tasks and fix warehouse pricelist workflow
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>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -21,16 +22,37 @@ func NewHandler(manager *Manager) *Handler {
|
||||
// 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user