Example #1
0
def test_args_get_create(capsys, tmp_work_dir):
    database.get_connection().execute("DROP TABLE flags")
    with pytest.raises(SystemExit) as e:
        flags.run(["get"])

    assert "--create" in str(e.value)

    flags.run(["get", "--create"])
    stdout, stderr = capsys.readouterr()
    assert stdout == ""
    assert stderr == ""
Example #2
0
def test_args_set_create(capsys, tmp_work_dir, freezer):
    freezer.move_to(TEST_DATESTR)
    database.get_connection().execute("DROP TABLE flags")
    with pytest.raises(SystemExit) as e:
        flags.run(["set", "foo=bar"])

    assert "--create" in str(e.value)

    flags.run(["set", "foo=bar", "--create"])
    stdout, stderr = capsys.readouterr()
    assert stdout == f"foo=bar ({TEST_DATESTR})\n"
    assert stderr == ""
    assert queries.get_flag("foo").value == "bar"
Example #3
0
def main(action, flags, create=False):
    try:
        get_current_flags()
    except sqlite3.OperationalError as e:
        if "no such table" in str(e):
            if create:
                create_table(get_connection(), Flag)
                get_current_flags()
            else:
                sys.exit(
                    "The flags table does not exists. Run command again with --create to create it."
                )

    flags_to_show = []

    if action == "set":
        for name, value in flags:
            flag = set_flag(name, value)
            flags_to_show.append(flag)

    else:  # action == "get"
        if flags:
            for f in flags:
                try:
                    flag = get_flag(f)
                except ValueError:
                    flag = Flag(f, None, None)
                flags_to_show.append(flag)
        else:
            flags_to_show = get_current_flags()

    for flag in flags_to_show:
        print(flag)
Example #4
0
def main():
    """Run the main run loop after starting the sync loop in a thread."""
    # extra space to align with other thread's "sync" label.
    threading.current_thread().name = "run "
    fmt = "{asctime} {threadName} {message} {tags}"
    configure_logging(fmt)
    # ensure db is set up before we start any threads, otherwise if we don't already have
    # a database (which we don't in tests) then threads will race to create the schema
    get_connection()

    try:
        log.info("jobrunner.service started")
        # note: thread name appears in log output, so its nice to keep them all the same length
        start_thread(sync_wrapper, "sync")
        start_thread(record_stats_wrapper, "stat")
        if config.ENABLE_MAINTENANCE_MODE_THREAD:
            start_thread(maintenance_wrapper, "mntn")
        run.main()
    except KeyboardInterrupt:
        log.info("jobrunner.service stopped")
def test_get_flag_no_table_does_not_error(tmp_work_dir):
    conn = get_connection()
    conn.execute("DROP TABLE IF EXISTS flags")
    assert get_flag_value("foo") is None