Implement resumable download queue (T-301)

This commit is contained in:
ila
2026-07-16 19:49:06 +08:00
parent 2d302b731a
commit 8dad40f934
27 changed files with 5498 additions and 18 deletions
+43
View File
@@ -0,0 +1,43 @@
package downloader
import "context"
// EventType identifies an observer event emitted by Queue.
type EventType string
const (
EventStarted EventType = "started"
EventProgress EventType = "progress"
EventPaused EventType = "paused"
EventCompleted EventType = "completed"
EventFailed EventType = "failed"
EventCanceled EventType = "canceled"
)
// Event reports one generation of a download task. Done is monotonic within a
// RequestID+Attempt pair. A new Attempt permits a reset to zero when a server
// ignores Range or an entity cannot be safely resumed.
type Event struct {
Type EventType
RequestID string
AppID string
Attempt uint64
Done int64
TotalKnown bool
Total int64
SpeedBytesSec int64
CompletedPath string
ErrorCode string
}
// Observer receives queue events. Implementations must honor context
// cancellation so pause/cancel can wait for the old generation to exit.
type Observer interface {
PublishDownload(context.Context, Event) error
}
type discardObserver struct{}
func (discardObserver) PublishDownload(context.Context, Event) error {
return nil
}