Пример #1
0
def fillSiteCheckingDaemonInfo(connection, sci):
    now = datetime.datetime.now()
    c_site_checking_daemon_logs = mongo_client.getSiteDBCollection(
        sci["site_id"], "site_checking_daemon_logs")
    last_records = [
        row for row in c_site_checking_daemon_logs.find().sort(
            "created_on", -1).limit(1)
    ]

    sci["site_checking_status_msg"] = ""
    if last_records == []:
        sci["site_checking_status"] = "NEVER_CHECKED"
    else:
        last_record = last_records[0]
        sci["site_checking_last_id"] = last_record["checking_id"]
        if last_record["state"] in ("FAIL", "SUCC"):
            sci["site_checking_status"] = last_record["state"]
            sci["site_checking_since_last"] = convertTimedeltaAsDaysHoursMinutesSeconds(
                now - last_record["ended_on"])
            sci["site_checking_time_spent"] = convertTimedeltaAsDaysHoursMinutesSeconds(
                last_record["ended_on"] - last_record["created_on"])
        elif last_record["state"] == "RUNNING":
            sci["site_checking_status"] = last_record["state"]
            sci["site_checking_time_spent"] = convertTimedeltaAsDaysHoursMinutesSeconds(
                now - last_record["created_on"])
        else:
            sci["site_checking_status"] = "UNKNOWN_STATE"
            sci["site_checking_status_msg"] = "unknown state: %s" % last_record[
                "state"]
Пример #2
0
def getSiteInfos():
    connection = mongo_client.connection
    sites = mongo_client.loadSites()
    now = datetime.datetime.now()
    result = []
    for site in sites:
        sci = {"site_id": site["site_id"], "site_name": site["site_name"], 
               "disabledFlows": site.get("disabledFlows", [])}
        fillSiteCheckingDaemonInfo(connection, sci)
        calculation_records = mongo_client.getSiteDBCollection(site["site_id"], 
                                    "calculation_records")
        records = [row for row in calculation_records.find().sort("begin_datetime", -1).limit(1)]
        if records == []:
            sci["status"] = "NEVER_CALC"
        else:
            record = records[0]
            sci["last_calculation_id"] = record["calculation_id"]
            if record.has_key("end_datetime"):
                if record["is_successful"]:
                    sci["status"] = "SUCCESSFUL"
                else:
                    sci["status"] = "FAILED"
                sci["since_last"] = convertTimedeltaAsDaysHoursMinutesSeconds(now - record["end_datetime"])
                sci["time_spent"] = convertTimedeltaAsDaysHoursMinutesSeconds(record["end_datetime"] - record["begin_datetime"])
                est_next_run = max(record["end_datetime"] + datetime.timedelta(seconds=site["calc_interval"]) - now, 
                                   datetime.timedelta(seconds=0))
                if est_next_run == datetime.timedelta(seconds=0):
                    sci["est_next_run"] = "as soon as possible"
                else:
                    sci["est_next_run"] = convertTimedeltaAsDaysHoursMinutesSeconds(est_next_run)
            else:
                sci["status"] = "RUNNING"
                sci["time_spent"] = convertTimedeltaAsDaysHoursMinutesSeconds(now - record["begin_datetime"])

        manual_calculation_list = connection["tjb-db"]["manual_calculation_list"]
        manual_calculation_request = manual_calculation_list.find_one({"site_id": site["site_id"]})
        if manual_calculation_request is not None:
            request_datetime = manual_calculation_request["request_datetime"]
            sci["request_waiting_time"] = convertTimedeltaAsDaysHoursMinutesSeconds(now - request_datetime)

        c_items = mongo_client.getSiteDBCollection(site["site_id"], "items")
        sci["all_items_count"] = c_items.find().count()
        sci["available_items_count"] = c_items.find({"available": True}).count()

        result.append(sci)

    return result
Пример #3
0
def getSiteInfos():
    connection = mongo_client.connection
    sites = mongo_client.loadSites()
    now = datetime.datetime.now()
    result = []
    for site in sites:
        sci = {"site_id": site["site_id"], "site_name": site["site_name"], 
               "disabledFlows": site.get("disabledFlows", [])}
        fillSiteCheckingDaemonInfo(connection, sci)
        calculation_records = getSiteDBCollection(connection, site["site_id"], 
                                    "calculation_records")
        records = [row for row in calculation_records.find().sort("begin_datetime", -1).limit(1)]
        if records == []:
            sci["status"] = "NEVER_CALC"
        else:
            record = records[0]
            sci["last_calculation_id"] = record["calculation_id"]
            if record.has_key("end_datetime"):
                if record["is_successful"]:
                    sci["status"] = "SUCCESSFUL"
                else:
                    sci["status"] = "FAILED"
                sci["since_last"] = convertTimedeltaAsDaysHoursMinutesSeconds(now - record["end_datetime"])
                sci["time_spent"] = convertTimedeltaAsDaysHoursMinutesSeconds(record["end_datetime"] - record["begin_datetime"])
                est_next_run = max(record["end_datetime"] + datetime.timedelta(seconds=site["calc_interval"]) - now, 
                                   datetime.timedelta(seconds=0))
                if est_next_run == datetime.timedelta(seconds=0):
                    sci["est_next_run"] = "as soon as possible"
                else:
                    sci["est_next_run"] = convertTimedeltaAsDaysHoursMinutesSeconds(est_next_run)
            else:
                sci["status"] = "RUNNING"
                sci["time_spent"] = convertTimedeltaAsDaysHoursMinutesSeconds(now - record["begin_datetime"])

        manual_calculation_list = connection["tjb-db"]["manual_calculation_list"]
        manual_calculation_request = manual_calculation_list.find_one({"site_id": site["site_id"]})
        if manual_calculation_request is not None:
            request_datetime = manual_calculation_request["request_datetime"]
            sci["request_waiting_time"] = convertTimedeltaAsDaysHoursMinutesSeconds(now - request_datetime)

        c_items = getSiteDBCollection(connection, site["site_id"], "items")
        sci["all_items_count"] = c_items.find().count()
        sci["available_items_count"] = c_items.find({"available": True}).count()

        result.append(sci)

    return result
Пример #4
0
def fillSiteCheckingDaemonInfo(connection, sci):
    now = datetime.datetime.now()
    c_site_checking_daemon_logs = mongo_client.getSiteDBCollection(sci["site_id"], "site_checking_daemon_logs")
    last_records = [row for row in c_site_checking_daemon_logs.find().sort("created_on", -1).limit(1)]
    
    sci["site_checking_status_msg"] = ""
    if last_records == []:
        sci["site_checking_status"] = "NEVER_CHECKED"
    else:
        last_record = last_records[0]
        sci["site_checking_last_id"] = last_record["checking_id"]
        if last_record["state"] in ("FAIL", "SUCC"):
            sci["site_checking_status"] = last_record["state"]
            sci["site_checking_since_last"] = convertTimedeltaAsDaysHoursMinutesSeconds(now - last_record["ended_on"])
            sci["site_checking_time_spent"] = convertTimedeltaAsDaysHoursMinutesSeconds(last_record["ended_on"] - last_record["created_on"])
        elif last_record["state"] == "RUNNING":
            sci["site_checking_status"] = last_record["state"]
            sci["site_checking_time_spent"] = convertTimedeltaAsDaysHoursMinutesSeconds(now - last_record["created_on"])
        else:
            sci["site_checking_status"] = "UNKNOWN_STATE"
            sci["site_checking_status_msg"] = "unknown state: %s" % last_record["state"]