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 test_add_job():
    """
    Test if jobs are successfully created in the database.
    """
    datasource_id = 33
    dispatcher_id = 17

    mock_conn = mock.Mock()
    mock_cursor = mock.Mock()
    mock_cursor.fetchone.return_value = (42, )
    mock_conn.cursor.return_value = mock_cursor

    enqueue_job(mock_conn, "/share/file.xml", 23675, datasource_id,
            dispatcher_id)
def test_enqueue_job(conn):
    job_source_name = "dummy-job-src"
    path = "/data/kpi_1.csv"
    job_type = "dummy"
    filesize = 1000
    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)

    with closing(conn.cursor()) as cursor:
        cursor.execute(
            "SELECT j.description "
            "FROM system.job_queue jq "
            "JOIN system.job j ON j.id = jq.job_id")

        eq_(cursor.rowcount, 1)

        job_description, = cursor.fetchone()

    eq_(json.loads(job_description)["uri"], path)
Example #5
0
 def enqueue(self, conn):
     enqueue_job(conn, self.type, json.dumps(self.description), self.size,
                 self.job_source_id)
def enqueue(conn, jobsource_id, description, size):
    enqueue_job(conn, 'dummy', description, size, jobsource_id)
    conn.commit()