From 44878d71480f0b20379383e6e51987c00e2cc136 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sat, 20 Jul 2019 04:45:01 +0200 Subject: [PATCH] [ux] add a warning mecanism to inform the user about the current lock --- locales/en.json | 4 +++- moulinette/core.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/locales/en.json b/locales/en.json index 32c9eec8..634a85c1 100644 --- a/locales/en.json +++ b/locales/en.json @@ -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..." } diff --git a/moulinette/core.py b/moulinette/core.py index f10523c5..4de9d0fc 100644 --- a/moulinette/core.py +++ b/moulinette/core.py @@ -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)