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:
34
internal/tasks/task.go
Normal file
34
internal/tasks/task.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package tasks
|
||||
|
||||
import "time"
|
||||
|
||||
// TaskStatus represents the current status of a task
|
||||
type TaskStatus string
|
||||
|
||||
const (
|
||||
TaskStatusRunning TaskStatus = "running"
|
||||
TaskStatusCompleted TaskStatus = "completed"
|
||||
TaskStatusError TaskStatus = "error"
|
||||
)
|
||||
|
||||
// TaskType represents the type of background task
|
||||
type TaskType string
|
||||
|
||||
const (
|
||||
TaskTypeRecalculate TaskType = "recalculate"
|
||||
TaskTypeStockImport TaskType = "stock_import"
|
||||
TaskTypePricelistCreate TaskType = "pricelist_create"
|
||||
)
|
||||
|
||||
// Task represents a background task with progress tracking
|
||||
type Task struct {
|
||||
ID string `json:"id"`
|
||||
Type TaskType `json:"type"`
|
||||
Status TaskStatus `json:"status"`
|
||||
Progress int `json:"progress"` // 0-100
|
||||
Message string `json:"message"`
|
||||
Result map[string]interface{} `json:"result,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
DoneAt *time.Time `json:"done_at,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user