예제 #1
0
def create_queue(script, max_submit=2):
    driver = Driver(driver_type=QueueDriverEnum.LOCAL_DRIVER, max_running=5)
    job_queue = JobQueue(driver, max_submit=max_submit)

    with open(dummy_config["job_script"], "w") as f:
        f.write(script)

    os.chmod(dummy_config["job_script"],
             stat.S_IRWXU | stat.S_IRWXO | stat.S_IRWXG)
    for i in range(10):
        os.mkdir(dummy_config["run_path"].format(i))
        job = JobQueueNode(
            job_script=dummy_config["job_script"],
            job_name=dummy_config["job_name"].format(i),
            run_path=os.path.realpath(dummy_config["run_path"].format(i)),
            num_cpu=dummy_config["num_cpu"],
            status_file=job_queue.status_file,
            ok_file=job_queue.ok_file,
            exit_file=job_queue.exit_file,
            done_callback_function=dummy_config["ok_callback"],
            exit_callback_function=dummy_config["exit_callback"],
            callback_arguments=[
                {
                    "job_number": i
                },
                os.path.realpath(dummy_config["run_path"].format(i)),
            ])
        job_queue.add_job(job)

    return job_queue
예제 #2
0
def create_queue():
    driver = Driver(driver_type=QueueDriverEnum.LOCAL_DRIVER, max_running=5)
    job_queue = JobQueue(driver)

    with open(dummy_config["job_script"], "w") as f:
        f.write("#!/usr/bin/env python\n"\
                "with open('STATUS', 'w') as f:"\
                "   f.write('finished successfully')"\
                "\n")
    os.chmod(dummy_config["job_script"],
             stat.S_IRWXU | stat.S_IRWXO | stat.S_IRWXG)
    for i in range(10):
        os.mkdir(dummy_config["run_path"].format(i))
        job = JobQueueNode(
            job_script=dummy_config["job_script"],
            job_name=dummy_config["job_name"].format(i),
            run_path=os.path.realpath(dummy_config["run_path"].format(i)),
            num_cpu=dummy_config["num_cpu"],
            status_file=job_queue.status_file,
            ok_file=job_queue.ok_file,
            exit_file=job_queue.exit_file,
            done_callback_function=dummy_config["ok_callback"],
            exit_callback_function=dummy_config["exit_callback"],
            callback_arguments=[
                {
                    "job_number": i
                },
                os.path.realpath(dummy_config["run_path"].format(i)),
            ])
        job_queue.add_job(job)

    return job_queue
예제 #3
0
    def test_stop_long_running(self):
        """
        This test should verify that only the jobs that are has a runtime
        25% longer than the average completed are stopped when
        stop_long_running_jobs is called.
        """
        job_list = [
            MockedJob(JobStatusType.JOB_QUEUE_WAITING) for i in range(10)
        ]

        for i in range(5):
            job_list[i].status = JobStatusType.JOB_QUEUE_DONE
            job_list[i]._start_time = 0
            job_list[i]._end_time = 10

        for i in range(5, 8):
            job_list[i].status = JobStatusType.JOB_QUEUE_RUNNING
            job_list[i]._start_time = 0
            job_list[i]._end_time = 20

        for i in range(8, 10):
            job_list[i].status = JobStatusType.JOB_QUEUE_RUNNING
            job_list[i]._start_time = 0
            job_list[i]._end_time = 5

        # The driver is of no consequence, so resolving it in the c layer is
        # uninteresting and mocked out.
        with mock.patch("res.job_queue.JobQueue._set_driver"):
            queue = JobQueue(mock.MagicMock())

            # We don't need the c layer call here, we only need it added to
            # the queue's job_list.
            with mock.patch("res.job_queue.JobQueue._add_job") as _add_job:
                for idx, job in enumerate(job_list):
                    _add_job.return_value = idx
                    queue.add_job(job, idx)

        queue.stop_long_running_jobs(5)
        queue._transition()

        for i in range(5):
            assert job_list[i].status == JobStatusType.JOB_QUEUE_DONE
            assert queue.snapshot()[i] == str(JobStatusType.JOB_QUEUE_DONE)

        for i in range(5, 8):
            assert job_list[i].status == JobStatusType.JOB_QUEUE_FAILED
            assert queue.snapshot()[i] == str(JobStatusType.JOB_QUEUE_FAILED)

        for i in range(8, 10):
            assert job_list[i].status == JobStatusType.JOB_QUEUE_RUNNING
            assert queue.snapshot()[i] == str(JobStatusType.JOB_QUEUE_RUNNING)