Documentation
¶
Index ¶
- type DownloadInfo
- type DownloadManager
- func (dm *DownloadManager) DownloadFile(ctx context.Context, file *state.File) error
- func (dm *DownloadManager) GetStats() *DownloadManagerStats
- func (dm *DownloadManager) ScheduleBatch(files []*state.File) error
- func (dm *DownloadManager) ScheduleDownload(file *state.File, priority int) error
- func (dm *DownloadManager) Start(ctx context.Context) error
- func (dm *DownloadManager) Stop() error
- type DownloadManagerConfig
- type DownloadManagerStats
- type DownloadStats
- func (ds *DownloadStats) AddBytes(n int64)
- func (ds *DownloadStats) CompleteDownload(bytes int64, duration time.Duration)
- func (ds *DownloadStats) DecrementActiveDownloads()
- func (ds *DownloadStats) IncrementDownloads()
- func (ds *DownloadStats) IncrementDownloadsAndActive()
- func (ds *DownloadStats) IncrementFailedDownloads()
- type DownloadTask
- type Engine
- func (e *Engine) GetProgress() *SyncProgress
- func (e *Engine) Pause() error
- func (e *Engine) Resume() error
- func (e *Engine) ResumeSession(ctx context.Context, sessionID string) error
- func (e *Engine) StartNewSession(ctx context.Context, rootFolderID, destinationPath string) error
- func (e *Engine) StartNewSessionWithID(ctx context.Context, rootFolderID, destinationPath string) (string, error)
- func (e *Engine) Stop() error
- func (e *Engine) WaitForCompletion() <-chan struct{}
- type EngineConfig
- type Event
- type EventBus
- func (eb *EventBus) Close()
- func (eb *EventBus) CloseChannel(name string)
- func (eb *EventBus) CreateChannel(name string) <-chan Event
- func (eb *EventBus) Publish(event Event)
- func (eb *EventBus) PublishFileComplete(fileID, fileName string, bytesTransferred int64)
- func (eb *EventBus) PublishFileError(fileID, fileName string, err error)
- func (eb *EventBus) PublishFileProgress(fileID string, bytesTransferred int64)
- func (eb *EventBus) PublishFileStart(fileID, fileName, filePath string, fileSize int64)
- func (eb *EventBus) PublishSyncComplete(sessionID string, processedFiles, processedBytes int64)
- func (eb *EventBus) PublishSyncStart(sessionID string, totalFiles, totalBytes int64)
- func (eb *EventBus) Subscribe(eventType EventType, handler EventHandler, filter EventFilter, ...)
- func (eb *EventBus) SubscribeAll(handler EventHandler, filter EventFilter, priority EventPriority)
- type EventFilter
- type EventHandler
- type EventPriority
- type EventType
- type FileEvent
- type FileProgress
- type FolderEvent
- type FolderWalker
- type HandlerInfo
- type PriorityQueue
- type ProgressEvent
- type ProgressEventType
- type ProgressStats
- type ProgressTracker
- func (pt *ProgressTracker) CheckBandwidthLimit(ctx context.Context, bytesRequested int64) error
- func (pt *ProgressTracker) FileCompleted(fileID string)
- func (pt *ProgressTracker) FileFailed(fileID string, err error)
- func (pt *ProgressTracker) FileProgress(fileID string, bytesDownloaded int64)
- func (pt *ProgressTracker) FileSkipped(fileID, fileName, filePath string, reason string)
- func (pt *ProgressTracker) FileStarted(fileID, fileName, filePath string, totalBytes int64)
- func (pt *ProgressTracker) FolderCompleted(folderID, folderName, folderPath string, fileCount int64)
- func (pt *ProgressTracker) FolderStarted(folderID, folderName, folderPath string)
- func (pt *ProgressTracker) GetStats() *ProgressStats
- func (pt *ProgressTracker) OnEvent(handler func(event *ProgressEvent))
- func (pt *ProgressTracker) SetBandwidthLimit(bytesPerSecond int64)
- func (pt *ProgressTracker) SetTotals(totalFiles, totalBytes int64)
- type RetryEvent
- type SyncEvent
- type SyncProgress
- type TaskResult
- type TraversalStrategy
- type WalkResult
- type WalkerConfig
- type WalkerStats
- type Worker
- type WorkerPool
- type WorkerPoolConfig
- type WorkerPoolStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DownloadInfo ¶
type DownloadInfo struct {
StartTime time.Time
FileID string
FileName string
TempPath string
FinalPath string
Checksum string
ExportFormat string
Size int64
BytesDownloaded int64
IsGoogleDoc bool
}
DownloadInfo tracks active download information.
type DownloadManager ¶
type DownloadManager struct {
// contains filtered or unexported fields
}
DownloadManager manages file downloads with advanced features.
func NewDownloadManager ¶
func NewDownloadManager( client *api.DriveClient, stateManager *state.Manager, progressTracker *ProgressTracker, errorHandler *errors.Handler, logger *logger.Logger, config *DownloadManagerConfig, ) (*DownloadManager, error)
NewDownloadManager creates a new download manager.
func (*DownloadManager) DownloadFile ¶
DownloadFile downloads a single file with resume support.
func (*DownloadManager) GetStats ¶
func (dm *DownloadManager) GetStats() *DownloadManagerStats
GetStats returns download manager statistics.
func (*DownloadManager) ScheduleBatch ¶
func (dm *DownloadManager) ScheduleBatch(files []*state.File) error
ScheduleBatch schedules a batch of files for download.
func (*DownloadManager) ScheduleDownload ¶
func (dm *DownloadManager) ScheduleDownload(file *state.File, priority int) error
ScheduleDownload schedules a file for download.
func (*DownloadManager) Start ¶
func (dm *DownloadManager) Start(ctx context.Context) error
Start starts the download manager.
func (*DownloadManager) Stop ¶
func (dm *DownloadManager) Stop() error
Stop stops the download manager.
type DownloadManagerConfig ¶
type DownloadManagerConfig struct {
TempDir string
ChunkSize int64
MaxConcurrent int
VerifyChecksums bool
}
DownloadManagerConfig contains configuration for the download manager.
func DefaultDownloadManagerConfig ¶
func DefaultDownloadManagerConfig() *DownloadManagerConfig
DefaultDownloadManagerConfig returns default configuration.
type DownloadManagerStats ¶
type DownloadManagerStats struct {
WorkerPoolStats *WorkerPoolStats
TotalDownloads int64
ActiveDownloads int64
CompletedDownloads int64
FailedDownloads int64
BytesDownloaded int64
AverageSpeed int64
AverageDuration time.Duration
}
DownloadManagerStats contains download manager statistics.
type DownloadStats ¶
type DownloadStats struct {
TotalDownloads int64
ActiveDownloads int64
CompletedDownloads int64
FailedDownloads int64
BytesDownloaded int64
TotalDuration time.Duration
// contains filtered or unexported fields
}
DownloadStats tracks download statistics.
func (*DownloadStats) AddBytes ¶
func (ds *DownloadStats) AddBytes(n int64)
AddBytes atomically adds n bytes to the total bytes downloaded.
func (*DownloadStats) CompleteDownload ¶
func (ds *DownloadStats) CompleteDownload(bytes int64, duration time.Duration)
CompleteDownload updates all completion-related fields together.
func (*DownloadStats) DecrementActiveDownloads ¶
func (ds *DownloadStats) DecrementActiveDownloads()
DecrementActiveDownloads decrements the active download count by 1.
func (*DownloadStats) IncrementDownloads ¶
func (ds *DownloadStats) IncrementDownloads()
IncrementDownloads atomically increments the total downloads count by 1.
func (*DownloadStats) IncrementDownloadsAndActive ¶
func (ds *DownloadStats) IncrementDownloadsAndActive()
IncrementDownloadsAndActive increments the total and active download counts together.
func (*DownloadStats) IncrementFailedDownloads ¶
func (ds *DownloadStats) IncrementFailedDownloads()
IncrementFailedDownloads increments the failed download count by 1.
type DownloadTask ¶
type DownloadTask struct {
CreatedAt time.Time
LastError error
File *state.File
StartedAt *time.Time
CompletedAt *time.Time
Priority int
Retries int
}
DownloadTask represents a file download task.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the main sync orchestrator.
func NewEngine ¶
func NewEngine( client *api.DriveClient, stateManager *state.Manager, errorHandler *errors.Handler, logger *logger.Logger, config *EngineConfig, ) (*Engine, error)
NewEngine creates a new sync engine.
func (*Engine) GetProgress ¶
func (e *Engine) GetProgress() *SyncProgress
GetProgress returns current sync progress.
func (*Engine) ResumeSession ¶
ResumeSession resumes an existing sync session.
func (*Engine) StartNewSession ¶
StartNewSession starts a new sync session.
func (*Engine) StartNewSessionWithID ¶
func (e *Engine) StartNewSessionWithID(ctx context.Context, rootFolderID, destinationPath string) (string, error)
StartNewSessionWithID starts a new sync session and returns the session ID.
func (*Engine) WaitForCompletion ¶
func (e *Engine) WaitForCompletion() <-chan struct{}
WaitForCompletion waits until the sync engine completes.
type EngineConfig ¶
type EngineConfig struct {
// Folder walker configuration
WalkerConfig *WalkerConfig
// Download manager configuration
DownloadConfig *DownloadManagerConfig
// Worker pool configuration
WorkerConfig *WorkerPoolConfig
// Progress update interval
ProgressInterval time.Duration
// Session checkpoint interval
CheckpointInterval time.Duration
// Maximum errors before stopping
MaxErrors int
}
EngineConfig contains configuration for the sync engine.
func DefaultEngineConfig ¶
func DefaultEngineConfig() *EngineConfig
DefaultEngineConfig returns default engine configuration.
type Event ¶
type Event struct {
Timestamp time.Time
Data interface{}
Type EventType
Priority EventPriority
}
Event represents a sync event.
type EventBus ¶
type EventBus struct {
// contains filtered or unexported fields
}
EventBus manages event distribution.
func (*EventBus) CloseChannel ¶
CloseChannel closes a named channel.
func (*EventBus) CreateChannel ¶
CreateChannel creates a named channel for event streaming.
func (*EventBus) PublishFileComplete ¶
PublishFileComplete publishes a file completion event.
func (*EventBus) PublishFileError ¶
PublishFileError publishes a file error event.
func (*EventBus) PublishFileProgress ¶
PublishFileProgress publishes a file progress event.
func (*EventBus) PublishFileStart ¶
PublishFileStart publishes a file start event.
func (*EventBus) PublishSyncComplete ¶
PublishSyncComplete publishes a sync completion event.
func (*EventBus) PublishSyncStart ¶
PublishSyncStart publishes a sync start event.
func (*EventBus) Subscribe ¶
func (eb *EventBus) Subscribe(eventType EventType, handler EventHandler, filter EventFilter, priority EventPriority)
Subscribe adds a handler for specific event types.
func (*EventBus) SubscribeAll ¶
func (eb *EventBus) SubscribeAll(handler EventHandler, filter EventFilter, priority EventPriority)
SubscribeAll adds a global handler for all events.
type EventFilter ¶
EventFilter determines if an event should be processed.
type EventPriority ¶
type EventPriority int
EventPriority defines the priority of an event.
const ( EventPriorityLow EventPriority = iota EventPriorityNormal EventPriorityHigh EventPriorityCritical )
type FileEvent ¶
type FileEvent struct {
Error error
Metadata map[string]interface{}
FileID string
FileName string
FilePath string
FileSize int64
BytesTransferred int64
}
FileEvent contains data for file-related events.
type FileProgress ¶
type FileProgress struct {
StartTime time.Time
LastUpdate time.Time
FileID string
FileName string
FilePath string
TotalBytes int64
BytesDownloaded int64
Speed int64
}
FileProgress tracks individual file download progress.
type FolderEvent ¶
type FolderEvent struct {
FolderID string
FolderName string
FolderPath string
FileCount int
TotalSize int64
}
FolderEvent contains data for folder-related events.
type FolderWalker ¶
type FolderWalker struct {
// contains filtered or unexported fields
}
FolderWalker implements efficient folder tree traversal.
func NewFolderWalker ¶
func NewFolderWalker( client *api.DriveClient, stateManager *state.Manager, progressTracker *ProgressTracker, logger *logger.Logger, config *WalkerConfig, ) (*FolderWalker, error)
NewFolderWalker creates a new folder walker.
func (*FolderWalker) GetStats ¶
func (fw *FolderWalker) GetStats() *WalkerStats
GetStats returns walker statistics.
func (*FolderWalker) Walk ¶
func (fw *FolderWalker) Walk(ctx context.Context, rootFolderID string, sessionID string) (<-chan *WalkResult, error)
Walk starts walking the folder tree from the given root.
type HandlerInfo ¶
type HandlerInfo struct {
Handler EventHandler
Filter EventFilter
Priority EventPriority
}
HandlerInfo contains handler metadata.
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
PriorityQueue implements a priority queue for download tasks.
func NewPriorityQueue ¶
func NewPriorityQueue() *PriorityQueue
NewPriorityQueue creates a new priority queue.
func (*PriorityQueue) Len ¶
func (pq *PriorityQueue) Len() int
Len returns the number of tasks in the queue.
func (*PriorityQueue) Pop ¶
func (pq *PriorityQueue) Pop() *DownloadTask
Pop removes and returns the highest priority task.
func (*PriorityQueue) Push ¶
func (pq *PriorityQueue) Push(task *DownloadTask)
Push adds a task to the queue.
type ProgressEvent ¶
type ProgressEvent struct {
Timestamp time.Time
Error error
Context map[string]interface{}
SessionID string
ItemID string
ItemName string
ItemPath string
ErrorMessage string
Type ProgressEventType
FilesCompleted int64
CurrentSpeed int64
AverageSpeed int64
RemainingTime time.Duration
TotalFiles int64
TotalBytes int64
BytesTransferred int64
}
ProgressEvent represents a progress update event.
type ProgressEventType ¶
type ProgressEventType string
ProgressEventType defines types of progress events.
const ( // Progress event types as strings for better readability. ProgressEventFileStarted ProgressEventType = "file_started" ProgressEventFileProgress ProgressEventType = "file_progress" ProgressEventFileCompleted ProgressEventType = "file_completed" ProgressEventFileFailed ProgressEventType = "file_failed" ProgressEventFolderStarted ProgressEventType = "folder_started" ProgressEventFolderCompleted ProgressEventType = "folder_completed" ProgressEventSessionUpdate ProgressEventType = "session_update" ProgressEventBandwidthUpdate ProgressEventType = "bandwidth_update" )
type ProgressStats ¶
type ProgressStats struct {
StartTime time.Time
SessionID string
FailedFiles int64
RemainingTime time.Duration
TotalFiles int64
CompletedFiles int64
ElapsedTime time.Duration
SkippedFiles int64
TotalBytes int64
CompletedBytes int64
CurrentSpeed int64
AverageSpeed int64
ActiveDownloads int
BandwidthLimit int64
}
ProgressStats contains current progress statistics.
func (*ProgressStats) BytesProgress ¶
func (ps *ProgressStats) BytesProgress() float64
BytesProgress returns bytes completion percentage.
func (*ProgressStats) Progress ¶
func (ps *ProgressStats) Progress() float64
Progress returns completion percentage.
type ProgressTracker ¶
type ProgressTracker struct {
// contains filtered or unexported fields
}
ProgressTracker tracks sync progress and emits events.
func NewProgressTracker ¶
func NewProgressTracker(sessionID string) *ProgressTracker
NewProgressTracker creates a new progress tracker.
func (*ProgressTracker) CheckBandwidthLimit ¶
func (pt *ProgressTracker) CheckBandwidthLimit(ctx context.Context, bytesRequested int64) error
CheckBandwidthLimit checks if we're within bandwidth limits.
func (*ProgressTracker) FileCompleted ¶
func (pt *ProgressTracker) FileCompleted(fileID string)
FileCompleted notifies that a file download completed.
func (*ProgressTracker) FileFailed ¶
func (pt *ProgressTracker) FileFailed(fileID string, err error)
FileFailed notifies that a file download failed.
func (*ProgressTracker) FileProgress ¶
func (pt *ProgressTracker) FileProgress(fileID string, bytesDownloaded int64)
FileProgress updates file download progress.
func (*ProgressTracker) FileSkipped ¶
func (pt *ProgressTracker) FileSkipped(fileID, fileName, filePath string, reason string)
FileSkipped notifies that a file was skipped.
func (*ProgressTracker) FileStarted ¶
func (pt *ProgressTracker) FileStarted(fileID, fileName, filePath string, totalBytes int64)
FileStarted notifies that a file download has started.
func (*ProgressTracker) FolderCompleted ¶
func (pt *ProgressTracker) FolderCompleted(folderID, folderName, folderPath string, fileCount int64)
FolderCompleted notifies that folder scanning completed.
func (*ProgressTracker) FolderStarted ¶
func (pt *ProgressTracker) FolderStarted(folderID, folderName, folderPath string)
FolderStarted notifies that folder scanning started.
func (*ProgressTracker) GetStats ¶
func (pt *ProgressTracker) GetStats() *ProgressStats
GetStats returns current progress statistics.
func (*ProgressTracker) OnEvent ¶
func (pt *ProgressTracker) OnEvent(handler func(event *ProgressEvent))
OnEvent registers an event handler.
func (*ProgressTracker) SetBandwidthLimit ¶
func (pt *ProgressTracker) SetBandwidthLimit(bytesPerSecond int64)
SetBandwidthLimit sets the bandwidth limit in bytes per second.
func (*ProgressTracker) SetTotals ¶
func (pt *ProgressTracker) SetTotals(totalFiles, totalBytes int64)
SetTotals sets the total files and bytes for the session.
type RetryEvent ¶
type RetryEvent struct {
NextRetryAt time.Time
Error error
FileID string
FileName string
RetryCount int
MaxRetries int
}
RetryEvent contains data for retry events.
type SyncEvent ¶
type SyncEvent struct {
StartTime time.Time
SessionID string
Message string
TotalFiles int64
TotalBytes int64
ProcessedFiles int64
ProcessedBytes int64
}
SyncEvent contains data for sync-related events.
type SyncProgress ¶
type SyncProgress struct {
StartTime time.Time
SessionID string
Status string
SkippedFiles int64
RemainingTime time.Duration
TotalFiles int64
CompletedFiles int64
FailedFiles int64
ElapsedTime time.Duration
TotalBytes int64
CompletedBytes int64
CurrentSpeed int64
AverageSpeed int64
FoldersScanned int64
ActiveDownloads int64
QueuedDownloads int
}
SyncProgress represents the current sync progress.
type TaskResult ¶
type TaskResult struct {
Error error
Task *DownloadTask
BytesWritten int64
Duration time.Duration
WorkerID int
Success bool
}
TaskResult represents the result of a download task.
type TraversalStrategy ¶
type TraversalStrategy int
TraversalStrategy defines the folder traversal strategy.
const ( // TraversalBFS performs breadth-first search traversal. TraversalBFS TraversalStrategy = iota // TraversalDFS performs depth-first search traversal. TraversalDFS )
type WalkResult ¶
type WalkResult struct {
Error error
Folder *state.Folder
SkipReason string
Files []*state.File
Depth int
IsSkipped bool
}
WalkResult represents a folder walk result.
type WalkerConfig ¶
type WalkerConfig struct {
IncludePatterns []string
ExcludePatterns []string
Strategy TraversalStrategy
MaxDepth int
Concurrency int
ChannelBufferSize int
FollowShortcuts bool
}
WalkerConfig contains configuration for the folder walker.
func DefaultWalkerConfig ¶
func DefaultWalkerConfig() *WalkerConfig
DefaultWalkerConfig returns default walker configuration.
type WalkerStats ¶
WalkerStats contains walker statistics.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker represents a download worker.
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool manages concurrent download workers.
func NewWorkerPool ¶
func NewWorkerPool( client *api.DriveClient, stateManager *state.Manager, progressTracker *ProgressTracker, errorHandler *errors.Handler, logger *logger.Logger, config *WorkerPoolConfig, ) *WorkerPool
NewWorkerPool creates a new worker pool.
func (*WorkerPool) GetStats ¶
func (wp *WorkerPool) GetStats() *WorkerPoolStats
GetStats returns worker pool statistics.
func (*WorkerPool) SetDownloadManager ¶
func (wp *WorkerPool) SetDownloadManager(dm *DownloadManager)
SetDownloadManager sets the download manager reference.
func (*WorkerPool) Start ¶
func (wp *WorkerPool) Start(ctx context.Context) error
Start starts the worker pool.
func (*WorkerPool) SubmitTask ¶
func (wp *WorkerPool) SubmitTask(file *state.File, priority int) error
SubmitTask submits a download task to the pool.
type WorkerPoolConfig ¶
WorkerPoolConfig contains configuration for the worker pool.
func DefaultWorkerPoolConfig ¶
func DefaultWorkerPoolConfig() *WorkerPoolConfig
DefaultWorkerPoolConfig returns default configuration.