I'm writing a code where users can manage servers (AWS instances) from a browser. The servers take a while to start up and I would like to do a live countdown so users know how long to wait for before all the servers are turned on.
This is my views.py code
def startservers(request, question_id):
inst() #updates all instance status
if instance1[0].state in 'stopped':
instance1[0].start()
if instance2[0].state in 'stopped':
instance2[0].start()
if instance3[0].state in 'stopped':
instance3[0].start()
if instance4[0].state in 'stopped':
instance4[0].start()
for i in range (10,0,-1):
print 'Wait for %d seconds \r' % i,
sys.stdout.flush()
time.sleep(1)
check() #makes sure all instances are running
text1 = 'WebServer-Test %s' % instance1[0].state
text2 = 'Gluster %s' % instance2[0].state
return render(request, 'awsservers/startservers.html', {'webstatus': text1, 'glu1status': text2})
I'm not sure how I should parse the countdown value to
return render(request, 'awsservers/startservers.html', {'webstatus': text1, 'glu1status': text2})
To understand better what I mean by a live countdown, you can just run this section of the code on a console to see the output it produces.
for i in range (10,0,-1):
print 'Wait for %d seconds \r' % i,
sys.stdout.flush()
time.sleep(1)
print '' #without this, next line prints onto the same line as "Wait for.."
print "Server1 running"
print "Server 2 running"
Thanks for the help!
If anyone knows a much better way to put up a countdown, do let me know!