-
Notifications
You must be signed in to change notification settings - Fork 109
Process deleting projects as background task #1060
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -349,9 +349,13 @@ def __init__(self, data=None, *args, **kwargs): | |
|
||
# Default filtering by "Active" projects. | ||
if not data or data.get("is_archived", "") == "": | ||
self.queryset = self.queryset.filter(is_archived=False) | ||
self.queryset = self.queryset.filter( | ||
is_archived=False, is_marked_for_deletion=False | ||
) | ||
|
||
active_count = Project.objects.filter(is_archived=False).count() | ||
active_count = Project.objects.filter( | ||
is_archived=False, is_marked_for_deletion=False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use |
||
).count() | ||
archived_count = Project.objects.filter(is_archived=True).count() | ||
self.filters["is_archived"].extra["widget"] = BulmaLinkWidget( | ||
choices=[ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.0.1 on 2024-01-26 12:25 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('scanpipe', '0051_rename_pipelines_data'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='project', | ||
name='is_marked_for_deletion', | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,7 @@ | |
from packageurl.contrib.django.models import PackageURLMixin | ||
from packageurl.contrib.django.models import PackageURLQuerySetMixin | ||
from rest_framework.authtoken.models import Token | ||
from rq import Queue | ||
from rq.command import send_stop_job_command | ||
from rq.exceptions import NoSuchJobError | ||
from rq.job import Job | ||
|
@@ -534,6 +535,7 @@ class Project(UUIDPKModel, ExtraDataFieldMixin, UpdateMixin, models.Model): | |
labels = TaggableManager(through=UUIDTaggedItem) | ||
|
||
objects = ProjectQuerySet.as_manager() | ||
is_marked_for_deletion = models.BooleanField(default=False) | ||
jayanth-kumar-morem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
class Meta: | ||
ordering = ["-created_date"] | ||
|
@@ -633,6 +635,16 @@ def delete(self, *args, **kwargs): | |
|
||
return super().delete(*args, **kwargs) | ||
|
||
def mark_for_deletion(self): | ||
self.is_marked_for_deletion = True | ||
self.save() | ||
jayanth-kumar-morem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def delete_in_background(self): | ||
# Mark the project for deletion and enqueue background deletion task | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A docstring would be better than a comment. |
||
self.mark_for_deletion() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can put |
||
q = Queue("default", connection=redis.Redis()) | ||
job = q.enqueue(tasks.background_delete_task, self) | ||
jayanth-kumar-morem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def reset(self, keep_input=True): | ||
""" | ||
Reset the project by deleting all related database objects and all work | ||
|
Uh oh!
There was an error while loading. Please reload this page.