From 5d1db974841a7c6d7bb60be1a27978f9a3dda579 Mon Sep 17 00:00:00 2001 From: TomBurch Date: Thu, 1 Apr 2021 23:02:18 +0100 Subject: [PATCH 1/4] Change wait_first to a float --- fastapi_restful/tasks.py | 10 +++++----- tests/test_tasks.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) 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/tests/test_tasks.py b/tests/test_tasks.py index 8f2bd654..f1852080 100644 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -50,7 +50,7 @@ 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) + @repeat_every(seconds=0.07, max_repetitions=3, wait_first=0.1) def repeatedly_print_hello() -> None: print("hello") From 3e4c81467d94837ecf547d29e4be1aa299867206 Mon Sep 17 00:00:00 2001 From: Yuval Date: Wed, 7 Apr 2021 22:29:36 +0300 Subject: [PATCH 2/4] Fix tests issue --- tests/test_tasks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_tasks.py b/tests/test_tasks.py index f1852080..e7ebfd5d 100644 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -51,11 +51,11 @@ 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=0.1) - def repeatedly_print_hello() -> None: + 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 == "" From c3d2214dd6b978218cef01551c63698aaad17fe0 Mon Sep 17 00:00:00 2001 From: Yuval Date: Wed, 7 Apr 2021 22:32:44 +0300 Subject: [PATCH 3/4] Fix error of deprecation in the Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 2cc1d6d38f1628944d3e2e5ed1f2c90825f38f42 Mon Sep 17 00:00:00 2001 From: Yuval Date: Wed, 7 Apr 2021 22:33:06 +0300 Subject: [PATCH 4/4] Minor changes to the develop.sh script --- scripts/develop.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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