1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-30 22:21:13 +03:00

Merge pull request #2287 from AlanCoding/files_are_in_the_computer

automatically delete project files in entire cluster

Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
softwarefactory-project-zuul[bot] 2018-10-25 20:53:20 +00:00 committed by GitHub
commit 9bca937fad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -466,6 +466,14 @@ class Project(UnifiedJobTemplate, ProjectOptions, ResourceMixin, CustomVirtualEn
models.Q(ProjectUpdate___project=self)
)
def delete(self, *args, **kwargs):
path_to_delete = self.get_project_path(check_if_exists=False)
r = super(Project, self).delete(*args, **kwargs)
if self.scm_type and path_to_delete: # non-manual, concrete path
from awx.main.tasks import delete_project_files
delete_project_files.delay(path_to_delete)
return r
class ProjectUpdate(UnifiedJob, ProjectOptions, JobNotificationMixin, TaskManagerProjectUpdateMixin):
'''

View File

@ -251,6 +251,24 @@ def handle_setting_changes(setting_keys):
cache.delete_many(cache_keys)
@task(queue='tower_broadcast_all', exchange_type='fanout')
def delete_project_files(project_path):
# TODO: possibly implement some retry logic
lock_file = project_path + '.lock'
if os.path.exists(project_path):
try:
shutil.rmtree(project_path)
logger.info(six.text_type('Success removing project files {}').format(project_path))
except Exception:
logger.exception(six.text_type('Could not remove project directory {}').format(project_path))
if os.path.exists(lock_file):
try:
os.remove(lock_file)
logger.debug(six.text_type('Success removing {}').format(lock_file))
except Exception:
logger.exception(six.text_type('Could not remove lock file {}').format(lock_file))
@task()
def send_notifications(notification_list, job_id=None):
if not isinstance(notification_list, list):