Skip to content

Commit f7780f4

Browse files
authored
Merge pull request fastapiutils#45 from yuval9313/feature/wait-first-float
Feature/wait first float
2 parents 83d54e5 + 2cc1d6d commit f7780f4

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ tests_src = tests
66
docs_src = docs/src
77
all_src = $(pkg_src) $(tests_src)
88

9-
isort = isort -rc $(all_src)
9+
isort = isort $(all_src)
1010
autoflake = autoflake -r --remove-all-unused-imports --ignore-init-module-imports $(all_src)
1111
black = black $(all_src)
1212
flake8 = flake8 $(all_src)

fastapi_restful/tasks.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
def repeat_every(
1616
*,
1717
seconds: float,
18-
wait_first: bool = False,
18+
wait_first: float = None,
1919
logger: Optional[logging.Logger] = None,
2020
raise_exceptions: bool = False,
2121
max_repetitions: Optional[int] = None,
@@ -30,8 +30,8 @@ def repeat_every(
3030
----------
3131
seconds: float
3232
The number of seconds to wait between repeated calls
33-
wait_first: bool (default False)
34-
If True, the function will wait for a single period before the first call
33+
wait_first: float (default None)
34+
If not None, the function will wait for the given duration before the first call
3535
logger: Optional[logging.Logger] (default None)
3636
The logger to use to log any exceptions raised by calls to the decorated function.
3737
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:
5656

5757
async def loop() -> None:
5858
nonlocal repetitions
59-
if wait_first:
60-
await asyncio.sleep(seconds)
59+
if wait_first is not None:
60+
await asyncio.sleep(wait_first)
6161
while max_repetitions is None or repetitions < max_repetitions:
6262
try:
6363
if is_coroutine:

scripts/develop.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ check_for_python3
4444
check_for_poetry
4545

4646
set -x
47-
poetry run pip install -r requirements.txt
4847
poetry install
4948

5049
{ set +x; } 2>/dev/null
5150
echo ""
52-
echo "Virtual environment interpreter installed at:"
53-
poetry run python -c "import sys; print(sys.executable)"
51+
echo "Virtual environment interpreter details:"
52+
poetry env info

tests/test_tasks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def repeatedly_print_hello() -> None:
5050

5151
@pytest.mark.asyncio
5252
async def test_repeat_print_wait(capsys: CaptureFixture) -> None:
53-
@repeat_every(seconds=0.07, max_repetitions=3, wait_first=True)
54-
def repeatedly_print_hello() -> None:
53+
@repeat_every(seconds=0.07, max_repetitions=3, wait_first=0.1)
54+
async def repeatedly_print_hello() -> None:
5555
print("hello")
5656

5757
await repeatedly_print_hello()
58-
await asyncio.sleep(0.1)
58+
await asyncio.sleep(0.15)
5959
out, err = capsys.readouterr()
6060
assert out == "hello\n" * 1
6161
assert err == ""

0 commit comments

Comments
 (0)