pydocket 0.6.2__tar.gz → 0.6.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pydocket might be problematic. Click here for more details.
- {pydocket-0.6.2 → pydocket-0.6.4}/.cursor/rules/general.mdc +1 -1
- pydocket-0.6.4/.github/workflows/docs.yml +84 -0
- pydocket-0.6.4/PKG-INFO +139 -0
- pydocket-0.6.4/README.md +103 -0
- pydocket-0.6.4/docs/api-reference.md +3 -0
- pydocket-0.6.2/README.md → pydocket-0.6.4/docs/getting-started.md +32 -99
- pydocket-0.6.4/docs/index.md +71 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/examples/common.py +1 -3
- {pydocket-0.6.2 → pydocket-0.6.4}/examples/find_and_flood.py +3 -1
- pydocket-0.6.4/examples/self_perpetuating.py +36 -0
- pydocket-0.6.4/mkdocs.yml +60 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/pyproject.toml +8 -0
- pydocket-0.6.4/src/docket/__main__.py +3 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/src/docket/annotations.py +23 -1
- {pydocket-0.6.2 → pydocket-0.6.4}/src/docket/cli.py +10 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/src/docket/dependencies.py +173 -10
- {pydocket-0.6.2 → pydocket-0.6.4}/src/docket/docket.py +107 -7
- {pydocket-0.6.2 → pydocket-0.6.4}/src/docket/execution.py +43 -4
- {pydocket-0.6.2 → pydocket-0.6.4}/src/docket/instrumentation.py +30 -4
- {pydocket-0.6.2 → pydocket-0.6.4}/src/docket/worker.py +56 -35
- pydocket-0.6.4/tests/test_execution.py +63 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/test_fundamentals.py +88 -2
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/test_instrumentation.py +25 -1
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/test_worker.py +6 -6
- {pydocket-0.6.2 → pydocket-0.6.4}/uv.lock +339 -0
- pydocket-0.6.2/PKG-INFO +0 -388
- pydocket-0.6.2/src/docket/__main__.py +0 -3
- {pydocket-0.6.2 → pydocket-0.6.4}/.cursor/rules/python-style.mdc +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/.github/codecov.yml +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/.github/workflows/chaos.yml +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/.github/workflows/ci.yml +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/.github/workflows/publish.yml +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/.gitignore +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/.pre-commit-config.yaml +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/LICENSE +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/chaos/README.md +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/chaos/__init__.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/chaos/driver.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/chaos/producer.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/chaos/run +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/chaos/tasks.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/examples/__init__.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/src/docket/__init__.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/src/docket/py.typed +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/src/docket/tasks.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/telemetry/.gitignore +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/telemetry/start +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/telemetry/stop +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/__init__.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/cli/__init__.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/cli/conftest.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/cli/test_module.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/cli/test_parsing.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/cli/test_snapshot.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/cli/test_striking.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/cli/test_tasks.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/cli/test_version.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/cli/test_worker.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/cli/test_workers.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/conftest.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/test_dependencies.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/test_docket.py +0 -0
- {pydocket-0.6.2 → pydocket-0.6.4}/tests/test_striking.py +0 -0
|
@@ -6,7 +6,7 @@ alwaysApply: true
|
|
|
6
6
|
|
|
7
7
|
# about docket
|
|
8
8
|
docket is a distributed background task system for Python functions with a focus
|
|
9
|
-
on the scheduling of future work as seamlessly and
|
|
9
|
+
on the scheduling of future work as seamlessly and efficiently as immediate work.
|
|
10
10
|
|
|
11
11
|
docket is built in Python and uses Redis as the message broker and storage system.
|
|
12
12
|
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
name: Documentation
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
pages: write
|
|
14
|
+
id-token: write
|
|
15
|
+
pull-requests: write
|
|
16
|
+
|
|
17
|
+
concurrency:
|
|
18
|
+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
|
19
|
+
cancel-in-progress: true
|
|
20
|
+
|
|
21
|
+
jobs:
|
|
22
|
+
build:
|
|
23
|
+
runs-on: ubuntu-latest
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v4
|
|
26
|
+
with:
|
|
27
|
+
fetch-depth: 0
|
|
28
|
+
|
|
29
|
+
- name: Install uv and set Python version
|
|
30
|
+
uses: astral-sh/setup-uv@v5
|
|
31
|
+
with:
|
|
32
|
+
python-version: "3.12"
|
|
33
|
+
enable-cache: true
|
|
34
|
+
cache-dependency-glob: "pyproject.toml"
|
|
35
|
+
|
|
36
|
+
- name: Install dependencies
|
|
37
|
+
run: uv sync --group docs
|
|
38
|
+
|
|
39
|
+
- name: Build documentation
|
|
40
|
+
run: uv run mkdocs build
|
|
41
|
+
|
|
42
|
+
- name: Upload artifact
|
|
43
|
+
uses: actions/upload-artifact@v4
|
|
44
|
+
id: docs-artifact
|
|
45
|
+
with:
|
|
46
|
+
name: documentation
|
|
47
|
+
path: site/
|
|
48
|
+
|
|
49
|
+
- name: Add or Update Comment
|
|
50
|
+
if: github.event_name == 'pull_request'
|
|
51
|
+
uses: marocchino/sticky-pull-request-comment@v2
|
|
52
|
+
with:
|
|
53
|
+
header: preview
|
|
54
|
+
message: |
|
|
55
|
+
📚 Documentation has been built for this PR!
|
|
56
|
+
|
|
57
|
+
You can download the documentation directly here:
|
|
58
|
+
${{ steps.docs-artifact.outputs.artifact-url }}
|
|
59
|
+
|
|
60
|
+
publish:
|
|
61
|
+
needs: build
|
|
62
|
+
if: github.ref == 'refs/heads/main'
|
|
63
|
+
runs-on: ubuntu-latest
|
|
64
|
+
environment:
|
|
65
|
+
name: github-pages
|
|
66
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
67
|
+
steps:
|
|
68
|
+
- name: Download artifact
|
|
69
|
+
uses: actions/download-artifact@v4
|
|
70
|
+
with:
|
|
71
|
+
name: documentation
|
|
72
|
+
path: site
|
|
73
|
+
|
|
74
|
+
- name: Setup Pages
|
|
75
|
+
uses: actions/configure-pages@v4
|
|
76
|
+
|
|
77
|
+
- name: Upload Pages artifact
|
|
78
|
+
uses: actions/upload-pages-artifact@v3
|
|
79
|
+
with:
|
|
80
|
+
path: site
|
|
81
|
+
|
|
82
|
+
- name: Deploy to GitHub Pages
|
|
83
|
+
id: deployment
|
|
84
|
+
uses: actions/deploy-pages@v4
|
pydocket-0.6.4/PKG-INFO
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pydocket
|
|
3
|
+
Version: 0.6.4
|
|
4
|
+
Summary: A distributed background task system for Python functions
|
|
5
|
+
Project-URL: Homepage, https://github.com/chrisguidry/docket
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/chrisguidry/docket/issues
|
|
7
|
+
Author-email: Chris Guidry <guid@omg.lol>
|
|
8
|
+
License: # Released under MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2025 Chris Guidry.
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Classifier: Development Status :: 4 - Beta
|
|
19
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.12
|
|
26
|
+
Requires-Dist: cloudpickle>=3.1.1
|
|
27
|
+
Requires-Dist: opentelemetry-api>=1.30.0
|
|
28
|
+
Requires-Dist: opentelemetry-exporter-prometheus>=0.51b0
|
|
29
|
+
Requires-Dist: prometheus-client>=0.21.1
|
|
30
|
+
Requires-Dist: python-json-logger>=3.2.1
|
|
31
|
+
Requires-Dist: redis>=4.6
|
|
32
|
+
Requires-Dist: rich>=13.9.4
|
|
33
|
+
Requires-Dist: typer>=0.15.1
|
|
34
|
+
Requires-Dist: uuid7>=0.1.0
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
|
|
37
|
+
Docket is a distributed background task system for Python functions with a focus
|
|
38
|
+
on the scheduling of future work as seamlessly and efficiently as immediate work.
|
|
39
|
+
|
|
40
|
+
[](https://pypi.org/project/pydocket/)
|
|
41
|
+
[](https://pypi.org/project/pydocket/)
|
|
42
|
+
[](https://github.com/chrisguidry/docket/actions/workflows/ci.yml)
|
|
43
|
+
[](https://app.codecov.io/gh/chrisguidry/docket)
|
|
44
|
+
[](https://github.com/chrisguidry/docket/blob/main/LICENSE)
|
|
45
|
+
[](https://chrisguidry.github.io/docket/)
|
|
46
|
+
|
|
47
|
+
## At a glance
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from datetime import datetime, timedelta, timezone
|
|
51
|
+
|
|
52
|
+
from docket import Docket
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
async def greet(name: str, greeting="Hello") -> None:
|
|
56
|
+
print(f"{greeting}, {name} at {datetime.now()}!")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
async with Docket() as docket:
|
|
60
|
+
await docket.add(greet)("Jane")
|
|
61
|
+
|
|
62
|
+
now = datetime.now(timezone.utc)
|
|
63
|
+
soon = now + timedelta(seconds=3)
|
|
64
|
+
await docket.add(greet, when=soon)("John", greeting="Howdy")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from docket import Docket, Worker
|
|
69
|
+
|
|
70
|
+
async with Docket() as docket:
|
|
71
|
+
async with Worker(docket) as worker:
|
|
72
|
+
await worker.run_until_finished()
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
Hello, Jane at 2025-03-05 13:58:21.552644!
|
|
77
|
+
Howdy, John at 2025-03-05 13:58:24.550773!
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Check out our docs for more [details](http://chrisguidry.github.io/docket/),
|
|
81
|
+
[examples](https://chrisguidry.github.io/docket/getting-started/), and the [API
|
|
82
|
+
reference](https://chrisguidry.github.io/docket/api-reference/).
|
|
83
|
+
|
|
84
|
+
## Why `docket`?
|
|
85
|
+
|
|
86
|
+
⚡️ Snappy one-way background task processing without any bloat
|
|
87
|
+
|
|
88
|
+
📅 Schedule immediate or future work seamlessly with the same interface
|
|
89
|
+
|
|
90
|
+
⏭️ Skip problematic tasks or parameters without redeploying
|
|
91
|
+
|
|
92
|
+
🌊 Purpose-built for Redis streams
|
|
93
|
+
|
|
94
|
+
🧩 Fully type-complete and type-aware for your background task functions
|
|
95
|
+
|
|
96
|
+
## Installing `docket`
|
|
97
|
+
|
|
98
|
+
Docket is [available on PyPI](https://pypi.org/project/pydocket/) under the package name
|
|
99
|
+
`pydocket`. It targets Python 3.12 or above.
|
|
100
|
+
|
|
101
|
+
With [`uv`](https://docs.astral.sh/uv/):
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
uv pip install pydocket
|
|
105
|
+
|
|
106
|
+
or
|
|
107
|
+
|
|
108
|
+
uv add pydocket
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
With `pip`:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
pip install pydocket
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Docket requires a [Redis](http://redis.io/) server with Streams support (which was
|
|
118
|
+
introduced in Redis 5.0.0). Docket is tested with Redis 6 and 7.
|
|
119
|
+
|
|
120
|
+
# Hacking on `docket`
|
|
121
|
+
|
|
122
|
+
We use [`uv`](https://docs.astral.sh/uv/) for project management, so getting set up
|
|
123
|
+
should be as simple as cloning the repo and running:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
uv sync
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The to run the test suite:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
pytest
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
We aim to maintain 100% test coverage, which is required for all PRs to `docket`. We
|
|
136
|
+
believe that `docket` should stay small, simple, understandable, and reliable, and that
|
|
137
|
+
begins with testing all the dusty branches and corners. This will give us the
|
|
138
|
+
confidence to upgrade dependencies quickly and to adapt to new versions of Redis over
|
|
139
|
+
time.
|
pydocket-0.6.4/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
Docket is a distributed background task system for Python functions with a focus
|
|
2
|
+
on the scheduling of future work as seamlessly and efficiently as immediate work.
|
|
3
|
+
|
|
4
|
+
[](https://pypi.org/project/pydocket/)
|
|
5
|
+
[](https://pypi.org/project/pydocket/)
|
|
6
|
+
[](https://github.com/chrisguidry/docket/actions/workflows/ci.yml)
|
|
7
|
+
[](https://app.codecov.io/gh/chrisguidry/docket)
|
|
8
|
+
[](https://github.com/chrisguidry/docket/blob/main/LICENSE)
|
|
9
|
+
[](https://chrisguidry.github.io/docket/)
|
|
10
|
+
|
|
11
|
+
## At a glance
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from datetime import datetime, timedelta, timezone
|
|
15
|
+
|
|
16
|
+
from docket import Docket
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
async def greet(name: str, greeting="Hello") -> None:
|
|
20
|
+
print(f"{greeting}, {name} at {datetime.now()}!")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
async with Docket() as docket:
|
|
24
|
+
await docket.add(greet)("Jane")
|
|
25
|
+
|
|
26
|
+
now = datetime.now(timezone.utc)
|
|
27
|
+
soon = now + timedelta(seconds=3)
|
|
28
|
+
await docket.add(greet, when=soon)("John", greeting="Howdy")
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from docket import Docket, Worker
|
|
33
|
+
|
|
34
|
+
async with Docket() as docket:
|
|
35
|
+
async with Worker(docket) as worker:
|
|
36
|
+
await worker.run_until_finished()
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
Hello, Jane at 2025-03-05 13:58:21.552644!
|
|
41
|
+
Howdy, John at 2025-03-05 13:58:24.550773!
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Check out our docs for more [details](http://chrisguidry.github.io/docket/),
|
|
45
|
+
[examples](https://chrisguidry.github.io/docket/getting-started/), and the [API
|
|
46
|
+
reference](https://chrisguidry.github.io/docket/api-reference/).
|
|
47
|
+
|
|
48
|
+
## Why `docket`?
|
|
49
|
+
|
|
50
|
+
⚡️ Snappy one-way background task processing without any bloat
|
|
51
|
+
|
|
52
|
+
📅 Schedule immediate or future work seamlessly with the same interface
|
|
53
|
+
|
|
54
|
+
⏭️ Skip problematic tasks or parameters without redeploying
|
|
55
|
+
|
|
56
|
+
🌊 Purpose-built for Redis streams
|
|
57
|
+
|
|
58
|
+
🧩 Fully type-complete and type-aware for your background task functions
|
|
59
|
+
|
|
60
|
+
## Installing `docket`
|
|
61
|
+
|
|
62
|
+
Docket is [available on PyPI](https://pypi.org/project/pydocket/) under the package name
|
|
63
|
+
`pydocket`. It targets Python 3.12 or above.
|
|
64
|
+
|
|
65
|
+
With [`uv`](https://docs.astral.sh/uv/):
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
uv pip install pydocket
|
|
69
|
+
|
|
70
|
+
or
|
|
71
|
+
|
|
72
|
+
uv add pydocket
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
With `pip`:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install pydocket
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Docket requires a [Redis](http://redis.io/) server with Streams support (which was
|
|
82
|
+
introduced in Redis 5.0.0). Docket is tested with Redis 6 and 7.
|
|
83
|
+
|
|
84
|
+
# Hacking on `docket`
|
|
85
|
+
|
|
86
|
+
We use [`uv`](https://docs.astral.sh/uv/) for project management, so getting set up
|
|
87
|
+
should be as simple as cloning the repo and running:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
uv sync
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The to run the test suite:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pytest
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
We aim to maintain 100% test coverage, which is required for all PRs to `docket`. We
|
|
100
|
+
believe that `docket` should stay small, simple, understandable, and reliable, and that
|
|
101
|
+
begins with testing all the dusty branches and corners. This will give us the
|
|
102
|
+
confidence to upgrade dependencies quickly and to adapt to new versions of Redis over
|
|
103
|
+
time.
|
|
@@ -1,69 +1,14 @@
|
|
|
1
|
-
Docket is a distributed background task system for Python functions with a focus
|
|
2
|
-
on the scheduling of future work as seamlessly and efficiency as immediate work.
|
|
3
|
-
|
|
4
|
-
[](https://pypi.org/project/pydocket/)
|
|
5
|
-
[](https://pypi.org/project/pydocket/)
|
|
6
|
-
[](https://github.com/chrisguidry/docket/actions/workflows/ci.yml)
|
|
7
|
-
[](https://app.codecov.io/gh/chrisguidry/docket)
|
|
8
|
-
[](https://github.com/chrisguidry/docket/blob/main/LICENSE)
|
|
9
|
-
|
|
10
|
-
## At a glance
|
|
11
|
-
|
|
12
|
-
```python
|
|
13
|
-
from datetime import datetime, timedelta, timezone
|
|
14
|
-
|
|
15
|
-
from docket import Docket
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
async def greet(name: str, greeting="Hello") -> None:
|
|
19
|
-
print(f"{greeting}, {name} at {datetime.now()}!")
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
async with Docket() as docket:
|
|
23
|
-
await docket.add(greet)("Jane")
|
|
24
|
-
|
|
25
|
-
now = datetime.now(timezone.utc)
|
|
26
|
-
soon = now + timedelta(seconds=3)
|
|
27
|
-
await docket.add(greet, when=soon)("John", greeting="Howdy")
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
```python
|
|
31
|
-
from docket import Docket, Worker
|
|
32
|
-
|
|
33
|
-
async with Docket() as docket:
|
|
34
|
-
async with Worker(docket) as worker:
|
|
35
|
-
await worker.run_until_finished()
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
Hello, Jane at 2025-03-05 13:58:21.552644!
|
|
40
|
-
Howdy, John at 2025-03-05 13:58:24.550773!
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## Why `docket`?
|
|
44
|
-
|
|
45
|
-
⚡️ Snappy one-way background task processing without any bloat
|
|
46
|
-
|
|
47
|
-
📅 Schedule immediate or future work seamlessly with the same interface
|
|
48
|
-
|
|
49
|
-
⏭️ Skip problematic tasks or parameters without redeploying
|
|
50
|
-
|
|
51
|
-
🌊 Purpose-built for Redis streams
|
|
52
|
-
|
|
53
|
-
🧩 Fully type-complete and type-aware for your background task functions
|
|
54
|
-
|
|
55
|
-
|
|
56
1
|
## Installing `docket`
|
|
57
2
|
|
|
58
3
|
Docket is [available on PyPI](https://pypi.org/project/pydocket/) under the package name
|
|
59
|
-
`pydocket`.
|
|
4
|
+
`pydocket`. It targets Python 3.12 or above.
|
|
60
5
|
|
|
61
6
|
With [`uv`](https://docs.astral.sh/uv/):
|
|
62
7
|
|
|
63
8
|
```bash
|
|
64
9
|
uv pip install pydocket
|
|
65
10
|
|
|
66
|
-
or
|
|
11
|
+
# or
|
|
67
12
|
|
|
68
13
|
uv add pydocket
|
|
69
14
|
```
|
|
@@ -74,14 +19,10 @@ With `pip`:
|
|
|
74
19
|
pip install pydocket
|
|
75
20
|
```
|
|
76
21
|
|
|
77
|
-
Docket requires a [Redis](http://redis.io/) server with Streams support (which was
|
|
78
|
-
introduced in Redis 5.0.0). Docket is tested with Redis 7.
|
|
79
|
-
|
|
80
|
-
|
|
81
22
|
## Creating a `Docket`
|
|
82
23
|
|
|
83
24
|
Each `Docket` should have a name that will be shared across your system, like the name
|
|
84
|
-
of a topic or queue.
|
|
25
|
+
of a topic or queue. By default this is `"docket"`. You can support many separate
|
|
85
26
|
dockets on a single Redis server as long as they have different names.
|
|
86
27
|
|
|
87
28
|
Docket accepts a URL to connect to the Redis server (defaulting to the local
|
|
@@ -96,11 +37,10 @@ async with Docket(name="orders", url="redis://my-redis:6379/0") as docket:
|
|
|
96
37
|
The `name` and `url` together represent a single shared docket of work across all your
|
|
97
38
|
system.
|
|
98
39
|
|
|
99
|
-
|
|
100
40
|
## Scheduling work
|
|
101
41
|
|
|
102
|
-
A `Docket` is the entrypoint to scheduling immediate and future work.
|
|
103
|
-
in the form of `async` functions that return `None`.
|
|
42
|
+
A `Docket` is the entrypoint to scheduling immediate and future work. You define work
|
|
43
|
+
in the form of `async` functions that return `None`. These task functions can accept
|
|
104
44
|
any parameter types, so long as they can be serialized with
|
|
105
45
|
[`cloudpickle`](https://github.com/cloudpipe/cloudpickle).
|
|
106
46
|
|
|
@@ -125,7 +65,7 @@ async with Docket() as docket:
|
|
|
125
65
|
`when: datetime` parameter).
|
|
126
66
|
|
|
127
67
|
All task executions are identified with a `key` that captures the unique essence of that
|
|
128
|
-
piece of work.
|
|
68
|
+
piece of work. By default they are randomly assigned UUIDs, but assigning your own keys
|
|
129
69
|
unlocks many powerful capabilities.
|
|
130
70
|
|
|
131
71
|
```python
|
|
@@ -171,9 +111,9 @@ await docket.cancel("welcome-email-for-12345")
|
|
|
171
111
|
```
|
|
172
112
|
|
|
173
113
|
Tasks may also be called by name, in cases where you can't or don't want to import the
|
|
174
|
-
module that has your tasks.
|
|
114
|
+
module that has your tasks. This may be common in a distributed environment where the
|
|
175
115
|
code of your task system just isn't available, or it requires heavyweight libraries that
|
|
176
|
-
you wouldn't want to import into your web server.
|
|
116
|
+
you wouldn't want to import into your web server. In this case, you will lose the
|
|
177
117
|
type-checking for `.add` and `.replace` calls, but otherwise everything will work as
|
|
178
118
|
it does with the actual function:
|
|
179
119
|
|
|
@@ -187,8 +127,8 @@ large-scale and robust system of background tasks for your application.
|
|
|
187
127
|
## Writing tasks
|
|
188
128
|
|
|
189
129
|
Tasks are any `async` function that takes `cloudpickle`-able parameters, and returns
|
|
190
|
-
`None`.
|
|
191
|
-
whose results aren't used or waited-on by your application.
|
|
130
|
+
`None`. Returning `None` is a strong signal that these are _fire-and-forget_ tasks
|
|
131
|
+
whose results aren't used or waited-on by your application. These are the only kinds of
|
|
192
132
|
tasks that Docket supports.
|
|
193
133
|
|
|
194
134
|
Docket uses a parameter-based dependency and configuration pattern, which has become
|
|
@@ -198,7 +138,7 @@ As such, there is no decorator for tasks.
|
|
|
198
138
|
|
|
199
139
|
A very common requirement for tasks is that they have access to schedule further work
|
|
200
140
|
on their own docket, especially for chains of self-perpetuating tasks to implement
|
|
201
|
-
distributed polling and other periodic systems.
|
|
141
|
+
distributed polling and other periodic systems. One of the first dependencies you may
|
|
202
142
|
look for is the `CurrentDocket`:
|
|
203
143
|
|
|
204
144
|
```python
|
|
@@ -215,8 +155,8 @@ async def poll_for_changes(file: Path, docket: Docket = CurrentDocket()) -> None
|
|
|
215
155
|
```
|
|
216
156
|
|
|
217
157
|
Here the argument to `docket` is an instance of `Docket` with the same name and URL as
|
|
218
|
-
the worker it's running on.
|
|
219
|
-
as well.
|
|
158
|
+
the worker it's running on. You can ask for the `CurrentWorker` and `CurrentExecution`
|
|
159
|
+
as well. Many times it could be useful to have your own task `key` available in order
|
|
220
160
|
to idempotently schedule future work:
|
|
221
161
|
|
|
222
162
|
```python
|
|
@@ -252,7 +192,7 @@ async def faily(retry: Retry = Retry(attempts=5, delay=timedelta(seconds=3))):
|
|
|
252
192
|
```
|
|
253
193
|
|
|
254
194
|
In this case, the task `faily` will run 4 times with a delay of 3 seconds between each
|
|
255
|
-
attempt.
|
|
195
|
+
attempt. If it were to get to 5 attempts, no more would be attempted. This is a
|
|
256
196
|
linear retry, and an `ExponentialRetry` is also available:
|
|
257
197
|
|
|
258
198
|
```python
|
|
@@ -276,13 +216,12 @@ async def faily(
|
|
|
276
216
|
|
|
277
217
|
This would retry in 2, 4, 8, then 16 seconds before that fourth attempt succeeded.
|
|
278
218
|
|
|
279
|
-
|
|
280
219
|
## Running workers
|
|
281
220
|
|
|
282
|
-
You can run as many workers as you like to process the tasks on your docket.
|
|
283
|
-
either run a worker programmatically in Python, or via the CLI.
|
|
221
|
+
You can run as many workers as you like to process the tasks on your docket. You can
|
|
222
|
+
either run a worker programmatically in Python, or via the CLI. Clients using docket
|
|
284
223
|
have the advantage that they are usually passing the task functions, but workers don't
|
|
285
|
-
necessarily know which tasks they are supposed to run.
|
|
224
|
+
necessarily know which tasks they are supposed to run. Docket solves this by allowing
|
|
286
225
|
you to explicitly register tasks.
|
|
287
226
|
|
|
288
227
|
In `my_tasks.py`:
|
|
@@ -324,30 +263,24 @@ to your needs with the `concurrency=` keyword argument or the `--concurrency` CL
|
|
|
324
263
|
option.
|
|
325
264
|
|
|
326
265
|
When a worker crashes ungracefully, any tasks it was currently executing will be held
|
|
327
|
-
for a period of time before being redelivered to other workers.
|
|
328
|
-
time period with `redelivery_timeout=` or `--redelivery-timeout`.
|
|
329
|
-
this to a value higher than the longest task you expect to run.
|
|
266
|
+
for a period of time before being redelivered to other workers. You can control this
|
|
267
|
+
time period with `redelivery_timeout=` or `--redelivery-timeout`. You'd want to set
|
|
268
|
+
this to a value higher than the longest task you expect to run. For queues of very fast
|
|
330
269
|
tasks, a few seconds may be ideal; for long data-processing steps involving large
|
|
331
270
|
amount of data, you may need minutes.
|
|
332
271
|
|
|
272
|
+
## Delivery guarantees
|
|
333
273
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
```bash
|
|
340
|
-
uv sync
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
The to run the test suite:
|
|
274
|
+
Docket provides _at-least-once_ delivery semantics. When a worker picks up a
|
|
275
|
+
task, if it crashes or fails to acknowledge within `redelivery_timeout`, the
|
|
276
|
+
task will be considered unacknowledged and redelivered to another available
|
|
277
|
+
worker. This ensures tasks are not lost but may be delivered more than once. To
|
|
278
|
+
achieve exactly-once processing, design your tasks to be idempotent.
|
|
344
279
|
|
|
345
|
-
|
|
346
|
-
pytest
|
|
347
|
-
```
|
|
280
|
+
## Serialization and cloudpickle usage
|
|
348
281
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
282
|
+
Docket uses `cloudpickle` to serialize task functions and their arguments. This
|
|
283
|
+
allows you to pass nearly any Python object as arguments to a task, but it also
|
|
284
|
+
means that deserializing these arguments can execute arbitrary code. Avoid
|
|
285
|
+
scheduling tasks from untrusted or unauthenticated sources to mitigate security
|
|
286
|
+
risks.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Welcome to docket
|
|
2
|
+
|
|
3
|
+
Docket is a distributed background task system for Python functions with a focus
|
|
4
|
+
on the scheduling of future work as seamlessly and efficiently as immediate work.
|
|
5
|
+
|
|
6
|
+
[](https://pypi.org/project/pydocket/)
|
|
7
|
+
[](https://pypi.org/project/pydocket/)
|
|
8
|
+
[](https://github.com/chrisguidry/docket/actions/workflows/ci.yml)
|
|
9
|
+
[](https://app.codecov.io/gh/chrisguidry/docket)
|
|
10
|
+
[](https://github.com/chrisguidry/docket/blob/main/LICENSE)
|
|
11
|
+
|
|
12
|
+
## At a glance
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
from datetime import datetime, timedelta, timezone
|
|
16
|
+
|
|
17
|
+
from docket import Docket
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
async def greet(name: str, greeting="Hello") -> None:
|
|
21
|
+
print(f"{greeting}, {name} at {datetime.now()}!")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
async with Docket() as docket:
|
|
25
|
+
await docket.add(greet)("Jane")
|
|
26
|
+
|
|
27
|
+
now = datetime.now(timezone.utc)
|
|
28
|
+
soon = now + timedelta(seconds=3)
|
|
29
|
+
await docket.add(greet, when=soon)("John", greeting="Howdy")
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
And in another process, run a worker:
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from docket import Docket, Worker
|
|
36
|
+
|
|
37
|
+
async with Docket() as docket:
|
|
38
|
+
async with Worker(docket) as worker:
|
|
39
|
+
await worker.run_until_finished()
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Which produces:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
Hello, Jane at 2025-03-05 13:58:21.552644!
|
|
46
|
+
Howdy, John at 2025-03-05 13:58:24.550773!
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Why docket?
|
|
50
|
+
|
|
51
|
+
⚡️ Snappy one-way background task processing without any bloat
|
|
52
|
+
|
|
53
|
+
📅 Schedule immediate or future work seamlessly with the same interface
|
|
54
|
+
|
|
55
|
+
⏭️ Skip problematic tasks or parameters without redeploying
|
|
56
|
+
|
|
57
|
+
🌊 Purpose-built for Redis streams
|
|
58
|
+
|
|
59
|
+
🧩 Fully type-complete and type-aware for your background task functions
|
|
60
|
+
|
|
61
|
+
## How It Works
|
|
62
|
+
|
|
63
|
+
docket integrates two modes of task execution:
|
|
64
|
+
|
|
65
|
+
1. **Immediate tasks** are pushed onto a Redis stream and are available to be picked up by any worker.
|
|
66
|
+
2. **Scheduled tasks** are pushed onto a Redis sorted set with a schedule time. A loop within each worker moves scheduled tasks onto the stream when their schedule time has arrived. This move is performed as a Lua script to ensure atomicity.
|
|
67
|
+
|
|
68
|
+
Docket requires a [Redis](http://redis.io/) server with Streams support (which was
|
|
69
|
+
introduced in Redis 5.0.0). Docket is tested with Redis 6 and 7.
|
|
70
|
+
|
|
71
|
+
For more detailed information, check out our [Getting Started](getting-started.md) guide or dive into the [API Reference](api-reference.md).
|
|
@@ -30,7 +30,7 @@ async def run_redis(version: str) -> AsyncGenerator[str, None]:
|
|
|
30
30
|
break
|
|
31
31
|
|
|
32
32
|
url = f"redis://localhost:{port}/0"
|
|
33
|
-
print("***** Redis is running on
|
|
33
|
+
print(f"***** Redis is running on {url} *****")
|
|
34
34
|
try:
|
|
35
35
|
yield url
|
|
36
36
|
finally:
|
|
@@ -43,8 +43,6 @@ async def run_example_workers(workers: int, concurrency: int, tasks: str):
|
|
|
43
43
|
await asyncio.create_subprocess_exec(
|
|
44
44
|
"docket",
|
|
45
45
|
"worker",
|
|
46
|
-
"--name",
|
|
47
|
-
f"worker-{i}",
|
|
48
46
|
"--url",
|
|
49
47
|
redis_url,
|
|
50
48
|
"--tasks",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
+
import random
|
|
2
3
|
from datetime import timedelta
|
|
3
4
|
from logging import Logger, LoggerAdapter
|
|
4
5
|
from typing import Annotated
|
|
@@ -16,7 +17,7 @@ async def find(
|
|
|
16
17
|
perpetual: Perpetual = Perpetual(every=timedelta(seconds=3), automatic=True),
|
|
17
18
|
) -> None:
|
|
18
19
|
for i in range(1, 10 + 1):
|
|
19
|
-
await docket.add(flood
|
|
20
|
+
await docket.add(flood)(i)
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
async def flood(
|
|
@@ -24,6 +25,7 @@ async def flood(
|
|
|
24
25
|
logger: LoggerAdapter[Logger] = TaskLogger(),
|
|
25
26
|
) -> None:
|
|
26
27
|
logger.info("Working on %s", item)
|
|
28
|
+
await asyncio.sleep(random.uniform(0.5, 2))
|
|
27
29
|
|
|
28
30
|
|
|
29
31
|
tasks = [find, flood]
|