Skip to content

Commit

Permalink
Issue #35: prevent crash if missing started_on
Browse files Browse the repository at this point in the history
  • Loading branch information
rgaudin committed May 1, 2024
1 parent 016046d commit 44a20c8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.2] - 2024-05-01

### Fixed

- Download crash if started_on information is missing (#35)

## [1.1.1] - 2024-04-24

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/image_creator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.1.1"
__version__ = "1.1.2"
12 changes: 9 additions & 3 deletions src/image_creator/utils/aria2.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,21 +906,27 @@ def get_feedback(self, only_for: list[str] | None = None):
started_ons.append(dl.started_on)
completed_ons.append(dl.completed_on)
feedbacks.append(feedback)
started_on = min(started_ons)

completed_on = (
max(completed_ons)
if all(isinstance(item, datetime.datetime) for item in completed_ons)
else datetime.datetime.now(tz=datetime.UTC)
)
duration = completed_on - started_on
if started_ons:
started_on = min(started_ons)
duration = completed_on - started_on
general_speed = int(downloaded_bytes / duration.total_seconds())
else:
duration = datetime.timedelta(seconds=0)
general_speed = 0

return GeneralFeedback(
count=Progress(downloaded=downloaded_nb, total=total_nb, speed=0),
weight=Progress(
downloaded=downloaded_bytes, total=total_bytes, speed=speed
),
duration=duration,
speed=int(downloaded_bytes / duration.total_seconds()),
speed=general_speed,
downloads=feedbacks,
)

Expand Down

0 comments on commit 44a20c8

Please sign in to comment.