Store unfinished tasks on disks
This commit is contained in:
@@ -17,11 +17,21 @@ const (
|
||||
StatusCanceled Status = "canceled"
|
||||
)
|
||||
|
||||
const (
|
||||
PhaseQueued = "queued"
|
||||
PhasePreparing = "preparing"
|
||||
PhaseReplacing = "replacing"
|
||||
PhaseLoadingHistory = "loading_history"
|
||||
PhaseScanning = "scanning"
|
||||
PhaseCopying = "copying"
|
||||
)
|
||||
|
||||
type Task struct {
|
||||
ID string `json:"id"`
|
||||
DiskID string `json:"disk_id"`
|
||||
Type string `json:"type"`
|
||||
Status Status `json:"status"`
|
||||
Phase string `json:"phase,omitempty"`
|
||||
Progress int `json:"progress"`
|
||||
Message string `json:"message"`
|
||||
SpeedBPS int64 `json:"speed_bps"`
|
||||
@@ -45,13 +55,15 @@ func NewStore() *Store {
|
||||
}
|
||||
|
||||
func (s *Store) Create(taskType, diskID string) *Task {
|
||||
now := time.Now().UTC()
|
||||
t := &Task{
|
||||
ID: uuid.New().String(),
|
||||
DiskID: diskID,
|
||||
Type: taskType,
|
||||
Status: StatusQueued,
|
||||
CreatedAt: time.Now().UTC(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
Phase: PhaseQueued,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
s.mu.Lock()
|
||||
s.tasks[t.ID] = t
|
||||
@@ -59,6 +71,13 @@ func (s *Store) Create(taskType, diskID string) *Task {
|
||||
return t
|
||||
}
|
||||
|
||||
func (s *Store) Upsert(t Task) {
|
||||
copy := t
|
||||
s.mu.Lock()
|
||||
s.tasks[t.ID] = ©
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
func (s *Store) Get(id string) (*Task, bool) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
|
||||
Reference in New Issue
Block a user