Beispiel #1
0
def update_status(batch_array_id, job_id, task_id, status, host_name):
    batch_array = BPBatchArray.select(batch_array_id)
    timeout = time.time() + JOB_QUERY_TIMEOUT
    while time.time() < timeout:
        job = BPJob.select(batch_array, job_id)
        if job is not None:
            break
        time.sleep(JOB_QUERY_PAUSE)
    task = BPJobTask.select_by_task_id(job, task_id)
    run = task.batch_array_task.run
    for attempt in range(10):
        try:
            with bpcursor() as cursor:
                BPJobTaskStatus.create(cursor, task, status)
                cmd = run.command
                if status == JS_RUNNING:
                    if host_name is not None:
                        task_host = BPTaskHost.create(cursor, task, host_name,
                                                      run.wants_xvfb)
                        if run.wants_xvfb:
                            cmd = 'xvfb-run -n %d %s' % (task_host.xvfb_server,
                                                         run.command)
                    return cmd
                else:
                    return "OK"
                break
        except OperationalError as e:
            traceback.print_exc()
    else:
        raise
Beispiel #2
0
def update_status(batch_array_id, job_id, task_id, status, host_name):
    batch_array = BPBatchArray.select(batch_array_id)
    timeout = time.time() + JOB_QUERY_TIMEOUT
    while time.time() < timeout:
        job = BPJob.select(batch_array, job_id)
        if job is not None:
            break
        time.sleep(JOB_QUERY_PAUSE)
    task = BPJobTask.select_by_task_id(job, task_id)
    run = task.batch_array_task.run
    for attempt in range(10):
        try:
            with bpcursor() as cursor:
                BPJobTaskStatus.create(cursor, task, status)
                cmd = run.command
                if status == JS_RUNNING:
                    if host_name is not None:
                        task_host = BPTaskHost.create(cursor, task, host_name, run.wants_xvfb)
                        if run.wants_xvfb:
                            cmd = "xvfb-run -n %d %s" % (task_host.xvfb_server, run.command)
                    return cmd
                else:
                    return "OK"
                break
        except OperationalError as e:
            traceback.print_exc()
    else:
        raise
Beispiel #3
0
    if REQUEST_METHOD == RM_PUT:
        data = json.load(sys.stdin)
        action = data[K_ACTION]
        job_id = int(data[JOB_ID])
        batch_array_id = int(data[BATCH_ARRAY_ID])
        if TASK_ID in data and data[TASK_ID] is not None:
            task_id = int(data[TASK_ID])
        host_name = data.get(K_HOST_NAME, None)
        wants_xvfb = data.get(K_WANTS_XVFB, False)
        status = data.get(K_STATUS, JS_SUBMITTED)

        if action == A_CREATE:
            batch_array = BPBatchArray.select(batch_array_id)
            with bpcursor() as cursor:
                job = BPJob.create(cursor, batch_array, job_id)
            print "Content-Type: text/plain"
            print
            print "OK"
        elif action == A_UPDATE:
            cmd = update_status(batch_array_id, job_id, task_id, status,
                                host_name)
            print "Content-Type: text/plain"
            print
            print cmd

        else:
            raise NotImplementedError("Unsupported action: %s" % action)
    else:
        raise NotImplementedError("Unsupported http method: %s" %
                                  REQUEST_METHOD)
Beispiel #4
0
    )

    if REQUEST_METHOD == RM_PUT:
        data = json.load(sys.stdin)
        action = data[K_ACTION]
        job_id = int(data[JOB_ID])
        batch_array_id = int(data[BATCH_ARRAY_ID])
        if TASK_ID in data and data[TASK_ID] is not None:
            task_id = int(data[TASK_ID])
        host_name = data.get(K_HOST_NAME, None)
        wants_xvfb = data.get(K_WANTS_XVFB, False)
        status = data.get(K_STATUS, JS_SUBMITTED)

        if action == A_CREATE:
            batch_array = BPBatchArray.select(batch_array_id)
            with bpcursor() as cursor:
                job = BPJob.create(cursor, batch_array, job_id)
            print "Content-Type: text/plain"
            print
            print "OK"
        elif action == A_UPDATE:
            cmd = update_status(batch_array_id, job_id, task_id, status, host_name)
            print "Content-Type: text/plain"
            print
            print cmd

        else:
            raise NotImplementedError("Unsupported action: %s" % action)
    else:
        raise NotImplementedError("Unsupported http method: %s" % REQUEST_METHOD)
Beispiel #5
0
from RunBatch import BPJob, JS_SUBMITTED, JS_RUNNING
from bpformdata import REQUEST_METHOD, RM_PUT, K_ACTION, A_CREATE, A_READ, \
     A_UPDATE, A_DELETE, JOB_ID, RUN_ID, K_STATUS, K_HOST_NAME, K_WANTS_XVFB

K_JOB_ID = JOB_ID
K_RUN_ID = RUN_ID

if REQUEST_METHOD == RM_PUT:
    data = json.load(sys.stdin)
    action = data[K_ACTION]
    job_id = int(data[K_JOB_ID])
    run_id = int(data[K_RUN_ID])
    host_name = data.get(K_HOST_NAME, None)
    wants_xvfb = data.get(K_WANTS_XVFB, False)
    status = data.get(K_STATUS, JS_SUBMITTED)
    job = BPJob(run_id, job_id)
    if action == A_CREATE:
        job.create(status)
        print "Content-Type: text/plain"
        print
        print "OK"
    elif action == A_UPDATE:
        job.update_status(status)
        print "Content-Type: text/plain"
        print
        if status == JS_RUNNING and host_name is not None:
            xvfb_server = job.create_job_host(host_name, wants_xvfb)
            print xvfb_server
        else:
            print "OK"
    else: