示例#1
0
def test_remove(mongodb):
    queue = core4.queue.main.CoreQueue()
    worker = core4.queue.worker.CoreWorker()
    _id = queue.enqueue(core4.queue.helper.job.example.DummyJob)._id
    assert _id is not None
    assert queue.remove_job(_id)
    job = worker.get_next_job()
    assert job is None
    worker.remove_jobs()
    assert 0 == mongodb.core4test.sys.queue.count_documents({})
    assert 1 == mongodb.core4test.sys.journal.count_documents({})
    worker.cleanup()
    assert 0 == mongodb.core4test.sys.lock.count_documents({})
示例#2
0
def test_start_job():
    queue = core4.queue.main.CoreQueue()
    worker = core4.queue.worker.CoreWorker()
    worker.cleanup()
    job = queue.enqueue(core4.queue.helper.job.example.DummyJob)
    assert job.identifier == job._id
    assert job._id is not None
    assert job.wall_time is None
    worker.at = core4.util.node.now()
    worker.start_job(job.serialise())
    while queue.config.sys.queue.count_documents({}) > 0:
        time.sleep(0.5)
    assert queue.config.sys.queue.count_documents({}) == 0
    assert queue.config.sys.journal.count_documents({}) == 1
    job = queue.find_job(job._id)
    assert job.state == "complete"
    print(job.started_at)
    print(job.finished_at)
    print(job.finished_at - job.started_at)
    print(job.runtime)