perf: 优化 playbook 删除策略,正在被 job 使用时无法被删除

This commit is contained in:
Aaron3S
2023-03-14 17:37:02 +08:00
committed by Jiangjie.Bai
parent 2ce293bd81
commit df249a0355
5 changed files with 163 additions and 120 deletions

View File

@@ -32,6 +32,15 @@ class PlaybookViewSet(OrgBulkModelViewSet):
model = Playbook
search_fields = ('name', 'comment')
def perform_destroy(self, instance):
instance = self.get_object()
if instance.job_set.exists():
raise JMSException(code='playbook_has_job', detail={"msg": _("Currently playbook is being used in a job")})
instance_id = instance.id
super().perform_destroy(instance)
dest_path = os.path.join(settings.DATA_DIR, "ops", "playbook", instance_id.__str__())
shutil.rmtree(dest_path)
def get_queryset(self):
queryset = super().get_queryset()
queryset = queryset.filter(creator=self.request.user)