Skip to content

Track organization artifacts cleanup #8418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions readthedocs/organizations/migrations/0006_add_assets_cleaned.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.2.24 on 2021-08-17 14:54

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('organizations', '0005_historicalorganization_historicalteam'),
]

operations = [
migrations.AddField(
model_name='historicalorganization',
name='artifacts_cleaned',
field=models.BooleanField(default=False, help_text='Artifacts are cleaned out from storage', verbose_name='Artifacts Cleaned'),
),
migrations.AddField(
model_name='organization',
name='artifacts_cleaned',
field=models.BooleanField(default=False, help_text='Artifacts are cleaned out from storage', verbose_name='Artifacts Cleaned'),
),
]
5 changes: 5 additions & 0 deletions readthedocs/organizations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class Organization(models.Model):
help_text='Docs and builds are disabled for this organization',
default=False,
)
artifacts_cleaned = models.BooleanField(
_('Artifacts Cleaned'),
help_text='Artifacts are cleaned out from storage',
default=False,
)
max_concurrent_builds = models.IntegerField(
_('Maximum concurrent builds allowed for this organization'),
null=True,
Expand Down
13 changes: 12 additions & 1 deletion readthedocs/organizations/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from django.db.models.signals import pre_delete
from django.dispatch import receiver

from readthedocs.builds.models import Version
from readthedocs.builds.constants import BUILD_STATE_FINISHED
from readthedocs.builds.models import Build, Version
from readthedocs.builds.signals import build_complete
from readthedocs.organizations.models import (
Organization,
Team,
Expand Down Expand Up @@ -74,3 +76,12 @@ def remove_organization_completely(sender, instance, using, **kwargs):
version.delete()

projects.delete()


@receiver(build_complete, sender=Build)
def mark_organization_assets_not_cleaned(sender, build, **kwargs):
"""Mark the organization assets as not cleaned if there is a new build."""
organization = build.project.organizations.first()
if build.state == BUILD_STATE_FINISHED and build.success and organization:
organization.artifacts_cleaned = False
organization.save()