Skip to content

Instantly share code, notes, and snippets.

@adam-stokes
Created August 23, 2017 15:31
Show Gist options
  • Save adam-stokes/a167ab7e056dbdd129481276e1ddd29c to your computer and use it in GitHub Desktop.
Save adam-stokes/a167ab7e056dbdd129481276e1ddd29c to your computer and use it in GitHub Desktop.
diff --git a/conjureup/controllers/clouds/common.py b/conjureup/controllers/clouds/common.py
index 6bd84ba..367902f 100644
--- a/conjureup/controllers/clouds/common.py
+++ b/conjureup/controllers/clouds/common.py
@@ -1,33 +1,25 @@
import asyncio
-from conjureup import events
+from conjureup import events, utils
from conjureup.models.provider import LocalhostError, LocalhostJSONError
class BaseCloudController:
- retry_count = 0
- max_retry = 20
-
async def _monitor_localhost(self, provider, cb):
""" Checks that localhost/lxd is available and listening,
updates widget accordingly
"""
- if events.LXDAvailable.is_set():
- return
- try:
- await provider.is_server_available()
- events.LXDAvailable.set()
- self.retry_count = 0
- cb()
- except (LocalhostError,
- LocalhostJSONError):
- if self.retry_count == self.max_retry:
- raise
- provider._set_lxd_dir_env()
- self.retry_count += 1
- await asyncio.sleep(2)
- await self._monitor_localhost(provider, cb)
- except FileNotFoundError:
- await asyncio.sleep(5)
- await self._monitor_localhost(provider, cb)
+ cancel_monitor = asyncio.Event()
+ while not cancel_monitor.is_set():
+ try:
+ await provider.is_server_available()
+ events.LXDAvailable.set()
+ cb()
+ except (LocalhostError, LocalhostJSONError):
+ provider._set_lxd_dir_env()
+ await utils.run_with_interrupt(asyncio.sleep(2),
+ self.cancel_monitor)
+ except FileNotFoundError:
+ await utils.run_with_interrupt(asyncio.sleep(5),
+ self.cancel_monitor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment