From 147edf10a215923722e557ccb401f3fd97ec14fa Mon Sep 17 00:00:00 2001 From: Arnav Kohli Date: Sat, 14 Mar 2020 09:55:49 +0530 Subject: [PATCH 1/5] Removed unnecessary provison check --- zulip_bots/zulip_bots/run.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/zulip_bots/zulip_bots/run.py b/zulip_bots/zulip_bots/run.py index 0634bf8fd..fd978557e 100755 --- a/zulip_bots/zulip_bots/run.py +++ b/zulip_bots/zulip_bots/run.py @@ -127,9 +127,18 @@ def main() -> None: lib_module = finder.import_module_by_name(args.bot) if lib_module: bot_name = lib_module.__name__ - if args.provision: - print("ERROR: Could not load bot's module for '{}'. Exiting now.") - sys.exit(1) + + # Removed: Not needed as lib_module would have + # been imported during runtime if control + # flow reaches here. Adding any other provision + # check after this would be unnecessary as + # provision_bots require bot_path which + # could not be found, hence result == None + + # if args.provision: + # print("ERROR: Could not load bot's module for '{}'. Exiting now.") + # sys.exit(1) + if lib_module is None: print("ERROR: Could not load bot module. Exiting now.") From aa270ea8d87408777381bb506cbb903b3f915107 Mon Sep 17 00:00:00 2001 From: Arnav Kohli Date: Sat, 14 Mar 2020 10:00:18 +0530 Subject: [PATCH 2/5] Removed unnecessary provision check --- zulip_bots/zulip_bots/run.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/zulip_bots/zulip_bots/run.py b/zulip_bots/zulip_bots/run.py index fd978557e..9539094b1 100755 --- a/zulip_bots/zulip_bots/run.py +++ b/zulip_bots/zulip_bots/run.py @@ -135,11 +135,6 @@ def main() -> None: # provision_bots require bot_path which # could not be found, hence result == None - # if args.provision: - # print("ERROR: Could not load bot's module for '{}'. Exiting now.") - # sys.exit(1) - - if lib_module is None: print("ERROR: Could not load bot module. Exiting now.") sys.exit(1) From b892a17fd26547a90cf7c7ccc8a9dbcdbfbfe25e Mon Sep 17 00:00:00 2001 From: Arnav Kohli Date: Sat, 14 Mar 2020 10:18:53 +0530 Subject: [PATCH 3/5] Fixing trailing whitespaces in comment --- zulip_bots/zulip_bots/run.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zulip_bots/zulip_bots/run.py b/zulip_bots/zulip_bots/run.py index 9539094b1..9e9b1db93 100755 --- a/zulip_bots/zulip_bots/run.py +++ b/zulip_bots/zulip_bots/run.py @@ -131,9 +131,10 @@ def main() -> None: # Removed: Not needed as lib_module would have # been imported during runtime if control # flow reaches here. Adding any other provision - # check after this would be unnecessary as - # provision_bots require bot_path which - # could not be found, hence result == None + # check after this would be unnecessary as + # provision_bots require bot_path which + # could not be found, hence result is None + # and control is here. if lib_module is None: print("ERROR: Could not load bot module. Exiting now.") From 32b317214789b0e8778ced7eae34a2640b00c3ff Mon Sep 17 00:00:00 2001 From: Arnav Kohli Date: Sat, 14 Mar 2020 10:25:03 +0530 Subject: [PATCH 4/5] Added self. before class varible --- zulip/zulip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zulip/zulip/__init__.py b/zulip/zulip/__init__.py index a63fc50e7..21c862fad 100644 --- a/zulip/zulip/__init__.py +++ b/zulip/zulip/__init__.py @@ -95,7 +95,7 @@ def fail(self): # Exponential growth with ratio sqrt(2); compute random delay # between x and 2x where x is growing exponentially delay_scale = int(2 ** (self.number_of_retries / 2.0 - 1)) + 1 - delay = min(delay_scale + random.randint(1, delay_scale), delay_cap) + delay = min(delay_scale + random.randint(1, delay_scale), self.delay_cap) message = "Sleeping for %ss [max %s] before retrying." % (delay, delay_scale * 2) try: logger.warning(message) From 3845ca93e0aeb85ea4b15b3cf7f07cb606c51210 Mon Sep 17 00:00:00 2001 From: Arnav Kohli Date: Mon, 14 Dec 2020 13:56:00 +0530 Subject: [PATCH 5/5] Removed unnecessay provision check, added self. before class variable --- zulip/zulip/__init__.py | 2 +- zulip_bots/zulip_bots/run.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/zulip/zulip/__init__.py b/zulip/zulip/__init__.py index a63fc50e7..21c862fad 100644 --- a/zulip/zulip/__init__.py +++ b/zulip/zulip/__init__.py @@ -95,7 +95,7 @@ def fail(self): # Exponential growth with ratio sqrt(2); compute random delay # between x and 2x where x is growing exponentially delay_scale = int(2 ** (self.number_of_retries / 2.0 - 1)) + 1 - delay = min(delay_scale + random.randint(1, delay_scale), delay_cap) + delay = min(delay_scale + random.randint(1, delay_scale), self.delay_cap) message = "Sleeping for %ss [max %s] before retrying." % (delay, delay_scale * 2) try: logger.warning(message) diff --git a/zulip_bots/zulip_bots/run.py b/zulip_bots/zulip_bots/run.py index 0634bf8fd..9e9b1db93 100755 --- a/zulip_bots/zulip_bots/run.py +++ b/zulip_bots/zulip_bots/run.py @@ -127,9 +127,14 @@ def main() -> None: lib_module = finder.import_module_by_name(args.bot) if lib_module: bot_name = lib_module.__name__ - if args.provision: - print("ERROR: Could not load bot's module for '{}'. Exiting now.") - sys.exit(1) + + # Removed: Not needed as lib_module would have + # been imported during runtime if control + # flow reaches here. Adding any other provision + # check after this would be unnecessary as + # provision_bots require bot_path which + # could not be found, hence result is None + # and control is here. if lib_module is None: print("ERROR: Could not load bot module. Exiting now.")