def main():
    settings = startup.read_settings()
    Log.start(settings.debug)
    try:
        Log.note("Summarize by revision {{schema}}", {"schema": settings.perftest.schema})
        talos_alert_revision(settings)
    finally:
        Log.stop()
def main():
    settings = startup.read_settings()
    Log.start(settings.debug)
    try:
        for repo in settings.param.repos:
            with DB(settings.database) as db:
                try:
                    pull_repo(repo)

                    #GET LATEST DATE
                    existing_range = db.query("""
                        SELECT
                            max(`date`) `max`,
                            min(`date`) `min`,
                            min(revision) min_rev,
                            max(revision) max_rev
                        FROM
                            changesets
                        WHERE
                            repo={{repo}}
                    """, {"repo": repo.name})[0]

                    ranges = struct.wrap([
                        {"min": nvl(existing_range.max, CNV.milli2datetime(0)) + timedelta(0, 1)},
                        {"max": existing_range.min}
                    ])

                    for r in ranges:
                        for g, docs in Q.groupby(get_changesets(date_range=r, repo=repo), size=100):
                            for doc in docs:
                                doc.file_changes = None
                                doc.file_adds = None
                                doc.file_dels = None
                                doc.description = doc.description[0:16000]

                            db.insert_list("changesets", docs)
                            db.flush()

                    missing_revisions = sql.find_holes(db, "changesets", "revision", {"term":{"repo":repo.name}}, {"min": 0, "max": existing_range.max_rev + 1})
                    for _range in missing_revisions:
                        for g, docs in Q.groupby(get_changesets(revision_range=_range, repo=repo), size=100):
                            for doc in docs:
                                doc.file_changes = None
                                doc.file_adds = None
                                doc.file_dels = None
                                doc.description = doc.description[0:16000]

                            db.insert_list("changesets", docs)
                            db.flush()



                except Exception, e:
                    Log.warning("Failure to pull from {{repo.name}}", {"repo":repo}, e)
    finally:
        Log.stop()
def settings(request):
    settings = startup.read_settings(filename="test_settings.json")
    Log.start(settings.debug)
    testing.make_test_database(settings)

    def fin():
        Log.stop()

    request.addfinalizer(fin)

    return settings
def main():
    settings = startup.read_settings("test_settings.json")
    Log.start(settings.debug)
    try:
        test_a_fail_b_pass()
        test_a_pass_b_fail()
        test_a_fail_b_fail()
        test_safe_combinations()
        Log.note("SUCCESS!!")
    finally:
        Log.stop()
def main():
    settings = startup.read_settings()
    Log.start(settings.debug)
    try:
        Log.note("Running email using schema {{schema}}", {"schema": settings.perftest.schema})
        with DB(settings.alerts) as db:
            email_send(
                db=db,
                emailer=Emailer(settings.email),
                debug=nvl(settings.debug, False)
            )
    except Exception, e:
        Log.warning("Failure to send emails", cause=e)
def main():
    try:
        settings = startup.read_settings()
        Log.start(settings.debug)

        DB.execute_file(settings.database, settings.sql.rstrip("/")+"/util/util.sql")
        DB.execute_file(settings.database, settings.sql.rstrip("/")+"/util/debug.sql")
        DB.execute_file(settings.database, settings.sql.rstrip("/")+"/util/cnv.sql")
        DB.execute_file(settings.database, settings.sql.rstrip("/")+"/util/string.sql")
        DB.execute_file(settings.database, settings.sql.rstrip("/")+"/util/math.sql")
        DB.execute_file(settings.database, settings.sql.rstrip("/")+"/util/json.sql")
        DB.execute_file(settings.database, settings.sql.rstrip("/")+"/util/mail.sql")
        DB.execute_file(settings.database, settings.sql.rstrip("/")+"/alerts.sql")
        Log.note("DB setup complete")
    except Exception, e:
        Log.warning("Failure to setup DB", cause=e)
def main():
    settings = startup.read_settings(defs=[{
        "name": ["--restart", "--reset", "--redo"],
        "help": "use this to recalc alerts",
        "action": "store_true",
        "dest": "restart"
    }])
    Log.start(settings.debug)
    try:
        with startup.SingleInstance(flavor_id=settings.args.filename):
            Log.note("Finding exceptions in index {{index_name}}", {"index_name": settings.query["from"].name})

            with ESQuery(ElasticSearch(settings.query["from"])) as qb:
                qb.addDimension(CNV.JSON2object(File(settings.dimension.filename).read()))

                with DB(settings.alerts) as alerts_db:
                    alert_sustained_median(
                        settings,
                        qb,
                        alerts_db
                    )
    except Exception, e:
        Log.warning("Failure to find sustained_median exceptions", e)
            #I HOPE I CAN SEND ARRAYS OF NUMBERS
            db.execute(
                "UPDATE alerts SET last_sent={{time}} WHERE {{where}}", {
                    "time": datetime.utcnow(),
                    "where": esfilter2sqlwhere(db, {"terms": {"id": Q.select(new_alerts, "alert_id")}})
                })

    except Exception, e:
        Log.error("Could not send alerts", e)




if __name__ == '__main__':
    settings = startup.read_settings()
    Log.start(settings.debug)

    try:
        Log.note("Running alerts off of schema {{schema}}", {"schema": settings.perftest.schema})

        with DB(settings.alerts) as db:
            send_alerts(
                settings=settings,
                db=db
            )
    except Exception, e:
        Log.warning("Failure to run alerts", cause=e)
    finally:
        Log.stop()