示例#1
0
文件: tmsd.py 项目: bdotdub/norc
 def run_batch(self):
     tasks_to_run = tms_manage.get_tasks_allowed_to_run(end_completed_iterations=True, max_to_return=10)
     num_running_tasks = self.get_num_running_tasks()
     log.debug("tmsd running %s task(s), at least %s task(s) due to run" % (num_running_tasks, len(tasks_to_run)))
     need_resource_types = []
     for (task, iteration) in tasks_to_run:
         if self.__break_tasks_to_run_loop__:
             # some other thread (request_stop) doesn't want me to continue.  Stop here.
             break
         # check that there are currently sufficient resources to prevent
         # erroneously thinking this task can be run when it cannot.
         # There will be occasional cases where race conditions mean a task is not run when
         # it could be, but there are many more cases when this will save threads.
         if type(task) in need_resource_types:
             # A Task of this type already returned unavailable resources; don't check again.
             # This should be an efficiency gain for the running of Tasks to prevent
             # excessive polling of the resources table when there are likely no new resources.
             # log.info("Assuming no resources avail for Task type '%s'" % (type(task)))
             pass
         elif task.resources_available_to_run(self.get_daemon_status().get_region()):
             try:
                 self.start_task(task, iteration)
             except Exception, e:
                 log.error("Could not run Task '%s'" % (task), e)
         else:
             need_resource_types.append(type(task))
示例#2
0
def report_tmsd_status(status_filter, tms_list=None, max_tasks_due_to_run=None):
    include_statuses = DAEMON_STATUS_FILTER_2_STATUS_LIST[status_filter.lower()]
    if tms_list == None:
        matches = tms_models.NorcDaemonStatus.objects.filter()
        tms_list = matches.all()
    tabular = []
    tabular.append(["ID", "Type", "Region", "Host", "PID", "Running", "Success", "Error", "Status", "Started", "Ended"])
    for tds in tms_list:
        if not include_statuses == None and not tds.get_status() in include_statuses:
            continue
        one_row = []
        one_row.append(str(tds.id))
        one_row.append(tds.get_daemon_type())
        one_row.append(tds.get_region().get_name())
        one_row.append(tds.host)
        one_row.append(tds.pid)
        one_row.append(len(tds.get_task_statuses(only_statuses=TASK_STATUS_FILTER_2_STATUS_LIST['running'])))
        one_row.append(len(tds.get_task_statuses(only_statuses=TASK_STATUS_FILTER_2_STATUS_LIST['success'])))
        one_row.append(len(tds.get_task_statuses(only_statuses=TASK_STATUS_FILTER_2_STATUS_LIST['errored'])))
        one_row.append(tds.get_status())
        one_row.append(tds.date_started)
        if tds.is_done():
            one_row.append(tds.date_ended)
        else:
            one_row.append("-")
        tabular.append(one_row)
    
    print >>sys.stdout, "Status as of %s" % (time.strftime("%m/%d/%Y %H:%M:%S"))
    if not max_tasks_due_to_run in (None, 0):
        # This call is currently super expensive when there's lots of Tasks; limit it!
        to_run = tms_manage.get_tasks_allowed_to_run(max_to_return=max_tasks_due_to_run)
        if len(to_run) < max_tasks_due_to_run:
            print >>sys.stdout, "%s Task(s) due to run.\n" % (len(to_run))
        else:
            print >>sys.stdout, "At least %s Task(s) due to run.\n" % (len(to_run))
    
    if len(tabular) == 1:
        print >>sys.stdout, "No %s tms daemons" % (status_filter.upper())
    else:
        print >>sys.stdout, "%s %s tms daemon(s):" % (len(tabular)-1, status_filter.upper())
        formatting.pprint_table(sys.stdout, tabular)
        print >>sys.stdout, ""