Merge pull request #205 from YunoHost/warning_long_lock

Warn the user about long locks for a way better UX
This commit is contained in:
Bram 2019-07-28 18:56:43 +02:00 committed by GitHub
commit 76c8620861
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View file

@ -52,5 +52,8 @@
"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...",
"warn_the_user_that_lock_is_acquired": "the other command just complet, now starting this command"
}

View file

@ -461,6 +461,15 @@ 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:
lock_pids = self._lock_PIDs()
@ -483,9 +492,22 @@ 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)
# we have warned the user that we were waiting, for better UX also them
# that we have stop waiting and that the command is processing now
if warning_treshold != 15:
logger.warning(moulinette.m18n.g('warn_the_user_that_lock_is_acquired'))
logger.debug('lock has been acquired')
self._locked = True