From f88786c2cca0feecba26f1cc0937ea3507cee8b1 Mon Sep 17 00:00:00 2001 From: Luca Date: Sun, 24 Apr 2022 11:00:20 +0100 Subject: [PATCH] release --- .vscode/launch.json | 2 +- fluid/__init__.py | 2 +- fluid/scheduler/consumer.py | 25 +++------ fluid/scheduler/every.py | 9 +++- fluid/webcli.py | 16 ------ poetry.lock | 87 ++++++++++++++----------------- pyproject.toml | 12 ++--- tests/conftest.py | 2 +- tests/scheduler/test_every.py | 11 ++++ tests/scheduler/test_scheduler.py | 26 +++------ 10 files changed, 83 insertions(+), 109 deletions(-) delete mode 100644 fluid/webcli.py create mode 100644 tests/scheduler/test_every.py diff --git a/.vscode/launch.json b/.vscode/launch.json index 5e562d2..f041178 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,7 +12,7 @@ "env": {}, "args": [ "-x", - "tests/scheduler/test_scheduler.py" + "tests/scheduler/test_every.py" ], "debugOptions": [ "RedirectOutput" diff --git a/fluid/__init__.py b/fluid/__init__.py index 7d0806e..cad8d22 100644 --- a/fluid/__init__.py +++ b/fluid/__init__.py @@ -1,2 +1,2 @@ """Reusable server side python modules""" -__version__ = "0.4.2" +__version__ = "0.4.3" diff --git a/fluid/scheduler/consumer.py b/fluid/scheduler/consumer.py index fb6b61f..8be2d60 100644 --- a/fluid/scheduler/consumer.py +++ b/fluid/scheduler/consumer.py @@ -14,7 +14,6 @@ from .constants import TaskPriority, TaskState from .task import Task from .task_run import TaskRun -from .utils import WaitFor ConsumerCallback = Callable[[TaskRun, "TaskManager"], None] AsyncExecutor = Callable[..., Coroutine[Any, Any, None]] @@ -164,14 +163,9 @@ def num_concurrent_tasks_for(self, task_name: str) -> int: """The number of concurrent tasks for a given task_name""" return len(self._concurrent_tasks[task_name]) - async def queue_and_wait(self, task: str, **params: Any) -> TaskRun: - run_id = self.execute(task, **params).id - waitfor = WaitFor(run_id=run_id) - self.register_handler(f"end.{waitfor.run_id}", waitfor) - try: - return await waitfor.waiter - finally: - self.unregister_handler(f"end.{waitfor.run_id}") + async def queue_and_wait(self, task: str, **params: Any) -> Any: + """Execute a task by-passing the broker task queue and wait for result""" + return await self.execute(task, **params).waiter def execute(self, task: str, **params: Any) -> TaskRun: """Execute a Task by-passing the broker task queue""" @@ -210,20 +204,17 @@ async def _consume_tasks(self) -> None: task_run.start = microseconds() task_run.set_state(TaskState.running) task_context = task_run.task.create_context(self, task_run=task_run) - info = await self.broker.get_tasks_info(task_name) - if not info[0].enabled: - task_run.set_state(TaskState.aborted) - task_run.waiter.set_result(None) + self._concurrent_tasks[task_name][task_run.id] = task_run # - elif task_run.task.max_concurrency <= self.num_concurrent_tasks_for( - task_name - ): + if task_run.task.max_concurrency < self.num_concurrent_tasks_for(task_name): task_run.set_state(TaskState.rate_limited) task_run.waiter.set_result(None) + elif not (await self.broker.get_tasks_info(task_name))[0].enabled: + task_run.set_state(TaskState.aborted) + task_run.waiter.set_result(None) # else: task_context.logger.info("start") - self._concurrent_tasks[task_name][task_run.id] = task_run self.dispatch(task_run, "start") try: result = await task_run.task.executor(task_context) diff --git a/fluid/scheduler/every.py b/fluid/scheduler/every.py index 6641420..a3786ef 100644 --- a/fluid/scheduler/every.py +++ b/fluid/scheduler/every.py @@ -5,8 +5,10 @@ class every(Scheduler): - def __init__(self, delta: timedelta): + def __init__(self, delta: timedelta, delay: timedelta = timedelta()): self.delta = delta + self.delay = delay + self._started = None def info(self) -> str: return str(self.delta) @@ -14,6 +16,11 @@ def info(self) -> str: def __call__( self, timestamp: datetime, last_run: Optional[CronRun] = None ) -> Optional[CronRun]: + if not last_run and self.delay: + if not self._started: + self._started = timestamp + if timestamp - self._started < self.delay: + return None year, month, day, hour, minute, second, _, _, _ = timestamp.timetuple() run = CronRun(year, month, day, hour, minute, second) if not last_run or timestamp - last_run.datetime >= self.delta: diff --git a/fluid/webcli.py b/fluid/webcli.py deleted file mode 100644 index 90a6bde..0000000 --- a/fluid/webcli.py +++ /dev/null @@ -1,16 +0,0 @@ -from contextlib import asynccontextmanager - -from aiohttp.test_utils import TestClient, TestServer -from aiohttp.web import Application -from openapi.json import dumps - - -@asynccontextmanager -async def app_cli(app: Application) -> TestClient: - server = TestServer(app) - client = TestClient(server, json_serialize=dumps) - await client.start_server() - try: - yield client - finally: - await client.close() diff --git a/poetry.lock b/poetry.lock index bb97ee6..3f84225 100644 --- a/poetry.lock +++ b/poetry.lock @@ -13,7 +13,7 @@ PyYAML = ">=6.0,<7.0" [[package]] name = "aio-openapi" -version = "2.8.0" +version = "2.9.0" description = "Minimal OpenAPI asynchronous server application" category = "main" optional = false @@ -28,7 +28,7 @@ email-validator = ">=1.1.3,<2.0.0" httptools = ">=0.3.0,<0.4.0" psycopg2-binary = ">=2.9.2,<3.0.0" python-dateutil = ">=2.8.2,<3.0.0" -pytz = ">=2021.3,<2022.0" +pytz = ">=2022.1,<2023.0" PyYAML = ">=6.0,<7.0" simplejson = ">=3.17.5,<4.0.0" SQLAlchemy = ">=1.4.27,<2.0.0" @@ -572,7 +572,7 @@ python-versions = ">=3.7" [[package]] name = "mypy" -version = "0.931" +version = "0.942" description = "Optional static typing for Python" category = "dev" optional = false @@ -586,6 +586,7 @@ typing-extensions = ">=3.10" [package.extras] dmypy = ["psutil (>=4.0)"] python2 = ["typed-ast (>=1.4.0,<2)"] +reports = ["lxml"] [[package]] name = "mypy-extensions" @@ -723,11 +724,11 @@ diagrams = ["railroad-diagrams", "jinja2"] [[package]] name = "pytest" -version = "6.2.5" +version = "7.1.2" description = "pytest: simple powerful testing with Python" category = "dev" optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" [package.dependencies] atomicwrites = {version = ">=1.0", markers = "sys_platform == \"win32\""} @@ -737,10 +738,10 @@ iniconfig = "*" packaging = "*" pluggy = ">=0.12,<2.0" py = ">=1.8.2" -toml = "*" +tomli = ">=1.0.0" [package.extras] -testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"] +testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "xmlschema"] [[package]] name = "pytest-aiohttp" @@ -823,7 +824,7 @@ unidecode = ["Unidecode (>=1.1.1)"] [[package]] name = "pytz" -version = "2021.3" +version = "2022.1" description = "World timezone definitions, modern and historical" category = "main" optional = false @@ -968,14 +969,6 @@ category = "main" optional = false python-versions = "*" -[[package]] -name = "toml" -version = "0.10.2" -description = "Python Library for Tom's Obvious, Minimal Language" -category = "dev" -optional = false -python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" - [[package]] name = "tomli" version = "2.0.1" @@ -1069,7 +1062,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest- [metadata] lock-version = "1.1" python-versions = ">=3.8,<4" -content-hash = "45b1262cff6d25fb67fb12033f717e22f92e76ce9ac2876440e3948c7157cea5" +content-hash = "0453c7a25e7fe07e68568ae31145ec945801c1a888b27a7672d97a8f35890f28" [metadata.files] aio-kong = [ @@ -1077,8 +1070,8 @@ aio-kong = [ {file = "aio_kong-0.9.1-py3-none-any.whl", hash = "sha256:5f1d05edccdee721d35cae13a69e60b63a958d5f4bde7b53f188deb7165c8194"}, ] aio-openapi = [ - {file = "aio-openapi-2.8.0.tar.gz", hash = "sha256:31df1ad9b8ecd5bf5456f4fbe2515590fb7649e9c797213d16bc3bb962519ae0"}, - {file = "aio_openapi-2.8.0-py3-none-any.whl", hash = "sha256:3c57910d913b11cf1a14a2c5d575200eb12fc3de4b059664134a7cf138a6ed0e"}, + {file = "aio-openapi-2.9.0.tar.gz", hash = "sha256:47155ee0cd805c5f24f0617c2be39587ee52da4d60abbecd13ab2b768a2503e0"}, + {file = "aio_openapi-2.9.0-py3-none-any.whl", hash = "sha256:090d5f00a25d143b6d1329353d72b9f2b49bc02afb5e89af2f3b16f963d83e5b"}, ] aiobotocore = [ {file = "aiobotocore-2.2.0.tar.gz", hash = "sha256:71357939c3022670d7bb94833194147a44ebfce24b1643e4e44fedc1ee7349ba"}, @@ -1629,26 +1622,29 @@ multidict = [ {file = "multidict-6.0.2.tar.gz", hash = "sha256:5ff3bd75f38e4c43f1f470f2df7a4d430b821c4ce22be384e1459cb57d6bb013"}, ] mypy = [ - {file = "mypy-0.931-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:3c5b42d0815e15518b1f0990cff7a705805961613e701db60387e6fb663fe78a"}, - {file = "mypy-0.931-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:c89702cac5b302f0c5d33b172d2b55b5df2bede3344a2fbed99ff96bddb2cf00"}, - {file = "mypy-0.931-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:300717a07ad09525401a508ef5d105e6b56646f7942eb92715a1c8d610149714"}, - {file = "mypy-0.931-cp310-cp310-win_amd64.whl", hash = "sha256:7b3f6f557ba4afc7f2ce6d3215d5db279bcf120b3cfd0add20a5d4f4abdae5bc"}, - {file = "mypy-0.931-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:1bf752559797c897cdd2c65f7b60c2b6969ffe458417b8d947b8340cc9cec08d"}, - {file = "mypy-0.931-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:4365c60266b95a3f216a3047f1d8e3f895da6c7402e9e1ddfab96393122cc58d"}, - {file = "mypy-0.931-cp36-cp36m-win_amd64.whl", hash = "sha256:1b65714dc296a7991000b6ee59a35b3f550e0073411ac9d3202f6516621ba66c"}, - {file = "mypy-0.931-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:e839191b8da5b4e5d805f940537efcaa13ea5dd98418f06dc585d2891d228cf0"}, - {file = "mypy-0.931-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:50c7346a46dc76a4ed88f3277d4959de8a2bd0a0fa47fa87a4cde36fe247ac05"}, - {file = "mypy-0.931-cp37-cp37m-win_amd64.whl", hash = "sha256:d8f1ff62f7a879c9fe5917b3f9eb93a79b78aad47b533911b853a757223f72e7"}, - {file = "mypy-0.931-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:f9fe20d0872b26c4bba1c1be02c5340de1019530302cf2dcc85c7f9fc3252ae0"}, - {file = "mypy-0.931-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:1b06268df7eb53a8feea99cbfff77a6e2b205e70bf31743e786678ef87ee8069"}, - {file = "mypy-0.931-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:8c11003aaeaf7cc2d0f1bc101c1cc9454ec4cc9cb825aef3cafff8a5fdf4c799"}, - {file = "mypy-0.931-cp38-cp38-win_amd64.whl", hash = "sha256:d9d2b84b2007cea426e327d2483238f040c49405a6bf4074f605f0156c91a47a"}, - {file = "mypy-0.931-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:ff3bf387c14c805ab1388185dd22d6b210824e164d4bb324b195ff34e322d166"}, - {file = "mypy-0.931-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:5b56154f8c09427bae082b32275a21f500b24d93c88d69a5e82f3978018a0266"}, - {file = "mypy-0.931-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:8ca7f8c4b1584d63c9a0f827c37ba7a47226c19a23a753d52e5b5eddb201afcd"}, - {file = "mypy-0.931-cp39-cp39-win_amd64.whl", hash = "sha256:74f7eccbfd436abe9c352ad9fb65872cc0f1f0a868e9d9c44db0893440f0c697"}, - {file = "mypy-0.931-py3-none-any.whl", hash = "sha256:1171f2e0859cfff2d366da2c7092b06130f232c636a3f7301e3feb8b41f6377d"}, - {file = "mypy-0.931.tar.gz", hash = "sha256:0038b21890867793581e4cb0d810829f5fd4441aa75796b53033af3aa30430ce"}, + {file = "mypy-0.942-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:5bf44840fb43ac4074636fd47ee476d73f0039f4f54e86d7265077dc199be24d"}, + {file = "mypy-0.942-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:dcd955f36e0180258a96f880348fbca54ce092b40fbb4b37372ae3b25a0b0a46"}, + {file = "mypy-0.942-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:6776e5fa22381cc761df53e7496a805801c1a751b27b99a9ff2f0ca848c7eca0"}, + {file = "mypy-0.942-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:edf7237137a1a9330046dbb14796963d734dd740a98d5e144a3eb1d267f5f9ee"}, + {file = "mypy-0.942-cp310-cp310-win_amd64.whl", hash = "sha256:64235137edc16bee6f095aba73be5334677d6f6bdb7fa03cfab90164fa294a17"}, + {file = "mypy-0.942-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:b840cfe89c4ab6386c40300689cd8645fc8d2d5f20101c7f8bd23d15fca14904"}, + {file = "mypy-0.942-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:2b184db8c618c43c3a31b32ff00cd28195d39e9c24e7c3b401f3db7f6e5767f5"}, + {file = "mypy-0.942-cp36-cp36m-win_amd64.whl", hash = "sha256:1a0459c333f00e6a11cbf6b468b870c2b99a906cb72d6eadf3d1d95d38c9352c"}, + {file = "mypy-0.942-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:4c3e497588afccfa4334a9986b56f703e75793133c4be3a02d06a3df16b67a58"}, + {file = "mypy-0.942-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:6f6ad963172152e112b87cc7ec103ba0f2db2f1cd8997237827c052a3903eaa6"}, + {file = "mypy-0.942-cp37-cp37m-win_amd64.whl", hash = "sha256:0e2dd88410937423fba18e57147dd07cd8381291b93d5b1984626f173a26543e"}, + {file = "mypy-0.942-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:246e1aa127d5b78488a4a0594bd95f6d6fb9d63cf08a66dafbff8595d8891f67"}, + {file = "mypy-0.942-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d8d3ba77e56b84cd47a8ee45b62c84b6d80d32383928fe2548c9a124ea0a725c"}, + {file = "mypy-0.942-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:2bc249409a7168d37c658e062e1ab5173300984a2dada2589638568ddc1db02b"}, + {file = "mypy-0.942-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:9521c1265ccaaa1791d2c13582f06facf815f426cd8b07c3a485f486a8ffc1f3"}, + {file = "mypy-0.942-cp38-cp38-win_amd64.whl", hash = "sha256:e865fec858d75b78b4d63266c9aff770ecb6a39dfb6d6b56c47f7f8aba6baba8"}, + {file = "mypy-0.942-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:6ce34a118d1a898f47def970a2042b8af6bdcc01546454726c7dd2171aa6dfca"}, + {file = "mypy-0.942-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:10daab80bc40f84e3f087d896cdb53dc811a9f04eae4b3f95779c26edee89d16"}, + {file = "mypy-0.942-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:3841b5433ff936bff2f4dc8d54cf2cdbfea5d8e88cedfac45c161368e5770ba6"}, + {file = "mypy-0.942-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:6f7106cbf9cc2f403693bf50ed7c9fa5bb3dfa9007b240db3c910929abe2a322"}, + {file = "mypy-0.942-cp39-cp39-win_amd64.whl", hash = "sha256:7742d2c4e46bb5017b51c810283a6a389296cda03df805a4f7869a6f41246534"}, + {file = "mypy-0.942-py3-none-any.whl", hash = "sha256:a1b383fe99678d7402754fe90448d4037f9512ce70c21f8aee3b8bf48ffc51db"}, + {file = "mypy-0.942.tar.gz", hash = "sha256:17e44649fec92e9f82102b48a3bf7b4a5510ad0cd22fa21a104826b5db4903e2"}, ] mypy-extensions = [ {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, @@ -1756,8 +1752,8 @@ pyparsing = [ {file = "pyparsing-3.0.8.tar.gz", hash = "sha256:7bf433498c016c4314268d95df76c81b842a4cb2b276fa3312cfb1e1d85f6954"}, ] pytest = [ - {file = "pytest-6.2.5-py3-none-any.whl", hash = "sha256:7310f8d27bc79ced999e760ca304d69f6ba6c6649c0b60fb0e04a4a77cacc134"}, - {file = "pytest-6.2.5.tar.gz", hash = "sha256:131b36680866a76e6781d13f101efb86cf674ebb9762eb70d3082b6f29889e89"}, + {file = "pytest-7.1.2-py3-none-any.whl", hash = "sha256:13d0e3ccfc2b6e26be000cb6568c832ba67ba32e719443bfe725814d3c42433c"}, + {file = "pytest-7.1.2.tar.gz", hash = "sha256:a06a0425453864a270bc45e71f783330a7428defb4230fb5e6a731fde06ecd45"}, ] pytest-aiohttp = [ {file = "pytest-aiohttp-1.0.4.tar.gz", hash = "sha256:39ff3a0d15484c01d1436cbedad575c6eafbf0f57cdf76fb94994c97b5b8c5a4"}, @@ -1765,7 +1761,6 @@ pytest-aiohttp = [ ] pytest-asyncio = [ {file = "pytest-asyncio-0.18.3.tar.gz", hash = "sha256:7659bdb0a9eb9c6e3ef992eef11a2b3e69697800ad02fb06374a210d85b29f91"}, - {file = "pytest_asyncio-0.18.3-1-py3-none-any.whl", hash = "sha256:16cf40bdf2b4fb7fc8e4b82bd05ce3fbcd454cbf7b92afc445fe299dabb88213"}, {file = "pytest_asyncio-0.18.3-py3-none-any.whl", hash = "sha256:8fafa6c52161addfd41ee7ab35f11836c5a16ec208f93ee388f752bea3493a84"}, ] pytest-cov = [ @@ -1785,8 +1780,8 @@ python-slugify = [ {file = "python_slugify-6.1.1-py2.py3-none-any.whl", hash = "sha256:8c0016b2d74503eb64761821612d58fcfc729493634b1eb0575d8f5b4aa1fbcf"}, ] pytz = [ - {file = "pytz-2021.3-py2.py3-none-any.whl", hash = "sha256:3672058bc3453457b622aab7a1c3bfd5ab0bdae451512f6cf25f64ed37f5b87c"}, - {file = "pytz-2021.3.tar.gz", hash = "sha256:acad2d8b20a1af07d4e4c9d2e9285c5ed9104354062f275f3fcd88dcef4f1326"}, + {file = "pytz-2022.1-py2.py3-none-any.whl", hash = "sha256:e68985985296d9a66a881eb3193b0906246245294a881e7c8afe623866ac6a5c"}, + {file = "pytz-2022.1.tar.gz", hash = "sha256:1e760e2fe6a8163bc0b3d9a19c4f84342afa0a2affebfaa84b01b978a02ecaa7"}, ] pyyaml = [ {file = "PyYAML-6.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d4db7c7aef085872ef65a8fd7d6d09a14ae91f691dec3e87ee5ee0539d516f53"}, @@ -1948,10 +1943,6 @@ text-unidecode = [ {file = "text-unidecode-1.3.tar.gz", hash = "sha256:bad6603bb14d279193107714b288be206cac565dfa49aa5b105294dd5c4aab93"}, {file = "text_unidecode-1.3-py2.py3-none-any.whl", hash = "sha256:1311f10e8b895935241623731c2ba64f4c455287888b18189350b67134a822e8"}, ] -toml = [ - {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, - {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, -] tomli = [ {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, diff --git a/pyproject.toml b/pyproject.toml index 9ea5195..0d52c25 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "aio-fluid" -version = "0.4.2" +version = "0.4.3" description = "Tools for backend python services" license = "BSD" authors = ["Luca "] @@ -34,7 +34,7 @@ classifiers = [ [tool.poetry.dependencies] python = ">=3.8,<4" -aio-openapi = "^2.8.0" +aio-openapi = "^2.9.0" aioredis = "^2.0.0" ujson = "^5.1.0" inflection = "^0.5.1" @@ -45,13 +45,13 @@ python-slugify = {version = "^6.1.0", extras = ["unidecode"]} python-json-logger = "^2.0.2" colorlog = "^6.6.0" aiohttp_cors = "^0.7.0" -aiobotocore = {version = "^2.1.0", extras=["boto3"]} -s3fs = {version = "^2022.2.0"} +aiobotocore = {version = "~2.2.0", extras=["boto3"]} +s3fs = {version = "^2022.3.0"} aio-kong = "^0.9.0" uvloop = "^0.16.0" [tool.poetry.dev-dependencies] -pytest = "^6.2.4" +pytest = "^7.1.2" isort = "^5.9.3" black = "^22.1.0" flake8 = "^4.0.1" @@ -60,7 +60,7 @@ flake8-commas = "^2.0.0" pytest-cov = "^3.0.0" pytest-aiohttp = "^1.0.4" codecov = "^2.1.12" -mypy = "^0.931" +mypy = "^0.942" [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/tests/conftest.py b/tests/conftest.py index beae4da..d28bd63 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,9 +2,9 @@ import os import pytest +from openapi.testing import TestClient, app_cli from fluid.redis import FluidRedis -from fluid.webcli import TestClient, app_cli from .app import AppClient, create_app diff --git a/tests/scheduler/test_every.py b/tests/scheduler/test_every.py new file mode 100644 index 0000000..cba2288 --- /dev/null +++ b/tests/scheduler/test_every.py @@ -0,0 +1,11 @@ +import asyncio +from datetime import datetime, timedelta + +from fluid.scheduler import every + + +async def test_delay(): + scheduler = every(timedelta(seconds=10), delay=timedelta(seconds=0.3)) + assert scheduler(datetime.now()) is None + await asyncio.sleep(0.4) + assert scheduler(datetime.now()) is not None diff --git a/tests/scheduler/test_scheduler.py b/tests/scheduler/test_scheduler.py index e38d389..f77589c 100644 --- a/tests/scheduler/test_scheduler.py +++ b/tests/scheduler/test_scheduler.py @@ -1,6 +1,5 @@ import asyncio import os -from collections import defaultdict from dataclasses import dataclass, field from typing import List @@ -53,30 +52,21 @@ async def test_dummy_execution(task_consumer: TaskConsumer): async def test_dummy_queue(task_consumer: TaskConsumer): - task_run = await task_consumer.queue_and_wait("dummy") - assert task_run.state == TaskState.success.name - assert task_run.end + assert await task_consumer.queue_and_wait("dummy", sleep=0.2) == 0.2 async def test_dummy_error(task_consumer: TaskConsumer): - task_run = await task_consumer.queue_and_wait("dummy", error=True) - assert task_run.state == TaskState.failure.name - assert isinstance(task_run.exception, RuntimeError) + with pytest.raises(RuntimeError): + await task_consumer.queue_and_wait("dummy", error=True) -@pytest.mark.skip("flaky test after upgrade") async def test_dummy_rate_limit(task_consumer: TaskConsumer): - tasks = await asyncio.gather( - task_consumer.queue_and_wait("dummy", sleep=0.5), - task_consumer.queue_and_wait("dummy"), + s1, s2 = await asyncio.gather( + task_consumer.queue_and_wait("dummy", sleep=0.53), + task_consumer.queue_and_wait("dummy", sleep=0.52), ) - states = defaultdict(list) - for task in tasks: - states[task.state].append(task) - assert len(states) == 2 - assert len(states[TaskState.success.name]) == 1 - assert states[TaskState.success.name][0].result == 0.5 - assert len(states[TaskState.rate_limited.name]) == 1 + assert s1 == 0.53 + assert s2 is None assert task_consumer.num_concurrent_tasks == 0