import time # import paramiko as pk const = GlobalConstants() if __name__ == "__main__": try: while True: instances = ec2.get_ec2_ids_state() active_instances = len([ k for k, v in instances.items() if v == 'stopped' or v == 'running' ]) - 1 # print(instances) watiing_msg_count = int( queue_util.get_msg_count( queue_util.get_queue_url(const.ANALYSIS_QUEUE))) print("Messages in queue:\n" + str(watiing_msg_count)) if watiing_msg_count: stopped_instances = [ k for k, v in instances.items() if v == 'stopped' ] # print(stopped_instances) start_count = min(len(stopped_instances), watiing_msg_count) # print(start_count) create_count = 0 if start_count < watiing_msg_count: create_count = watiing_msg_count - start_count # print(create_count) if start_count > 0: print('restarting %d instances...\n' % int(start_count)) ec2.start_instances(stopped_instances[0:start_count])
from global_constants import GlobalConstants import sys import time # import paramiko as pk const = GlobalConstants() if __name__ == "__main__": unrecoverable = ['shutting-down','terminated'] up = ['pending','running'] down = ['stopping','stopped'] try: while True: instances = ec2.get_ec2_ids_state() active_instances = len([k for k,v in instances.items() if v not in unrecoverable]) - 1 # print(instances) watiing_msg_count = int(queue_util.get_msg_count(queue_util.get_queue_url(const.ANALYSIS_QUEUE))) print("Messages in queue:\n" + str(watiing_msg_count)) if watiing_msg_count: stopped_instances = [k for k,v in instances.items() if v not in unrecoverable and v not in up] # print(stopped_instances) start_count = min(stopped_instances, watiing_msg_count) # print(start_count) create_count = 0 if start_count < watiing_msg_count: create_count = watiing_msg_count - start_count # print(create_count) if start_count>0: print('restarting %d instances...\n' % int(start_count)) ec2.start_instances (stopped_instances [0:start_count]) if create_count>0 and active_instances<const.MAX_WORKERS: