def test_overview():
    db = MockDB(view=[MockRow('done', 1),
                      MockRow('todo', 3),
                      MockRow('finished_jobs', 2)])
    simcity.management.set_task_database(db)
    simcity.management.set_job_database(db)
    overview = simcity.overview_total()
    assert_equals(overview['done'], 1)
    assert_equals(overview['finished_jobs'], 2)
    assert_equals(overview['pending_jobs'], 0)
Exemple #2
0
def submit_if_needed(hostname, max_jobs, submitter=None):
    """
    Submit a new job if not enough jobs are already running or queued.

    Host configuration is extracted from an entry in the global config file.
    """
    if not isinstance(max_jobs, Number):
        raise ValueError("Max jobs must be a number")

    num = simcity.overview_total()

    num_jobs = num['active_jobs'] + num['pending_jobs']
    if ((num_jobs < num['todo'] and num_jobs < max_jobs) or
            # active jobs should be scrubbed, some of them are not running
            # anymore
            (num['pending_jobs'] == 0 and num['todo'] > 0 and
             num['locked'] == 0)):
        return submit(hostname, submitter)
    else:
        return None