Skip to content

Commit

Permalink
fixup: implement fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-psb committed Nov 27, 2024
1 parent 5594395 commit d5f13af
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
18 changes: 18 additions & 0 deletions pulpcore/app/migrations/0126_remoteartifact_failed_at.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.16 on 2024-11-27 15:06

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0125_openpgpdistribution_openpgpkeyring_openpgppublickey_and_more'),
]

operations = [
migrations.AddField(
model_name='remoteartifact',
name='failed_at',
field=models.DateTimeField(null=True),
),
]
2 changes: 2 additions & 0 deletions pulpcore/app/models/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ 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.
Relations:
Expand All @@ -721,6 +722,7 @@ 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
12 changes: 9 additions & 3 deletions pulpcore/content/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import socket
import struct
from gettext import gettext as _
from datetime import timedelta

from aiohttp.client_exceptions import ClientResponseError, ClientConnectionError
from aiohttp.web import FileResponse, StreamResponse, HTTPOk
Expand All @@ -22,6 +23,7 @@
from asgiref.sync import sync_to_async

import django
from django.utils import timezone

from pulpcore.constants import STORAGE_RESPONSE_MAP
from pulpcore.responses import ArtifactResponse
Expand Down Expand Up @@ -828,9 +830,11 @@ async def _stream_content_artifact(self, request, response, content_artifact):
ClientConnectionError,
)

remote_artifacts = content_artifact.remoteartifact_set.select_related(
"remote"
).order_by_acs()
remote_artifacts = (
content_artifact.remoteartifact_set.select_related("remote")
.order_by_acs()
.exclude(failed_at__gte=timezone.now() - timedelta(minutes=5))
)
async for remote_artifact in remote_artifacts:
try:
response = await self._stream_remote_artifact(request, response, remote_artifact)
Expand Down Expand Up @@ -1140,6 +1144,8 @@ async def finalize():
try:
download_result = await downloader.run()
except DigestValidationError:
remote_artifact.failed_at = timezone.now()
await remote_artifact.asave()
await downloader.session.close()
close_tcp_connection(request.transport._sock)
raise RuntimeError(
Expand Down

0 comments on commit d5f13af

Please sign in to comment.