Skip to content

Commit 3d6b605

Browse files
committed
Track organization artifacts cleanup
Add an extra field on the `Organization` model to keep track if its artificats were already cleanup. This allows us to filter disabled organization and run the cleaning periodically. The new field `Organization.artifacts_cleaned` is automatically set as `False` when a new build happens for any Project under the organization and is set to `True` when running a Django Admin action over the organization.
1 parent e475637 commit 3d6b605

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 2.2.24 on 2021-08-17 14:54
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('organizations', '0005_historicalorganization_historicalteam'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='historicalorganization',
15+
name='artifacts_cleaned',
16+
field=models.BooleanField(default=False, help_text='Artifacts are cleaned out from storage', verbose_name='Artifacts Cleaned'),
17+
),
18+
migrations.AddField(
19+
model_name='organization',
20+
name='artifacts_cleaned',
21+
field=models.BooleanField(default=False, help_text='Artifacts are cleaned out from storage', verbose_name='Artifacts Cleaned'),
22+
),
23+
]

readthedocs/organizations/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ class Organization(models.Model):
7676
help_text='Docs and builds are disabled for this organization',
7777
default=False,
7878
)
79+
artifacts_cleaned = models.BooleanField(
80+
_('Artifacts Cleaned'),
81+
help_text='Artifacts are cleaned out from storage',
82+
default=False,
83+
)
7984
max_concurrent_builds = models.IntegerField(
8085
_('Maximum concurrent builds allowed for this organization'),
8186
null=True,

readthedocs/organizations/signals.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
from django.db.models.signals import pre_delete
88
from django.dispatch import receiver
99

10-
from readthedocs.builds.models import Version
10+
from readthedocs.builds.constants import BUILD_STATE_FINISHED
11+
from readthedocs.builds.models import Build, Version
12+
from readthedocs.builds.signals import build_complete
1113
from readthedocs.organizations.models import (
1214
Organization,
1315
Team,
@@ -74,3 +76,12 @@ def remove_organization_completely(sender, instance, using, **kwargs):
7476
version.delete()
7577

7678
projects.delete()
79+
80+
81+
@receiver(build_complete, sender=Build)
82+
def mark_organization_assets_not_cleaned(sender, build, **kwargs):
83+
"""Mark the organization assets as not cleaned if there is a new build."""
84+
organization = build.project.organizations.first()
85+
if build.state == BUILD_STATE_FINISHED and build.success and organization:
86+
organization.artifacts_cleaned = False
87+
organization.save()

0 commit comments

Comments
 (0)