diff --git a/locales/en.json b/locales/en.json index 9e72df15..78ef4edc 100644 --- a/locales/en.json +++ b/locales/en.json @@ -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" } diff --git a/moulinette/core.py b/moulinette/core.py index 402fbf7f..70cc88c6 100644 --- a/moulinette/core.py +++ b/moulinette/core.py @@ -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