mirror of
https://github.com/ansible/awx.git
synced 2026-05-14 04:47:44 -02:30
Merge pull request #5457 from AlanCoding/always_release_lock
Fix situation were error happened before lock was released Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -2215,25 +2215,28 @@ class RunProjectUpdate(BaseTask):
|
|||||||
copy_tree(project_path, destination_folder)
|
copy_tree(project_path, destination_folder)
|
||||||
|
|
||||||
def post_run_hook(self, instance, status):
|
def post_run_hook(self, instance, status):
|
||||||
if self.playbook_new_revision:
|
# To avoid hangs, very important to release lock even if errors happen here
|
||||||
instance.scm_revision = self.playbook_new_revision
|
try:
|
||||||
instance.save(update_fields=['scm_revision'])
|
if self.playbook_new_revision:
|
||||||
if self.job_private_data_dir:
|
instance.scm_revision = self.playbook_new_revision
|
||||||
# copy project folder before resetting to default branch
|
instance.save(update_fields=['scm_revision'])
|
||||||
# because some git-tree-specific resources (like submodules) might matter
|
if self.job_private_data_dir:
|
||||||
self.make_local_copy(
|
# copy project folder before resetting to default branch
|
||||||
instance.get_project_path(check_if_exists=False), os.path.join(self.job_private_data_dir, 'project'),
|
# because some git-tree-specific resources (like submodules) might matter
|
||||||
instance.scm_type, instance.scm_revision
|
self.make_local_copy(
|
||||||
)
|
instance.get_project_path(check_if_exists=False), os.path.join(self.job_private_data_dir, 'project'),
|
||||||
if self.original_branch:
|
instance.scm_type, instance.scm_revision
|
||||||
# for git project syncs, non-default branches can be problems
|
)
|
||||||
# restore to branch the repo was on before this run
|
if self.original_branch:
|
||||||
try:
|
# for git project syncs, non-default branches can be problems
|
||||||
self.original_branch.checkout()
|
# restore to branch the repo was on before this run
|
||||||
except Exception:
|
try:
|
||||||
# this could have failed due to dirty tree, but difficult to predict all cases
|
self.original_branch.checkout()
|
||||||
logger.exception('Failed to restore project repo to prior state after {}'.format(instance.log_format))
|
except Exception:
|
||||||
self.release_lock(instance)
|
# this could have failed due to dirty tree, but difficult to predict all cases
|
||||||
|
logger.exception('Failed to restore project repo to prior state after {}'.format(instance.log_format))
|
||||||
|
finally:
|
||||||
|
self.release_lock(instance)
|
||||||
p = instance.project
|
p = instance.project
|
||||||
if instance.job_type == 'check' and status not in ('failed', 'canceled',):
|
if instance.job_type == 'check' and status not in ('failed', 'canceled',):
|
||||||
if self.playbook_new_revision:
|
if self.playbook_new_revision:
|
||||||
|
|||||||
Reference in New Issue
Block a user