def test_get_job(conn):
    job_source_name = "dummy-job-src"
    path = "/data/kpi_2.csv"
    job_type = 'dummy'
    filesize = 1060
    description = {"uri": path}
    description_json = json.dumps(description)

    with closing(conn.cursor()) as cursor:
        job_source_id = add_job_source(cursor, job_source_name, "dummy", '{}')

    enqueue_job(conn, job_type, description_json, filesize, job_source_id)

    conn.commit()

    with closing(conn.cursor()) as cursor:
        job = get_job(cursor)

    conn.commit()

    _, job_type, description, _, _ = job

    eq_(path, json.loads(description)["uri"])

    with closing(conn.cursor()) as cursor:
        job = get_job(cursor)

        eq_(job, None)
def test_waiting_locks(conn):
    job_source_name = "dummy-job-src"
    path = "/data/kpi_2.csv"
    job_type = 'dummy'
    filesize = 1060
    description_json = '{{"uri": "{}"}}'.format(path)

    with closing(conn.cursor()) as cursor:
        datasource = name_to_datasource(cursor, "dummy-src")

        job_source_id = get_job_source(cursor, job_source_name)

        if not job_source_id:
            job_source_id = add_job_source(cursor, job_source_name, "dummy", '{}')

    enqueue_job(conn, job_type, description_json, filesize, job_source_id)

    conn.commit()

    with closing(conn.cursor()) as cursor:
        job = get_job(cursor)

    conn.commit()

    with closing(conn.cursor()) as cursor:
        cursor.execute("select relation::regclass, * FROM pg_locks WHERE NOT GRANTED")

        rows = cursor.fetchall()

    job_id, job_type, description, size, parser_config = job

    eq_(path, json.loads(description)["uri"])
def jobs(conn):
    while True:
        with closing(conn.cursor()) as cursor:
            job = get_job(cursor)

        conn.commit()
        yield job
        sleep(TIMEOUT)