Exemplo n.º 1
0
def test_call():
    task = Task()
    cap = cap_exec_rate(func=task, pause_time=0.1)
    cap()
    time.sleep(0.05)
    assert 1 == task.counter
    cap.end()
Exemplo n.º 2
0
def test_init():
    task = Task()
    cap = cap_exec_rate(func=task, pause_time=0.1)
    assert cap.func is task
    assert 0.1 == cap.pause_time
    assert not cap.daemon
    cap.end()
    assert 0 == task.counter
Exemplo n.º 3
0
def test_call_4():
    task = Task()
    cap = cap_exec_rate(func=task, pause_time=10)
    cap()  # executed immediately
    cap()  # not executed
    cap()  # not executed
    cap()  # not executed
    cap()  # executed at the end
    time.sleep(0.05)
    assert 1 == task.counter
    cap.end()
    assert 2 == task.counter
Exemplo n.º 4
0
def request_backup_db():
    """reqeust to take a backup of the DB.
    """
    global _lock
    global _capped_backup_func
    with _lock:
        if not _capped_backup_func:
            pause = current_app.config['ACONDBS_DB_BACKUP_PAUSE']
            _capped_backup_func = cap_exec_rate(
                func=run_flask_backup_db,
                pause_time=pause, daemon=True)
                # Need to set daemon=True. Otherwise
                # threading waits for the thread to join
                # before the function registered in atexist
                # is executed.
    _capped_backup_func()
Exemplo n.º 5
0
def test_daemon():
    task = Task()
    cap = cap_exec_rate(func=task, pause_time=0.1, daemon=True)
    assert cap.daemon
    # end() doesn't need to be called
    assert 0 == task.counter