-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Task to remove orphan symlinks #3543
Conversation
readthedocs/projects/tasks.py
Outdated
for domain_path in [symlink.PROJECT_CNAME_ROOT, symlink.CNAME_ROOT]: | ||
for domain in os.listdir(domain_path): | ||
try: | ||
Domain.objects.get(domain=domain) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A different approach on the implementation, making just one query to database could be like this:
valid_cnames = set(Domain.objects.all().values_list('domain', flat=True))
orphan_cnames = set(os.listdir(domain_path)) - valid_cnames
for cname in orphan_cnames:
os.unlink(orphan_domain_path)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this approach, it saves a lot of queries.
The issue link here is wrong. Would be good to know more about the background here. I imagine there are places we should fixing this logic in the code too. |
@ericholscher I fixed the issue link in the description. There are some context in the issue.
I'm not very familiarized about how symlinks work, but this PR is half of the solution that it's described in the issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests look good! I do prefer the second query you posted, so I'd say 👍 on moving to that query.
readthedocs/projects/tasks.py
Outdated
for domain_path in [symlink.PROJECT_CNAME_ROOT, symlink.CNAME_ROOT]: | ||
for domain in os.listdir(domain_path): | ||
try: | ||
Domain.objects.get(domain=domain) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this approach, it saves a lot of queries.
@agjohnson I changed the query and did a quick test locally: all the cnames that comes with the test data (
Please, take a new a look at this and after merged I will create a new PR under |
Any reason to not set the task up as a scheduled task in the application? I think we can keep this out of ops. |
No strong reason, really. I though we were setup them only in the |
We have scheduled tasks set up in our corporate repo. The ops tasks are just for tasks that only make sense in production. This is a task that would be useful for a development instance. |
2555fe0
to
55463c0
Compare
I define the task here under This should be ready to be merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops! One thing i didn't catch here was that this isn't calling broadcast to all webs. Celery beat only runs one instance per cluster, not on each instance. The task will need to call broadcast instead.
The changes look okay at this point, but the call logic and tests will change with this.
55463c0
to
b847b4b
Compare
I just pushed the changes requested. I didn't find any example for celery beat and broadcast. So, I created a new task just to broadcast the one that I already had.
|
I resolved conflicts here, going to wait on tests to merge though |
Same issue with linting. Merging! |
This is an initial implementation of this task to remove orpahn symlinks, which should be ran periodically every 1h aprox.
In the ticket, I also suggested that the
Edit
action doesn't make sense to me and should be reconsidered.Finally, if we consider to remove the
Edit
action, this task should be run just once and should be enough.Closes #3493