def main(): logging.basicConfig(filename='log.main', level=logging.DEBUG, filemode='w', format='%(asctime)s %(levelname)s %(message)s') logging.info('Loading local configration...') config = Configuration() node_details = config.load_node_main() logging.info('Loading task_manager...') task_manager = TaskManager(node_details) logging.info('Setting up task storage db...') task_storage = TaskStorage() task_manager.start() try: task_manager.add(PingProbe('149.210.184.36', recurrence_time=1, run_on_nodes=['trucks'])) task_manager.add(TraceProbe('8.8.8.8', recurrence_time=3)) task_manager.add(PingProbe('10.0.0.1', run_on_nodes=['miles'])) while True: # Here we can send probes to the task_manager # e.g. task_manager.add(IcmpProbe('127.0.0.1')) db_tasks = task_storage.get_tasks() for task in db_tasks: if node_details['name'] in task['run_on_nodes']: if task['type'] == 'PingProbe': task_manager.add(PingProbe(task['dest_addr'], recurrence_time=task['recurrence_time'], recurrence_count=task['recurrence_count'], run_on_nodes=task['run_on_nodes'])) if task['type'] == 'TraceProbe': task_manager.add(TraceProbe(task['dest_addr'], recurrence_time=task['recurrence_time'], recurrence_count=task['recurrence_count'], run_on_nodes=task['run_on_nodes'])) time.sleep(5) except KeyboardInterrupt: task_manager.stop() print("\nThanks for joining!\n")
else: desc, due, hours = task.split(';') #do this with csv? try: due_dt = datetime.date(*map(int, due.split('-'))) except ValueError: print "[-] Invalid due date in line `{}`!".format(task) exit() if "fixed " == desc[:len("fixed ")]: new_task = FixedTask(desc, int(hours), due_dt) #fake the starttime and endtime else: if due_dt <= datetime.date.today(): print "[!] Task `{}` due on or before today.".format(desc) continue new_task = Task(desc, int(hours), due_dt) try: mgr.add(new_task) except TaskAlreadyExists: print "found duplicate task {}".format(desc) exit() print "[+] {} tasks processed. Attempting to generate schedule.".format(mgr.num_tasks()) prompted = False while MAX_HOURS < 24: try: #we often expect this to fail so using an exception is a little worse than returning None agenda = mgr.calc_agenda(MAX_HOURS, max_days=MAXIMIZE_DAYS,\ work_days=WORK_DAYS, work_today=WORK_TODAY, user_specified_days=USER_SPEC_DAYS) break except NotEnoughTime: #it's a little spamming to print this every time. do it better later if not prompted: