GetTaskStatus returns the current status of the task.
()
| 78 | |
| 79 | // GetTaskStatus returns the current status of the task. |
| 80 | func (s *TaskService) GetTaskStatus() (*TaskStatus, error) { |
| 81 | statusBytes, err := s.store.Get(globalTaskKey) |
| 82 | if err != nil { |
| 83 | if errors.Is(err, store.ErrNotFound) { |
| 84 | return &TaskStatus{IsRunning: false}, nil |
| 85 | } |
| 86 | return nil, fmt.Errorf("failed to get task status: %w", err) |
| 87 | } |
| 88 | |
| 89 | var status TaskStatus |
| 90 | if err := json.Unmarshal(statusBytes, &status); err != nil { |
| 91 | return nil, fmt.Errorf("failed to deserialize task status: %w", err) |
| 92 | } |
| 93 | |
| 94 | if !status.IsRunning && status.FinishedAt != nil { |
| 95 | status.DurationSeconds = status.FinishedAt.Sub(status.StartedAt).Seconds() |
| 96 | } |
| 97 | |
| 98 | return &status, nil |
| 99 | } |
| 100 | |
| 101 | // UpdateProgress updates the progress of the current task. |
| 102 | func (s *TaskService) UpdateProgress(processed int) error { |
no test coverage detected