feat(task): record and display task completion time (#1536)

This commit is contained in:
Levi authored and GitHub committed 2026-09-25 19:15:31 +08:00
1 parent 7ce4fb7f0e
commit 224b488087
30 files changed
+113 -23

No files matched your search

+10
View File
@@ -32,6 +32,10 @@ type Task struct {
Progress *Progress `json:"progress"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
// DoneAt is the time when the task completed; nil if it has never
// finished. A done task never leaves the done state, so the value is
// written once and kept.
DoneAt *time.Time `json:"doneAt"`
producer production.Source
producerReceived int64
@@ -134,6 +138,12 @@ func (t *Task) MarshalJSON() ([]byte, error) {
func (t *Task) updateStatus(status base.Status) {
t.UpdatedAt = time.Now()
t.Status = status
// A done task never leaves the done state, so there is no branch to clear
// DoneAt on other transitions.
if status == base.DownloadStatusDone {
doneAt := time.Now()
t.DoneAt = &doneAt
}
}
func (t *Task) clone() *Task {