Skip to content

Commit 623d715

Browse files
committed
Use Celery task to mark organization assets as not cleaned
1 parent 3d6b605 commit 623d715

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

readthedocs/organizations/signals.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
)
1919
from readthedocs.projects.models import Project
2020

21+
from .tasks import mark_organization_assets_not_cleaned as mark_organization_assets_not_cleaned_task
22+
2123
log = logging.getLogger(__name__)
2224

2325

@@ -80,8 +82,14 @@ def remove_organization_completely(sender, instance, using, **kwargs):
8082

8183
@receiver(build_complete, sender=Build)
8284
def mark_organization_assets_not_cleaned(sender, build, **kwargs):
83-
"""Mark the organization assets as not cleaned if there is a new build."""
85+
"""
86+
Mark the organization assets as not cleaned if there is a new build.
87+
88+
This signal triggers a Celery task because the `build_complete` signal is
89+
fired by the builder and it does not have access to the database. So, we
90+
trigger a Celery task that will be executed in the web and mark the
91+
organization assets as not cleaned.
92+
"""
8493
organization = build.project.organizations.first()
8594
if build.state == BUILD_STATE_FINISHED and build.success and organization:
86-
organization.artifacts_cleaned = False
87-
organization.save()
95+
mark_organization_assets_not_cleaned_task.delay(build)

readthedocs/organizations/tasks.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import logging
2+
3+
from readthedocs.worker import app
4+
5+
6+
log = logging.getLogger(__name__)
7+
8+
9+
@app.task(queue='web')
10+
def mark_organization_assets_not_cleaned(organization):
11+
log.info("Marking organization as not cleaned. organization=%s", organization.slug)
12+
organization.artifacts_cleaned = False
13+
organization.save()

0 commit comments

Comments
 (0)