Пример #1
0
def sql_file_job_and_status(batch_id, sql_file):
    """Return the latest job ID associated with the batch and sql path
    
    batch_id - batch id associated with the submission
    sql_path - path to the sql script submitted
    
    returns latest job or None if not submitted
    """
    batch = RunBatch.select(batch_id)
    run = RunBatch.BPSQLRun.select_by_sql_filename(batch, sql_file)
    if run is None:
        return None, None, None
    result = RunBatch.BPJobTask.select_by_run(run)
    if len(result) == 0:
        return None, None, None
    return run, result[0], RunBatch.BPJobTaskStatus.select_by_job_task(
        job_task)
Пример #2
0
def run_sql_file(batch_id, sql_filename):
    """Use the mysql command line to run the given SQL script
    
    batch_id    - sql_file is associated with this batch
    sql_path    - path and file of the sql script
    queue       - run job on this queue
    email       - who to email when done
    returns the RunBatch.BPJob
    """
    cwd = os.path.dirname(__file__)
    batch = RunBatch.select(batch_id)
    run = RunBatch.BPSQLRun.select_by_sql_filename(batch, sql_filename)
    if run is None:
        sql_path = os.path.join(RunBatch.batch_script_directory(batch),
                                sql_filename)
        cmd = "%s -b %d -i %s" % (os.path.join(
            cwd, "sql_jobs.py"), batch_id, sql_path)
        run = RunBatch.BPSQLRun.create(batch, sql_filename, cmd)
    return RunBatch.run(batch, [run], cwd=cwd)