From 5fa90196f57be652d8d9167fb39061a92f1b3f75 Mon Sep 17 00:00:00 2001 From: Pedro Brochado Date: Fri, 10 Jan 2025 17:59:51 -0300 Subject: [PATCH] Backport workaround for adding RA cooldown Original backport with migration already removed: 2f3b57b2fef50b48d48d8f61c34fdd09e04cc3e4 This adds unique migration field and update the code to use it. This will avoid conflicts with future fields. Must be cleaned up on a future release with an idempotent remove migration. --- ...0118_remoteartifact_failed_at_backport49.py | 18 ++++++++++++++++++ pulpcore/app/models/content.py | 5 +++++ pulpcore/content/handler.py | 4 ++-- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 pulpcore/app/migrations/0118_remoteartifact_failed_at_backport49.py diff --git a/pulpcore/app/migrations/0118_remoteartifact_failed_at_backport49.py b/pulpcore/app/migrations/0118_remoteartifact_failed_at_backport49.py new file mode 100644 index 0000000000..e28e43be6a --- /dev/null +++ b/pulpcore/app/migrations/0118_remoteartifact_failed_at_backport49.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.17 on 2025-01-10 20:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0117_task_unblocked_at'), + ] + + operations = [ + migrations.AddField( + model_name='remoteartifact', + name='failed_at_backport49', + field=models.DateTimeField(null=True), + ), + ] diff --git a/pulpcore/app/models/content.py b/pulpcore/app/models/content.py index b41390425b..e3adc44388 100644 --- a/pulpcore/app/models/content.py +++ b/pulpcore/app/models/content.py @@ -703,6 +703,10 @@ 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_backport49 (models.DateTimeField): + The datetime of last download attempt failure. Only for old branches to + avoid migration backport issues. + Relations: @@ -725,6 +729,7 @@ class RemoteArtifact(BaseModel, QueryMixin): content_artifact = models.ForeignKey(ContentArtifact, on_delete=models.CASCADE) remote = models.ForeignKey("Remote", on_delete=models.CASCADE) pulp_domain = models.ForeignKey("Domain", default=get_domain_pk, on_delete=models.PROTECT) + failed_at_backport49 = models.DateTimeField(null=True) objects = BulkCreateManager.from_queryset(RemoteArtifactQuerySet)() diff --git a/pulpcore/content/handler.py b/pulpcore/content/handler.py index 390122da50..28078b9a33 100644 --- a/pulpcore/content/handler.py +++ b/pulpcore/content/handler.py @@ -827,7 +827,7 @@ async def _stream_content_artifact(self, request, response, content_artifact): remote_artifacts = ( content_artifact.remoteartifact_set.select_related("remote") .order_by_acs() - .exclude(failed_at__gte=timezone.now() - timedelta(seconds=protection_time)) + .exclude(failed_at_backport49__gte=timezone.now() - timedelta(seconds=protection_time)) ) async for remote_artifact in remote_artifacts: try: @@ -1126,7 +1126,7 @@ async def finalize(): try: download_result = await downloader.run() except DigestValidationError: - remote_artifact.failed_at = timezone.now() + remote_artifact.failed_at_backport49 = timezone.now() await remote_artifact.asave() await downloader.session.close() close_tcp_connection(request.transport._sock)