diff --git a/Makefile b/Makefile index 9c0198b0..164ecc64 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ tests_src = tests docs_src = docs/src all_src = $(pkg_src) $(tests_src) -isort = isort -rc $(all_src) +isort = isort $(all_src) autoflake = autoflake -r --remove-all-unused-imports --ignore-init-module-imports $(all_src) black = black $(all_src) flake8 = flake8 $(all_src) diff --git a/fastapi_restful/tasks.py b/fastapi_restful/tasks.py index 0cbe6dd3..de6b9fb7 100644 --- a/fastapi_restful/tasks.py +++ b/fastapi_restful/tasks.py @@ -15,7 +15,7 @@ def repeat_every( *, seconds: float, - wait_first: bool = False, + wait_first: float = None, logger: Optional[logging.Logger] = None, raise_exceptions: bool = False, max_repetitions: Optional[int] = None, @@ -30,8 +30,8 @@ def repeat_every( ---------- seconds: float The number of seconds to wait between repeated calls - wait_first: bool (default False) - If True, the function will wait for a single period before the first call + wait_first: float (default None) + If not None, the function will wait for the given duration before the first call logger: Optional[logging.Logger] (default None) The logger to use to log any exceptions raised by calls to the decorated function. If not provided, exceptions will not be logged by this function (though they may be handled by the event loop). @@ -56,8 +56,8 @@ async def wrapped() -> None: async def loop() -> None: nonlocal repetitions - if wait_first: - await asyncio.sleep(seconds) + if wait_first is not None: + await asyncio.sleep(wait_first) while max_repetitions is None or repetitions < max_repetitions: try: if is_coroutine: diff --git a/scripts/develop.sh b/scripts/develop.sh index 55c119b2..07f234a9 100755 --- a/scripts/develop.sh +++ b/scripts/develop.sh @@ -44,10 +44,9 @@ check_for_python3 check_for_poetry set -x -poetry run pip install -r requirements.txt poetry install { set +x; } 2>/dev/null echo "" -echo "Virtual environment interpreter installed at:" -poetry run python -c "import sys; print(sys.executable)" +echo "Virtual environment interpreter details:" +poetry env info diff --git a/tests/test_tasks.py b/tests/test_tasks.py index 8f2bd654..e7ebfd5d 100644 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -50,12 +50,12 @@ def repeatedly_print_hello() -> None: @pytest.mark.asyncio async def test_repeat_print_wait(capsys: CaptureFixture) -> None: - @repeat_every(seconds=0.07, max_repetitions=3, wait_first=True) - def repeatedly_print_hello() -> None: + @repeat_every(seconds=0.07, max_repetitions=3, wait_first=0.1) + async def repeatedly_print_hello() -> None: print("hello") await repeatedly_print_hello() - await asyncio.sleep(0.1) + await asyncio.sleep(0.15) out, err = capsys.readouterr() assert out == "hello\n" * 1 assert err == ""