Skip to content

Commit

Permalink
Re-purpose RemoteArtifact.pulp_last_updated to read a failed_at
Browse files Browse the repository at this point in the history
A fix was introduced in pulpcore==3.69 which relied on a new DateTimeField
called 'failed_at'.
Do enable backporting that, this commits removes the migration and, as
a workaround, re-purpose a compatible field (pulp_last_updated) to serve
the same purpose.

Co-authored-by: Matthias Dellweg <[email protected]>
  • Loading branch information
pedro-psb and mdellweg committed Jan 16, 2025
1 parent 62ff400 commit ccfc63e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
18 changes: 0 additions & 18 deletions pulpcore/app/migrations/0126_remoteartifact_failed_at.py

This file was deleted.

5 changes: 3 additions & 2 deletions pulpcore/app/models/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,9 @@ class RemoteArtifact(BaseModel, QueryMixin):
sha256 (models.CharField): The expected SHA-256 checksum of the file.
sha384 (models.CharField): The expected SHA-384 checksum of the file.
sha512 (models.CharField): The expected SHA-512 checksum of the file.
failed_at (models.DateTimeField): The datetime of last download attempt failure.
pulp_last_updated (models.DateTimeField):
Re-purposed this field to enable a backport that contained a migration.
See https://github.com/pulp/pulpcore/pull/6196
Relations:
Expand All @@ -722,7 +724,6 @@ class RemoteArtifact(BaseModel, QueryMixin):
sha256 = models.CharField(max_length=64, null=True, db_index=True)
sha384 = models.CharField(max_length=96, null=True, db_index=True)
sha512 = models.CharField(max_length=128, null=True, db_index=True)
failed_at = models.DateTimeField(null=True)

content_artifact = models.ForeignKey(ContentArtifact, on_delete=models.CASCADE)
remote = models.ForeignKey("Remote", on_delete=models.CASCADE)
Expand Down
11 changes: 7 additions & 4 deletions pulpcore/content/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,11 +852,10 @@ async def _stream_content_artifact(self, request, response, content_artifact):
ClientConnectionError,
)

protection_time = settings.REMOTE_CONTENT_FETCH_FAILURE_COOLDOWN
remote_artifacts = (
content_artifact.remoteartifact_set.select_related("remote")
.order_by_acs()
.exclude(failed_at__gte=timezone.now() - timedelta(seconds=protection_time))
.exclude(pulp_last_updated__gte=timezone.now())
)
async for remote_artifact in remote_artifacts:
try:
Expand Down Expand Up @@ -1166,8 +1165,12 @@ async def finalize():
try:
download_result = await downloader.run()
except DigestValidationError:
remote_artifact.failed_at = timezone.now()
await remote_artifact.asave()
# Using this otherwise unused dbfield is a workaround to allow this fix to be
# backported. Read "failed_at" instead.
await RemoteArtifact.objects.filter(pulp_id=remote_artifact.pulp_id).aupdate(
pulp_last_updated=timezone.now()
+ timedelta(settings.REMOTE_CONTENT_FETCH_FAILURE_COOLDOWN)
)
await downloader.session.close()
close_tcp_connection(request.transport._sock)
REMOTE_CONTENT_FETCH_FAILURE_COOLDOWN = settings.REMOTE_CONTENT_FETCH_FAILURE_COOLDOWN
Expand Down

0 comments on commit ccfc63e

Please sign in to comment.