mirror of
https://github.com/ansible/awx.git
synced 2026-03-10 05:59:28 -02:30
Check if the project update for the project we are trying to lock is canceled
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
from collections import OrderedDict, namedtuple
|
from collections import OrderedDict, namedtuple
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import cStringIO
|
import cStringIO
|
||||||
|
import errno
|
||||||
import functools
|
import functools
|
||||||
import importlib
|
import importlib
|
||||||
import json
|
import json
|
||||||
@@ -1668,18 +1669,28 @@ class RunProjectUpdate(BaseTask):
|
|||||||
logger.error(six.text_type("I/O error({0}) while trying to open lock file [{1}]: {2}").format(e.errno, lock_path, e.strerror))
|
logger.error(six.text_type("I/O error({0}) while trying to open lock file [{1}]: {2}").format(e.errno, lock_path, e.strerror))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
try:
|
start_time = time.time()
|
||||||
start_time = time.time()
|
while True:
|
||||||
fcntl.flock(self.lock_fd, fcntl.LOCK_EX)
|
try:
|
||||||
waiting_time = time.time() - start_time
|
instance.refresh_from_db()
|
||||||
if waiting_time > 1.0:
|
if instance.cancel_flag:
|
||||||
logger.info(six.text_type(
|
logger.info(six.text_type("ProjectUpdate({0}) was cancelled".format(instance.pk)))
|
||||||
'{} spent {} waiting to acquire lock for local source tree '
|
return
|
||||||
'for path {}.').format(instance.log_format, waiting_time, lock_path))
|
fcntl.flock(self.lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
except IOError as e:
|
break
|
||||||
os.close(self.lock_fd)
|
except IOError as e:
|
||||||
logger.error(six.text_type("I/O error({0}) while trying to aquire lock on file [{1}]: {2}").format(e.errno, lock_path, e.strerror))
|
if e.errno != errno.EAGAIN:
|
||||||
raise
|
os.close(self.lock_fd)
|
||||||
|
logger.error(six.text_type("I/O error({0}) while trying to aquire lock on file [{1}]: {2}").format(e.errno, lock_path, e.strerror))
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
time.sleep(1.0)
|
||||||
|
waiting_time = time.time() - start_time
|
||||||
|
|
||||||
|
if waiting_time > 1.0:
|
||||||
|
logger.info(six.text_type(
|
||||||
|
'{} spent {} waiting to acquire lock for local source tree '
|
||||||
|
'for path {}.').format(instance.log_format, waiting_time, lock_path))
|
||||||
|
|
||||||
def pre_run_hook(self, instance, **kwargs):
|
def pre_run_hook(self, instance, **kwargs):
|
||||||
# re-create root project folder if a natural disaster has destroyed it
|
# re-create root project folder if a natural disaster has destroyed it
|
||||||
|
|||||||
Reference in New Issue
Block a user