Add structured logging and better error handling
This commit is contained in:
1 parent
db4e3c9611
commit
68c7dd76f2
31 files changed
+640
-109
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@@ -76,6 +77,12 @@ func (manager *Manager) UpdatePreferences(next preferences.Preferences) error {
|
||||
return err
|
||||
}
|
||||
manager.policy.SetAllowedPorts(next.AllowedPorts)
|
||||
slog.Debug("preferences saved",
|
||||
"parallel_downloads", next.MaxConcurrentDownloads,
|
||||
"connections_per_download", next.ConnectionsPerDownload,
|
||||
"min_free_gb", next.MinFreeGB,
|
||||
"download_paths", len(next.DownloadPaths),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -137,6 +144,11 @@ func (manager *Manager) Create(request CreateRequest) (Snapshot, error) {
|
||||
|
||||
manager.store(job)
|
||||
job.saveRecord()
|
||||
job.logger().Info("download added",
|
||||
"url", job.displayURL,
|
||||
"file_name", requestedName,
|
||||
"target", job.snapshot().MoveTarget,
|
||||
)
|
||||
manager.launchDownload(job)
|
||||
return job.snapshot(), nil
|
||||
}
|
||||
@@ -186,7 +198,12 @@ func (manager *Manager) Delete(id string) error {
|
||||
delete(manager.jobs, id)
|
||||
manager.mutex.Unlock()
|
||||
|
||||
return os.RemoveAll(job.directory)
|
||||
if err := os.RemoveAll(job.directory); err != nil {
|
||||
job.logger().Error("could not remove download files", "directory", job.directory, "error", err)
|
||||
return err
|
||||
}
|
||||
job.logger().Info("download removed")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *Manager) Shutdown(ctx context.Context) {
|
||||
@@ -208,6 +225,7 @@ func (manager *Manager) Shutdown(ctx context.Context) {
|
||||
select {
|
||||
case <-finished:
|
||||
case <-ctx.Done():
|
||||
slog.Warn("stopped waiting for downloads to save progress", "error", ctx.Err())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user