[ux] add a warning mecanism to inform the user about the current lock

This commit is contained in:
Laurent Peuch 2019-07-20 04:45:01 +02:00
parent 02c320f553
commit 44878d7148
2 changed files with 19 additions and 1 deletions

View file

@ -51,5 +51,7 @@
"download_timeout": "{url:s} took too long to answer, gave up.",
"download_unknown_error": "Error when downloading data from {url:s}: {error:s}",
"download_bad_status_code": "{url:s} returned status code {code:s}",
"command_unknown": "Command '{command:s}' unknown?"
"command_unknown": "Command '{command:s}' unknown ?",
"warn_the_user_about_waiting_lock": "another YunoHost command is running right now, we are waiting for it to finish before running this one",
"warn_the_user_about_waiting_lock_again": "still waiting..."
}

View file

@ -461,6 +461,13 @@ class MoulinetteLock(object):
"""
start_time = time.time()
# for UX reason, we are going to warn the user that we are waiting for
# another yunohost command to end, otherwise the user is very confused
# and don't understand that and think yunohost is broken
# we are going to warn the user after 15 seconds of waiting time then
# after 15*4 seconds, then 15*4*4 seconds...
warning_treshold = 15
logger.debug('acquiring lock...')
while True:
@ -485,6 +492,15 @@ class MoulinetteLock(object):
if self.timeout is not None and (time.time() - start_time) > self.timeout:
raise MoulinetteError('instance_already_running')
# warn the user if it's been too much time since they are waiting
if (time.time() - start_time) > warning_treshold:
if warning_treshold == 15:
logger.warning(moulinette.m18n.g('warn_the_user_about_waiting_lock'))
else:
logger.warning(moulinette.m18n.g('warn_the_user_about_waiting_lock_again'))
warning_treshold *= 4
# Wait before checking again
time.sleep(self.interval)