Feature: add feedback for cluster create wait (#273)

* add feedback for cluster create wait

* whitespace

* alphasort imports
This commit is contained in:
Jacob Freck 2017-12-12 19:32:54 -08:00 коммит произвёл GitHub
Родитель 6091b1d390
Коммит 46fd44414a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 40 добавлений и 1 удалений

Просмотреть файл

@ -53,6 +53,11 @@ def execute(args: typing.NamedTuple):
print_cluster_conf(cluster_conf)
spinner = utils.Spinner()
log.info("Please wait while your cluster is being provisioned")
spinner.start()
if cluster_conf.custom_scripts:
custom_scripts = []
for custom_script in cluster_conf.custom_scripts:
@ -107,6 +112,8 @@ def execute(args: typing.NamedTuple):
ssh_key=ssh_key
)
spinner.stop()
if cluster_conf.wait:
log.info("Cluster %s created successfully.", cluster.id)
else:

Просмотреть файл

@ -1,7 +1,9 @@
import getpass
import sys
import threading
import time
from typing import List
from subprocess import call
from typing import List
import azure.batch.models as batch_models
import aztk.spark
from aztk import error
@ -219,3 +221,33 @@ def print_batch_exception(batch_exception):
for mesg in batch_exception.error.values:
log.error("%s:\t%s", mesg.key, mesg.value)
log.error("-------------------------------------------")
class Spinner:
busy = False
delay = 0.1
@staticmethod
def spinning_cursor():
while 1:
for cursor in '|/-\\': yield cursor
def __init__(self, delay=None):
self.spinner_generator = self.spinning_cursor()
if delay and float(delay): self.delay = delay
def spinner_task(self):
while self.busy:
sys.stdout.write(next(self.spinner_generator))
sys.stdout.flush()
time.sleep(self.delay)
sys.stdout.write('\b')
sys.stdout.flush()
def start(self):
self.busy = True
threading.Thread(target=self.spinner_task, daemon=True).start()
def stop(self):
self.busy = False
time.sleep(self.delay)