feat: implement background task system with notifications
- Added background task manager with goroutine execution and panic recovery - Replaced SSE streaming with background task execution for: * Price recalculation (RecalculateAll) * Stock import (ImportStockLog) * Pricelist creation (CreateWithProgress) - Implemented unified polling for task status and DB connection in frontend - Added task indicator in top bar showing running tasks count - Added toast notifications for task completion/error - Tasks automatically cleaned up after 10 minutes - Tasks show progress (0-100%) with descriptive messages - Updated handler constructors to receive task manager - Added API endpoints for task status (/api/tasks, /api/tasks/:id) Fixes issue with SSE disconnection on slow connections during long-running operations
This commit is contained in:
36
internal/tasks/handler.go
Normal file
36
internal/tasks/handler.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"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()
|
||||
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")
|
||||
task, err := h.manager.Get(taskID)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "task not found"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, task)
|
||||
}
|
||||
Reference in New Issue
Block a user