Skip to content
This repository was archived by the owner on Nov 10, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions fastapi_restful/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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).
Expand All @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions scripts/develop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == ""
Expand Down