yao/job/progress.go
Max 4dd1424080 Enhance job management functionality and improve execution handling
- Implemented comprehensive job management features, including pagination for job listing, active job retrieval, and job counting.
- Enhanced job saving logic to support both creation and updates, ensuring proper handling of job metadata.
- Introduced category management with automatic creation and retrieval of categories during job operations.
- Added execution management capabilities, including progress tracking and logging for job executions.
- Improved error handling and validation across job and execution methods, ensuring robustness in job processing.
- Updated documentation to reflect new features and usage examples for job management and execution tracking.
2025-08-31 15:38:32 +08:00

51 lines
1,018 B
Go

package job
import (
"sync"
"github.com/yaoapp/gou/model"
)
// Progress the progress manager struct
type Progress struct {
ExecutionID string `json:"execution_id"`
Progress int `json:"progress"`
Message string `json:"message"`
mu sync.RWMutex
}
// Progress Progress manager
func (j *Job) Progress() ProgressManager {
return &Progress{
ExecutionID: "", // Will be set when execution starts
Progress: 0,
Message: "",
}
}
// Set set the progress
func (p *Progress) Set(progress int, message string) error {
p.mu.Lock()
defer p.mu.Unlock()
p.Progress = progress
p.Message = message
// Update execution in database if execution ID is set
if p.ExecutionID != "" {
execution, err := GetExecution(p.ExecutionID, model.QueryParam{})
if err == nil {
execution.Progress = progress
SaveExecution(execution)
}
}
return nil
}
// Get get current progress
func (p *Progress) Get() (int, string) {
p.mu.RLock()
defer p.mu.RUnlock()
return p.Progress, p.Message
}