-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmicro_controller_script.py
More file actions
21 lines (20 loc) · 982 Bytes
/
micro_controller_script.py
File metadata and controls
21 lines (20 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import subprocess
import datetime
import time
import sys
if __name__ == '__main__':
shutdown_old = 'gcloud compute instances delete soundcloud-pagerank --zone us-central1-f -q'
start_new = 'gcloud compute instances create soundcloud-pagerank --image container-vm-v20140710 --image-project google-containers --zone us-central1-f --machine-type n1-standard-1 --scopes userinfo-email datastore compute-rw --metadata-from-file startup-script=compute_instance_startup_script.sh'
twenty_one_hours = 21 * 60 * 60
while(True):
before = datetime.datetime.now()
print(shutdown_old)
subprocess.call(shutdown_old, shell=True)
print(start_new)
subprocess.call(start_new, shell=True)
time_spent = (datetime.datetime.now() - before).total_seconds()
to_sleep = twenty_one_hours - time_spent
print('starting pagerank took %s seconds. will now sleep for %s seconds before starting again' % (time_spent, to_sleep))
sys.stdout.flush()
sys.stderr.flush()
time.sleep(to_sleep)