Skip to content
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
33 changes: 33 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Lint

on:
pull_request:
branches: [develop]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v5

- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: 3.14

- name: Setup uv
uses: astral-sh/setup-uv@v7

- name: Create virtual environment
run: uv venv .venv && source .venv/bin/activate

- name: Install modules
run: uv sync

- name: Check code style
run: uv run ruff check

- name: Check static typing
run: uv run mypy .
35 changes: 35 additions & 0 deletions .github/workflows/run_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Testing

on:
pull_request:
branches: [develop]

jobs:
run-tests:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
fail-fast: false

steps:
- name: Checkout
uses: actions/checkout@v5

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}

- name: Setup uv
uses: astral-sh/setup-uv@v7

- name: Create virtual environment
run: uv venv .venv && source .venv/bin/activate

- name: Install modules
run: uv sync

- name: Run tests for Python ${{ matrix.python-version }}
run: uv run pytest
5 changes: 4 additions & 1 deletion examples/counter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

url = "redis://localhost"
broker = PubSubBroker(url).with_result_backend(RedisAsyncResultBackend(url))
cancellation_backend = RedisCancellationBackend(url)
cancellation_backend = RedisCancellationBackend(url).with_broker(broker)


@broker.task
Expand All @@ -20,11 +20,14 @@ async def count(up_to: int):
async def main():
await broker.startup()

print("Sending task and waiting 5 seconds...")
task = await count.kiq(5)
await asyncio.sleep(5)

print("Sending task and waiting 2.5 seconds...")
task = await count.kiq(5)
await asyncio.sleep(2.5)
print("Canceling task...")
await cancellation_backend.cancel(task.task_id)

await broker.shutdown()
Expand Down
30 changes: 22 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "taskiq-cancellation"
dynamic = ["version"]
description = 'Task cancellation mechanism for taskiq'
description = 'Task cancellation for taskiq'
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.9"
license = "MIT"
keywords = ["taskiq", "cancellation"]
authors = [{ name = "Alexander Starikov", email = "acherryjam@gmail.com" }]
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = ["taskiq"]
dependencies = ["taskiq", "typing-extensions>=4.13.2"]

[project.optional-dependencies]
redis = ["redis~=3.0"]
Expand All @@ -33,6 +30,10 @@ Documentation = "https://github.com/ACherryJam/taskiq-cancellation#readme"
Issues = "https://github.com/ACherryJam/taskiq-cancellation/issues"
Source = "https://github.com/ACherryJam/taskiq-cancellation"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.version]
path = "src/taskiq_cancellation/__about__.py"

Expand All @@ -41,6 +42,11 @@ extra-dependencies = ["mypy>=1.0.0"]
[tool.hatch.envs.types.scripts]
check = "mypy --install-types --non-interactive {args:src/taskiq_cancellation tests}"

[tool.mypy]
ignore_missing_imports = true
exclude = ["examples"]


[tool.coverage.run]
source_pkgs = ["taskiq_cancellation", "tests"]
branch = true
Expand All @@ -56,3 +62,11 @@ tests = ["tests", "*/taskiq-cancellation/tests"]

[tool.coverage.report]
exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]

[dependency-groups]
dev = [
"mypy>=1.14.1",
"pytest>=8.3.5",
"pytest-asyncio>=0.24.0",
"ruff>=0.14.4",
]
6 changes: 3 additions & 3 deletions src/taskiq_cancellation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .abc import *
from .modular import ModularCancellationBackend
from .abc import CancellationBackend
from .backends.modular import ModularCancellationBackend


__all__ = [
"CancellationBackend",
"ModularCancellationBackend"
]

6 changes: 1 addition & 5 deletions src/taskiq_cancellation/abc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@
from .state_holder import CancellationStateHolder


__all__ = [
"CancellationBackend",
"CancellationNotifier",
"CancellationStateHolder"
]
__all__ = ["CancellationBackend", "CancellationNotifier", "CancellationStateHolder"]
Loading