grindsharp 0.1.0__tar.gz → 0.1.1__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.
- {grindsharp-0.1.0 → grindsharp-0.1.1}/PKG-INFO +16 -3
- grindsharp-0.1.0/src/grindsharp.egg-info/PKG-INFO → grindsharp-0.1.1/README.md +10 -21
- {grindsharp-0.1.0 → grindsharp-0.1.1}/pyproject.toml +50 -45
- {grindsharp-0.1.0 → grindsharp-0.1.1}/src/grindsharp/__init__.py +23 -23
- {grindsharp-0.1.0 → grindsharp-0.1.1}/src/grindsharp/app.py +1 -2
- {grindsharp-0.1.0 → grindsharp-0.1.1}/src/grindsharp/cli.py +11 -3
- {grindsharp-0.1.0 → grindsharp-0.1.1}/src/grindsharp/redis_store.py +0 -1
- {grindsharp-0.1.0 → grindsharp-0.1.1}/src/grindsharp/worker.py +209 -142
- grindsharp-0.1.0/README.md → grindsharp-0.1.1/src/grindsharp.egg-info/PKG-INFO +217 -183
- {grindsharp-0.1.0 → grindsharp-0.1.1}/tests/test_grindsharp.py +313 -274
- {grindsharp-0.1.0 → grindsharp-0.1.1}/LICENSE +0 -0
- {grindsharp-0.1.0 → grindsharp-0.1.1}/setup.cfg +0 -0
- {grindsharp-0.1.0 → grindsharp-0.1.1}/src/grindsharp/__main__.py +0 -0
- {grindsharp-0.1.0 → grindsharp-0.1.1}/src/grindsharp/errors.py +0 -0
- {grindsharp-0.1.0 → grindsharp-0.1.1}/src/grindsharp/models.py +0 -0
- {grindsharp-0.1.0 → grindsharp-0.1.1}/src/grindsharp/postgres.py +0 -0
- {grindsharp-0.1.0 → grindsharp-0.1.1}/src/grindsharp/py.typed +0 -0
- {grindsharp-0.1.0 → grindsharp-0.1.1}/src/grindsharp/store.py +0 -0
- {grindsharp-0.1.0 → grindsharp-0.1.1}/src/grindsharp.egg-info/SOURCES.txt +0 -0
- {grindsharp-0.1.0 → grindsharp-0.1.1}/src/grindsharp.egg-info/dependency_links.txt +0 -0
- {grindsharp-0.1.0 → grindsharp-0.1.1}/src/grindsharp.egg-info/entry_points.txt +0 -0
- {grindsharp-0.1.0 → grindsharp-0.1.1}/src/grindsharp.egg-info/requires.txt +0 -0
- {grindsharp-0.1.0 → grindsharp-0.1.1}/src/grindsharp.egg-info/top_level.txt +0 -0
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: grindsharp
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: SQLite-first background jobs for Python. No Redis required.
|
|
5
|
-
Author:
|
|
5
|
+
Author: GT47THY
|
|
6
6
|
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://pypi.org/project/grindsharp/
|
|
8
|
+
Project-URL: Repository, https://pypi.org/project/grindsharp/
|
|
9
|
+
Project-URL: Issues, https://pypi.org/project/grindsharp/
|
|
7
10
|
Keywords: background-jobs,queue,sqlite,worker,tasks,scheduler
|
|
8
|
-
Classifier: Development Status ::
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
12
|
Classifier: Intended Audience :: Developers
|
|
10
13
|
Classifier: License :: OSI Approved :: MIT License
|
|
11
14
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -124,6 +127,7 @@ grindsharp worker --app app:jobs --db jobs.db
|
|
|
124
127
|
- **Durable:** jobs are saved in SQLite, so they survive app restarts.
|
|
125
128
|
- **At-least-once:** if a worker crashes mid-job, that job might run again. So write tasks like they may be retried (because they might).
|
|
126
129
|
- **Retries:** failed jobs retry with backoff (`retry_backoff_seconds * attempt`).
|
|
130
|
+
- **Timeouts:** if a task sets `timeout_seconds`, the worker marks it as timed out/failed when that limit passes (then it retries or goes dead like any other failure). A stuck Python thread may still keep running in-process, so task code should still respect timeouts/cancellation where it can.
|
|
127
131
|
- **Dead jobs:** when retries run out, the job gets marked `dead` and keeps the last error so you can see what happened.
|
|
128
132
|
- **Crash recovery:** stale `running` jobs get moved back to `pending` after a timeout.
|
|
129
133
|
|
|
@@ -136,6 +140,9 @@ grindsharp worker --app jobs:jobs --db jobs.db --concurrency 4
|
|
|
136
140
|
# process one job then exit (useful for debugging)
|
|
137
141
|
grindsharp worker --app jobs:jobs --db jobs.db --once
|
|
138
142
|
|
|
143
|
+
# give the worker a stable name / tune stale-job recovery
|
|
144
|
+
grindsharp worker --app jobs:jobs --db jobs.db --worker-name worker-1 --stale-timeout-seconds 300
|
|
145
|
+
|
|
139
146
|
# inspect jobs
|
|
140
147
|
grindsharp --db jobs.db list --status pending --limit 20
|
|
141
148
|
grindsharp --db jobs.db stats
|
|
@@ -147,6 +154,8 @@ grindsharp --db jobs.db retry <job_id>
|
|
|
147
154
|
grindsharp --db jobs.db purge --status succeeded --older-than-seconds 86400
|
|
148
155
|
```
|
|
149
156
|
|
|
157
|
+
When you run `grindsharp worker` from the CLI, it handles SIGINT/SIGTERM and stops gracefully.
|
|
158
|
+
|
|
150
159
|
## When Grindsharp is a good fit
|
|
151
160
|
|
|
152
161
|
Use it when you want background jobs without extra infrastructure:
|
|
@@ -186,6 +195,10 @@ These adapters keep the same `Jobs`/`Worker` API. Use SQLite for simple/local ap
|
|
|
186
195
|
- Payloads must be **JSON-serializable**.
|
|
187
196
|
- SQLite makes this a great fit for **small/medium single-node apps**. When you need distributed throughput, grow to a Postgres/Redis-style queue.
|
|
188
197
|
|
|
198
|
+
## Version 0.1.1
|
|
199
|
+
|
|
200
|
+
Small production-hardening pass: worker timeout enforcement, graceful SIGINT/SIGTERM shutdown in the CLI worker, CI/release workflows, and tighter packaging/lint/test setup.
|
|
201
|
+
|
|
189
202
|
## Development
|
|
190
203
|
|
|
191
204
|
```bash
|
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: grindsharp
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: SQLite-first background jobs for Python. No Redis required.
|
|
5
|
-
Author: REDX Contributors
|
|
6
|
-
License: MIT
|
|
7
|
-
Keywords: background-jobs,queue,sqlite,worker,tasks,scheduler
|
|
8
|
-
Classifier: Development Status :: 3 - Alpha
|
|
9
|
-
Classifier: Intended Audience :: Developers
|
|
10
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
-
Classifier: Topic :: Software Development :: Libraries
|
|
14
|
-
Classifier: Typing :: Typed
|
|
15
|
-
Requires-Python: >=3.9
|
|
16
|
-
Description-Content-Type: text/markdown
|
|
17
|
-
License-File: LICENSE
|
|
18
|
-
Provides-Extra: dev
|
|
19
|
-
Requires-Dist: pytest>=7.4; extra == "dev"
|
|
20
|
-
Dynamic: license-file
|
|
21
|
-
|
|
22
1
|
# Grindsharp
|
|
23
2
|
|
|
24
3
|
Most Python apps eventually need to do stuff in the background: send an email, process an upload, call a webhook, generate a report, retry something that flopped.
|
|
@@ -124,6 +103,7 @@ grindsharp worker --app app:jobs --db jobs.db
|
|
|
124
103
|
- **Durable:** jobs are saved in SQLite, so they survive app restarts.
|
|
125
104
|
- **At-least-once:** if a worker crashes mid-job, that job might run again. So write tasks like they may be retried (because they might).
|
|
126
105
|
- **Retries:** failed jobs retry with backoff (`retry_backoff_seconds * attempt`).
|
|
106
|
+
- **Timeouts:** if a task sets `timeout_seconds`, the worker marks it as timed out/failed when that limit passes (then it retries or goes dead like any other failure). A stuck Python thread may still keep running in-process, so task code should still respect timeouts/cancellation where it can.
|
|
127
107
|
- **Dead jobs:** when retries run out, the job gets marked `dead` and keeps the last error so you can see what happened.
|
|
128
108
|
- **Crash recovery:** stale `running` jobs get moved back to `pending` after a timeout.
|
|
129
109
|
|
|
@@ -136,6 +116,9 @@ grindsharp worker --app jobs:jobs --db jobs.db --concurrency 4
|
|
|
136
116
|
# process one job then exit (useful for debugging)
|
|
137
117
|
grindsharp worker --app jobs:jobs --db jobs.db --once
|
|
138
118
|
|
|
119
|
+
# give the worker a stable name / tune stale-job recovery
|
|
120
|
+
grindsharp worker --app jobs:jobs --db jobs.db --worker-name worker-1 --stale-timeout-seconds 300
|
|
121
|
+
|
|
139
122
|
# inspect jobs
|
|
140
123
|
grindsharp --db jobs.db list --status pending --limit 20
|
|
141
124
|
grindsharp --db jobs.db stats
|
|
@@ -147,6 +130,8 @@ grindsharp --db jobs.db retry <job_id>
|
|
|
147
130
|
grindsharp --db jobs.db purge --status succeeded --older-than-seconds 86400
|
|
148
131
|
```
|
|
149
132
|
|
|
133
|
+
When you run `grindsharp worker` from the CLI, it handles SIGINT/SIGTERM and stops gracefully.
|
|
134
|
+
|
|
150
135
|
## When Grindsharp is a good fit
|
|
151
136
|
|
|
152
137
|
Use it when you want background jobs without extra infrastructure:
|
|
@@ -186,6 +171,10 @@ These adapters keep the same `Jobs`/`Worker` API. Use SQLite for simple/local ap
|
|
|
186
171
|
- Payloads must be **JSON-serializable**.
|
|
187
172
|
- SQLite makes this a great fit for **small/medium single-node apps**. When you need distributed throughput, grow to a Postgres/Redis-style queue.
|
|
188
173
|
|
|
174
|
+
## Version 0.1.1
|
|
175
|
+
|
|
176
|
+
Small production-hardening pass: worker timeout enforcement, graceful SIGINT/SIGTERM shutdown in the CLI worker, CI/release workflows, and tighter packaging/lint/test setup.
|
|
177
|
+
|
|
189
178
|
## Development
|
|
190
179
|
|
|
191
180
|
```bash
|
|
@@ -1,45 +1,50 @@
|
|
|
1
|
-
[build-system]
|
|
2
|
-
requires = ["setuptools>=61.0"]
|
|
3
|
-
build-backend = "setuptools.build_meta"
|
|
4
|
-
|
|
5
|
-
[project]
|
|
6
|
-
name = "grindsharp"
|
|
7
|
-
version = "0.1.
|
|
8
|
-
description = "SQLite-first background jobs for Python. No Redis required."
|
|
9
|
-
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.9"
|
|
11
|
-
license = { text = "MIT" }
|
|
12
|
-
authors = [{ name = "
|
|
13
|
-
dependencies = []
|
|
14
|
-
keywords = ["background-jobs", "queue", "sqlite", "worker", "tasks", "scheduler"]
|
|
15
|
-
classifiers = [
|
|
16
|
-
"Development Status ::
|
|
17
|
-
"Intended Audience :: Developers",
|
|
18
|
-
"License :: OSI Approved :: MIT License",
|
|
19
|
-
"Programming Language :: Python :: 3",
|
|
20
|
-
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
-
"Topic :: Software Development :: Libraries",
|
|
22
|
-
"Typing :: Typed",
|
|
23
|
-
]
|
|
24
|
-
|
|
25
|
-
[project.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
[
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
[
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "grindsharp"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "SQLite-first background jobs for Python. No Redis required."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "GT47THY" }]
|
|
13
|
+
dependencies = []
|
|
14
|
+
keywords = ["background-jobs", "queue", "sqlite", "worker", "tasks", "scheduler"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Topic :: Software Development :: Libraries",
|
|
22
|
+
"Typing :: Typed",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.urls]
|
|
26
|
+
Homepage = "https://pypi.org/project/grindsharp/"
|
|
27
|
+
Repository = "https://pypi.org/project/grindsharp/"
|
|
28
|
+
Issues = "https://pypi.org/project/grindsharp/"
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
dev = ["pytest>=7.4"]
|
|
32
|
+
|
|
33
|
+
[project.scripts]
|
|
34
|
+
grindsharp = "grindsharp.cli:main"
|
|
35
|
+
|
|
36
|
+
[tool.setuptools]
|
|
37
|
+
package-dir = {"" = "src"}
|
|
38
|
+
include-package-data = true
|
|
39
|
+
|
|
40
|
+
[tool.setuptools.packages.find]
|
|
41
|
+
where = ["src"]
|
|
42
|
+
include = ["grindsharp*"]
|
|
43
|
+
|
|
44
|
+
[tool.setuptools.package-data]
|
|
45
|
+
grindsharp = ["py.typed"]
|
|
46
|
+
|
|
47
|
+
[tool.pytest.ini_options]
|
|
48
|
+
testpaths = ["tests"]
|
|
49
|
+
pythonpath = ["src"]
|
|
50
|
+
addopts = "-ra --strict-markers"
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
from .app import Jobs, Task
|
|
2
|
-
from .errors import DuplicateJob, InvalidTask, GrindsharpError, TaskNotFound
|
|
3
|
-
from .models import Job
|
|
4
|
-
from .store import SQLiteJobStore
|
|
5
|
-
from .postgres import PostgresJobStore
|
|
6
|
-
from .redis_store import RedisJobStore
|
|
7
|
-
from .worker import Worker
|
|
8
|
-
|
|
9
|
-
__all__ = [
|
|
10
|
-
"Jobs",
|
|
11
|
-
"Task",
|
|
12
|
-
"Worker",
|
|
13
|
-
"Job",
|
|
14
|
-
"SQLiteJobStore",
|
|
15
|
-
"PostgresJobStore",
|
|
16
|
-
"RedisJobStore",
|
|
17
|
-
"GrindsharpError",
|
|
18
|
-
"DuplicateJob",
|
|
19
|
-
"TaskNotFound",
|
|
20
|
-
"InvalidTask",
|
|
21
|
-
]
|
|
22
|
-
|
|
23
|
-
__version__ = "0.1.
|
|
1
|
+
from .app import Jobs, Task
|
|
2
|
+
from .errors import DuplicateJob, InvalidTask, GrindsharpError, TaskNotFound
|
|
3
|
+
from .models import Job
|
|
4
|
+
from .store import SQLiteJobStore
|
|
5
|
+
from .postgres import PostgresJobStore
|
|
6
|
+
from .redis_store import RedisJobStore
|
|
7
|
+
from .worker import Worker
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"Jobs",
|
|
11
|
+
"Task",
|
|
12
|
+
"Worker",
|
|
13
|
+
"Job",
|
|
14
|
+
"SQLiteJobStore",
|
|
15
|
+
"PostgresJobStore",
|
|
16
|
+
"RedisJobStore",
|
|
17
|
+
"GrindsharpError",
|
|
18
|
+
"DuplicateJob",
|
|
19
|
+
"TaskNotFound",
|
|
20
|
+
"InvalidTask",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
__version__ = "0.1.1"
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import inspect
|
|
4
3
|
import json
|
|
5
4
|
import uuid
|
|
6
5
|
from datetime import datetime, timedelta, timezone
|
|
7
6
|
from typing import Any, Callable, Generic, TypeVar
|
|
8
7
|
|
|
9
|
-
from .errors import
|
|
8
|
+
from .errors import InvalidTask, TaskNotFound
|
|
10
9
|
from .models import Job
|
|
11
10
|
from .store import SQLiteJobStore
|
|
12
11
|
|
|
@@ -22,6 +22,8 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
22
22
|
p_worker.add_argument("--concurrency", type=int, default=1)
|
|
23
23
|
p_worker.add_argument("--max-jobs", type=int, default=None, help="Stop after handling N jobs")
|
|
24
24
|
p_worker.add_argument("--once", action="store_true", help="Process at most one job and exit")
|
|
25
|
+
p_worker.add_argument("--worker-name", default=None, help="Stable worker name for locks/logs")
|
|
26
|
+
p_worker.add_argument("--stale-timeout-seconds", type=int, default=300, help="Requeue running jobs older than this")
|
|
25
27
|
|
|
26
28
|
p_list = sub.add_parser("list", help="List jobs")
|
|
27
29
|
p_list.add_argument("--status", default=None)
|
|
@@ -37,20 +39,26 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
37
39
|
p_purge.add_argument("--status", default="succeeded")
|
|
38
40
|
p_purge.add_argument("--older-than-seconds", type=int, default=None)
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
sub.add_parser("stats", help="Show job counts")
|
|
41
43
|
|
|
42
44
|
args = parser.parse_args(argv)
|
|
43
45
|
logging.basicConfig(level=getattr(logging, args.log_level.upper(), logging.INFO), format="%(asctime)s %(levelname)s %(name)s %(message)s")
|
|
44
46
|
|
|
45
47
|
if args.cmd == "worker":
|
|
46
48
|
jobs = _load_jobs(args.app, args.db)
|
|
47
|
-
worker = Worker(
|
|
49
|
+
worker = Worker(
|
|
50
|
+
jobs,
|
|
51
|
+
poll_interval=args.poll_interval,
|
|
52
|
+
concurrency=args.concurrency,
|
|
53
|
+
stale_timeout_seconds=args.stale_timeout_seconds,
|
|
54
|
+
worker_name=args.worker_name,
|
|
55
|
+
)
|
|
48
56
|
if args.once:
|
|
49
57
|
job = worker.run_once()
|
|
50
58
|
print(json.dumps(job.to_dict() if job else None, indent=2))
|
|
51
59
|
return 0
|
|
52
60
|
try:
|
|
53
|
-
worker.run(max_jobs=args.max_jobs)
|
|
61
|
+
worker.run(max_jobs=args.max_jobs, install_signal_handlers=True)
|
|
54
62
|
except KeyboardInterrupt:
|
|
55
63
|
worker.stop()
|
|
56
64
|
return 0
|