stablemates-workhorse 0.1.0__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.
- stablemates_workhorse-0.1.0/.gitignore +33 -0
- stablemates_workhorse-0.1.0/CHANGELOG.md +169 -0
- stablemates_workhorse-0.1.0/LICENSE +201 -0
- stablemates_workhorse-0.1.0/NOTICE +6 -0
- stablemates_workhorse-0.1.0/PKG-INFO +117 -0
- stablemates_workhorse-0.1.0/README.md +88 -0
- stablemates_workhorse-0.1.0/examples/async_enqueue.py +39 -0
- stablemates_workhorse-0.1.0/examples/async_worker.py +79 -0
- stablemates_workhorse-0.1.0/examples/dedicated_worker.py +32 -0
- stablemates_workhorse-0.1.0/examples/demo_worker.py +70 -0
- stablemates_workhorse-0.1.0/examples/lifecycle.py +167 -0
- stablemates_workhorse-0.1.0/examples/quickstart.py +22 -0
- stablemates_workhorse-0.1.0/pyproject.toml +98 -0
- stablemates_workhorse-0.1.0/src/workhorse/__init__.py +261 -0
- stablemates_workhorse-0.1.0/src/workhorse/_compatibility.py +88 -0
- stablemates_workhorse-0.1.0/src/workhorse/_contracts.py +123 -0
- stablemates_workhorse-0.1.0/src/workhorse/_drivers.py +122 -0
- stablemates_workhorse-0.1.0/src/workhorse/_external_waits.py +52 -0
- stablemates_workhorse-0.1.0/src/workhorse/_notifications.py +121 -0
- stablemates_workhorse-0.1.0/src/workhorse/_protocol.py +253 -0
- stablemates_workhorse-0.1.0/src/workhorse/_statements.py +559 -0
- stablemates_workhorse-0.1.0/src/workhorse/_telemetry.py +409 -0
- stablemates_workhorse-0.1.0/src/workhorse/_version.py +5 -0
- stablemates_workhorse-0.1.0/src/workhorse/admin.py +1215 -0
- stablemates_workhorse-0.1.0/src/workhorse/async_worker.py +474 -0
- stablemates_workhorse-0.1.0/src/workhorse/client.py +643 -0
- stablemates_workhorse-0.1.0/src/workhorse/compatibility.py +52 -0
- stablemates_workhorse-0.1.0/src/workhorse/dashboard/__init__.py +366 -0
- stablemates_workhorse-0.1.0/src/workhorse/dashboard/_backend.py +508 -0
- stablemates_workhorse-0.1.0/src/workhorse/dashboard/_errors.py +10 -0
- stablemates_workhorse-0.1.0/src/workhorse/dashboard/bundle.json +6 -0
- stablemates_workhorse-0.1.0/src/workhorse/dashboard/read-surface-1.tar.gz +0 -0
- stablemates_workhorse-0.1.0/src/workhorse/dashboard_v1.py +2028 -0
- stablemates_workhorse-0.1.0/src/workhorse/errors.py +315 -0
- stablemates_workhorse-0.1.0/src/workhorse/py.typed +1 -0
- stablemates_workhorse-0.1.0/src/workhorse/types.py +618 -0
- stablemates_workhorse-0.1.0/src/workhorse/worker.py +2175 -0
- stablemates_workhorse-0.1.0/src/workhorse/worker_process.py +57 -0
- stablemates_workhorse-0.1.0/tests/conftest.py +112 -0
- stablemates_workhorse-0.1.0/tests/eventual_conditions.py +51 -0
- stablemates_workhorse-0.1.0/tests/fixtures/crash_worker.py +25 -0
- stablemates_workhorse-0.1.0/tests/fixtures/process_runner.py +50 -0
- stablemates_workhorse-0.1.0/tests/protocol_fixtures.py +22 -0
- stablemates_workhorse-0.1.0/tests/support/check_dashboard_distribution.py +48 -0
- stablemates_workhorse-0.1.0/tests/test_admin.py +261 -0
- stablemates_workhorse-0.1.0/tests/test_async_enqueue.py +166 -0
- stablemates_workhorse-0.1.0/tests/test_async_worker.py +208 -0
- stablemates_workhorse-0.1.0/tests/test_compatibility.py +135 -0
- stablemates_workhorse-0.1.0/tests/test_contracts_profile.py +24 -0
- stablemates_workhorse-0.1.0/tests/test_dashboard_assets.py +18 -0
- stablemates_workhorse-0.1.0/tests/test_dashboard_bindings.py +23 -0
- stablemates_workhorse-0.1.0/tests/test_dashboard_conformance.py +201 -0
- stablemates_workhorse-0.1.0/tests/test_dashboard_host.py +171 -0
- stablemates_workhorse-0.1.0/tests/test_demo_worker_example.py +72 -0
- stablemates_workhorse-0.1.0/tests/test_driver_integration.py +191 -0
- stablemates_workhorse-0.1.0/tests/test_enqueue.py +174 -0
- stablemates_workhorse-0.1.0/tests/test_errors.py +92 -0
- stablemates_workhorse-0.1.0/tests/test_notifications.py +107 -0
- stablemates_workhorse-0.1.0/tests/test_policies.py +197 -0
- stablemates_workhorse-0.1.0/tests/test_protocol_conformance.py +322 -0
- stablemates_workhorse-0.1.0/tests/test_public_surface.py +174 -0
- stablemates_workhorse-0.1.0/tests/test_release.py +183 -0
- stablemates_workhorse-0.1.0/tests/test_schedules.py +47 -0
- stablemates_workhorse-0.1.0/tests/test_sql_catalogue.py +59 -0
- stablemates_workhorse-0.1.0/tests/test_worker.py +1551 -0
- stablemates_workhorse-0.1.0/tests/test_worker_child_jobs.py +385 -0
- stablemates_workhorse-0.1.0/tests/test_worker_external_waits.py +369 -0
- stablemates_workhorse-0.1.0/tests/test_worker_process.py +183 -0
- stablemates_workhorse-0.1.0/tests/test_worker_runtime_conformance.py +717 -0
- stablemates_workhorse-0.1.0/tests/test_worker_schedules.py +114 -0
- stablemates_workhorse-0.1.0/tests/test_worker_telemetry.py +271 -0
- stablemates_workhorse-0.1.0/tests/typecheck_usage.py +233 -0
- stablemates_workhorse-0.1.0/tools/api_snapshot.py +253 -0
- stablemates_workhorse-0.1.0/uv.lock +1149 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
docs/research
|
|
2
|
+
node_modules/
|
|
3
|
+
.pnpm-home/
|
|
4
|
+
dist/
|
|
5
|
+
__pycache__/
|
|
6
|
+
.mypy_cache/
|
|
7
|
+
.pytest_cache/
|
|
8
|
+
.ruff_cache/
|
|
9
|
+
.venv/
|
|
10
|
+
/typescript/dashboard/development/
|
|
11
|
+
coverage/
|
|
12
|
+
.source/
|
|
13
|
+
/site/public/robots.txt
|
|
14
|
+
/site/public/sitemap.xml
|
|
15
|
+
.env
|
|
16
|
+
.env.*
|
|
17
|
+
!.env.example
|
|
18
|
+
!**/.env.example
|
|
19
|
+
*.tgz
|
|
20
|
+
benchmark*.json
|
|
21
|
+
benchmark-artifacts/
|
|
22
|
+
health*.json
|
|
23
|
+
logs/
|
|
24
|
+
ops/signoz/pours/
|
|
25
|
+
.jcode/
|
|
26
|
+
scripts/with-env-probe.tmp.*
|
|
27
|
+
.build/
|
|
28
|
+
/site/public/llms.txt
|
|
29
|
+
/site/public/llms-full.txt
|
|
30
|
+
/site/public/docs.md
|
|
31
|
+
/site/public/docs/
|
|
32
|
+
/site/public/blog/
|
|
33
|
+
/sql/schema.sql
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# Python changelog
|
|
2
|
+
|
|
3
|
+
`stablemates-workhorse` versions and release notes live here because the Python distribution builds
|
|
4
|
+
and publishes from its own tag. It carries the version the TypeScript packages and the Go module
|
|
5
|
+
carry, because all three tags name one commit.
|
|
6
|
+
|
|
7
|
+
Workhorse is a public beta. Any 0.x minor release may change behaviour. From `0.1.0` the schema
|
|
8
|
+
upgrades in place: every release ships ordered migrations, and inside a major line a migration only
|
|
9
|
+
adds.
|
|
10
|
+
|
|
11
|
+
## 0.1.0 — 2026-09-14
|
|
12
|
+
|
|
13
|
+
Published to PyPI from one source commit shared with the npm packages and the Go module, tagged
|
|
14
|
+
`python/v0.1.0`. This is the first version without a prerelease suffix
|
|
15
|
+
([ADR 0050](../docs/decisions/0050-release-0-1-0-without-a-prerelease-suffix.md)). The distribution
|
|
16
|
+
stays a public beta on the `0.x` line, and its classifier stays `Development Status :: 4 - Beta`.
|
|
17
|
+
|
|
18
|
+
Requires **schema v1** and Python **3.12** or newer.
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- The dashboard backend serves `redriveTask` and `redriveDeadLetters`, which the shared
|
|
23
|
+
`dashboard/v1` contract added this release. Both map onto `Admin.redrive` and
|
|
24
|
+
`Admin.redrive_many`: a source the queue does not hold answers 404, and a bulk page reports every
|
|
25
|
+
result plus the continuation cursor the next page resumes from. The host lists both as mutations,
|
|
26
|
+
so a cross-origin or read-only request is refused before dispatch. `workhorse.dashboard_v1` gains
|
|
27
|
+
their generated input and output types.
|
|
28
|
+
- **The Python worker records what it is.** The schema baseline carries `client_protocol_version`,
|
|
29
|
+
`sdk_language`, and `sdk_version` to `workhorse.worker_registry`, and every registration refresh
|
|
30
|
+
reports `python` with this distribution's version and the SQL protocol version it speaks. The
|
|
31
|
+
dashboard shows them per worker, and `workhorse schema status --json` counts the live workers by
|
|
32
|
+
protocol so an operator can see whether a protocol is still in use before retiring it. The
|
|
33
|
+
columns are nullable and the older call is retained, so a worker running an earlier release keeps
|
|
34
|
+
registering during a rolling deploy.
|
|
35
|
+
- `workhorse.compatibility` publishes the startup schema check that the installation page tells every
|
|
36
|
+
runtime to make. `assert_schema_compatible(connection)` takes a Psycopg connection, and
|
|
37
|
+
`assert_schema_compatible_psycopg` and `assert_schema_compatible_asyncpg` name their asynchronous
|
|
38
|
+
driver, mirroring `AsyncQueue.from_psycopg` and `AsyncQueue.from_asyncpg`.
|
|
39
|
+
- `workhorse` exports nine names that were reachable only through a submodule and are the declared
|
|
40
|
+
type of an already-exported field or callback: `CancelStatus`, `CompatibilityCode`,
|
|
41
|
+
`DependencyPolicy`, `EnqueueOutcome`, `Handler`, `HumanWaitCompletionStatus`, `JobState`,
|
|
42
|
+
`JobTimelineEntry`, and `SignalDeliveryStatus`. `workhorse.dashboard` exports `Authorize`, the
|
|
43
|
+
declared type of its documented `authorize` hook, and `DashboardProcedure`, the declared type of
|
|
44
|
+
its `enqueue_test` and `set_schedule_enabled` parameters.
|
|
45
|
+
- Every module under `workhorse` whose name carries no leading underscore now declares `__all__`,
|
|
46
|
+
so `from workhorse.worker import *` and `dir(workhorse.admin)` describe the supported surface.
|
|
47
|
+
Only `workhorse.dashboard` declared one before.
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
|
|
51
|
+
- `Worker.handle_batch` groups and orders members by the worker's claim order. Each job runs on its
|
|
52
|
+
own handler thread, so members previously reached the coordinator in thread scheduling order, and
|
|
53
|
+
two equal-priority jobs could appear in a batch in either order. `AsyncWorker.handle_batch`
|
|
54
|
+
shares the coordinator and gains the same guarantee. This change landed after `0.1.0b3` published
|
|
55
|
+
and was listed under that entry in error.
|
|
56
|
+
|
|
57
|
+
### Changed
|
|
58
|
+
|
|
59
|
+
- **The compatibility check declares a floor and no ceiling, and reads the ceiling from the
|
|
60
|
+
database.** It refused any schema newer than the version this build was compiled against, which
|
|
61
|
+
would have turned the first in-place migration into an outage for the length of a rolling
|
|
62
|
+
deployment. A build cannot know which later release stops serving it, so the installed schema
|
|
63
|
+
declares that instead: `workhorse.protocol_version` records the SQL protocol versions it still
|
|
64
|
+
serves, and a client whose protocol is absent from that list raises
|
|
65
|
+
`ProtocolCompatibilityError`. Below the oldest served version is `schema-too-new`; above the
|
|
66
|
+
newest is `schema-too-old`. A schema that records nothing enforces nothing. One statement returns
|
|
67
|
+
the schema version and the served list together, so the check stays one round trip.
|
|
68
|
+
- The README states the unpinned install command and the schema install step, which the TypeScript
|
|
69
|
+
CLI owns.
|
|
70
|
+
|
|
71
|
+
### Removed
|
|
72
|
+
|
|
73
|
+
- The public submodules no longer re-export the private helpers they import. About seventy names
|
|
74
|
+
from `workhorse._compatibility`, `workhorse._contracts`, `workhorse._drivers`,
|
|
75
|
+
`workhorse._external_waits`, `workhorse._notifications`, `workhorse._protocol`,
|
|
76
|
+
`workhorse._statements`, and `workhorse._telemetry` are gone from `workhorse.admin`,
|
|
77
|
+
`workhorse.client`, `workhorse.compatibility`, `workhorse.dashboard`, and `workhorse.worker`.
|
|
78
|
+
Among them are `SQL_STATEMENTS`, `STATEMENTS`, `DriverStatement`, `Row`, `SyncConnection`,
|
|
79
|
+
`SyncExecutor`, `PsycopgConnection`, `AsyncpgConnection`, and every other driver protocol. Import
|
|
80
|
+
the supported name from `workhorse` instead; nothing in the documented surface referenced them.
|
|
81
|
+
- `workhorse.errors.translate_database_error`, `workhorse.worker.AttemptOutcome`,
|
|
82
|
+
`workhorse.worker.JobExecutionOutcome`, `workhorse.async_worker.T`,
|
|
83
|
+
`workhorse.types.TJson`, `workhorse.dashboard.DashboardBackend`,
|
|
84
|
+
`workhorse.dashboard.DashboardRPCError`, and `workhorse.dashboard.normalize_dashboard_path`
|
|
85
|
+
are private. They were internal helpers that no document or test named.
|
|
86
|
+
- The `workhorse.admin` statement and limit constants `GET_*`, `LIST_*`, `REDRIVE`,
|
|
87
|
+
`REDRIVE_MANY`, `SET_*`, `PURGE_QUEUE`, `DEFAULT_PAYLOAD_BYTES`, `JOB_STATES`, `MAX_PAGE_SIZE`,
|
|
88
|
+
`MAX_PAYLOAD_BYTES`, `MAX_REDACT_KEYS`, and `MAX_REDRIVE_BATCH_SIZE` are private. The limits stay
|
|
89
|
+
internal rather than becoming public under the TypeScript names, because the Go module publishes
|
|
90
|
+
no counterpart and no Python document states them.
|
|
91
|
+
- The dashboard backend's run-now action calls the audited `workhorse.run_task_now_v1` instead of
|
|
92
|
+
`workhorse.dashboard_run_task_now_v1`, which is removed from the schema. The action now records
|
|
93
|
+
the authenticated actor, the reason, and the request identity in its `promoted` event, matching
|
|
94
|
+
the TypeScript dashboard server.
|
|
95
|
+
- **Type names.** Two exported type aliases take the names the TypeScript and Go SDKs already share:
|
|
96
|
+
`workhorse.types.TerminalPolicy` becomes `DependencyTerminalPolicy` and
|
|
97
|
+
`workhorse.types.NonReplaceableReason` becomes `EnqueueNonReplaceableReason`. Both new names are
|
|
98
|
+
exported from `workhorse`, which neither old name was. Each old name stays in `workhorse.types` as
|
|
99
|
+
a deprecated alias of its replacement, so no code has to change on this release. The aliases are
|
|
100
|
+
removed in `1.0.0`.
|
|
101
|
+
- **`workhorse.dashboard_v1` type names.** Every type generated from a shared `dashboard/v1` wire
|
|
102
|
+
type now carries the `Dashboard` prefix, so the module no longer declares a second `CancelStatus`
|
|
103
|
+
and `JSON` beside `workhorse.types`. `CancelStatus`, `SendSignalStatus`,
|
|
104
|
+
`CompleteHumanWaitStatus`, `JSON`, `QueueHealthReason`, `QueueHealthReasonCode`,
|
|
105
|
+
`RetentionPolicyImpact`, and `MaintenanceLoopCadences` become `DashboardCancelStatus`,
|
|
106
|
+
`DashboardSignalDeliveryStatus`, `DashboardHumanWaitCompletionStatus`, `DashboardJSON`,
|
|
107
|
+
`DashboardQueueHealthReason`, `DashboardQueueHealthReasonCode`,
|
|
108
|
+
`DashboardRetentionPolicyImpact`, and `DashboardMaintenanceLoopCadences`. The module is
|
|
109
|
+
generated, so it carries no aliases: a caller that names one of the eight updates the name. No
|
|
110
|
+
request or response payload changes.
|
|
111
|
+
|
|
112
|
+
### Upgrade notes
|
|
113
|
+
|
|
114
|
+
- **Schema version.** `0.1.0` stays at schema version 1, but its baseline is not the one the last
|
|
115
|
+
beta installed: `workhorse.valid_tags` was renamed `workhorse.valid_tags_v1` and
|
|
116
|
+
`workhorse.dashboard_run_task_now_v1` was removed. A database installed by any beta reports
|
|
117
|
+
version 1 and passes the compatibility check, yet holds the old function names. You must recreate the database and
|
|
118
|
+
install the new baseline with
|
|
119
|
+
`npx --package @stablemates/workhorse@0.1.0 workhorse schema install`.
|
|
120
|
+
This is the last release that asks for a recreation: from `0.1.0` the schema is frozen as the
|
|
121
|
+
migration baseline, and later releases upgrade a database in place.
|
|
122
|
+
|
|
123
|
+
## 0.1.0b3 — 2026-09-01
|
|
124
|
+
|
|
125
|
+
Published to PyPI from commit `663c526805746786f12b3be3e151e8ce06c80057`, tagged
|
|
126
|
+
`python/v0.1.0b3`.
|
|
127
|
+
|
|
128
|
+
### Fixed
|
|
129
|
+
|
|
130
|
+
- The fix-forward release uploads PEP 740 attestations with its wheel and source distribution.
|
|
131
|
+
The package behavior is unchanged from `0.1.0b1`.
|
|
132
|
+
|
|
133
|
+
## 0.1.0b2 — 2026-08-31
|
|
134
|
+
|
|
135
|
+
Published to PyPI from commit `0c15212cc5510501bbc9b74bd372fa480e77a1ff`, tagged
|
|
136
|
+
`python/v0.1.0b2`.
|
|
137
|
+
|
|
138
|
+
### Fixed
|
|
139
|
+
|
|
140
|
+
- The release workflow generated PEP 740 attestations but omitted them from the PyPI upload.
|
|
141
|
+
The package behavior is unchanged from `0.1.0b1`.
|
|
142
|
+
|
|
143
|
+
## 0.1.0b1 — 2026-08-31
|
|
144
|
+
|
|
145
|
+
Published to PyPI from commit `6769c768d19861fb8c5c7ea3764e8d5abc62fcf4`, tagged
|
|
146
|
+
`python/v0.1.0b1`.
|
|
147
|
+
|
|
148
|
+
### Changed
|
|
149
|
+
|
|
150
|
+
- The distribution uses the Apache License, Version 2.0. Contributions require the
|
|
151
|
+
repository `CLA.md`.
|
|
152
|
+
|
|
153
|
+
### Added
|
|
154
|
+
|
|
155
|
+
- Synchronous and asynchronous queue clients, workers, administrative clients, and an embedded
|
|
156
|
+
WSGI dashboard implement the Workhorse SQL protocol through Psycopg and asyncpg.
|
|
157
|
+
- Handlers can use durable batches, timers, signals, human decisions, child jobs, progress, and
|
|
158
|
+
checkpoints with the same fenced ownership rules as the TypeScript runtime.
|
|
159
|
+
- Synchronous handlers can suspend through named signal and human-decision waits, then replay the
|
|
160
|
+
retained external value in the same logical attempt. Synchronous and asynchronous queue clients
|
|
161
|
+
deliver attributed values with idempotency and typed conflict errors.
|
|
162
|
+
- `run_worker_process` adds bounded `SIGINT` and `SIGTERM` drain handling for the synchronous
|
|
163
|
+
worker. A second signal exits with its conventional code, while an expired deadline exits with
|
|
164
|
+
failure so PostgreSQL can recover active leases.
|
|
165
|
+
- Synchronous `Worker.handle_batch` delivery supports queue-isolated full and partial groups,
|
|
166
|
+
explicit per-member outcomes, independent fences and retries, and durable batch evidence.
|
|
167
|
+
- Typed synchronous Psycopg and asynchronous Psycopg or asyncpg enqueue clients support delayed and
|
|
168
|
+
recurring work, priority, atomic batches, idempotency, debounce, throttle, dependencies,
|
|
169
|
+
caller-owned transactions, compatibility refusal, and shared SQL conformance.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but not
|
|
32
|
+
limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Stablemates
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: stablemates-workhorse
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for the Workhorse durable job queue for PostgreSQL. Public beta.
|
|
5
|
+
Project-URL: Documentation, https://workhorse.run/docs/quickstart
|
|
6
|
+
Project-URL: Repository, https://github.com/stablemates/workhorse
|
|
7
|
+
Project-URL: Issues, https://github.com/stablemates/workhorse/issues
|
|
8
|
+
Author: Stablemates
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
License-File: NOTICE
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Database :: Front-Ends
|
|
20
|
+
Requires-Python: >=3.12
|
|
21
|
+
Requires-Dist: jsonschema<5,>=4.25
|
|
22
|
+
Requires-Dist: psycopg<4,>=3.3
|
|
23
|
+
Provides-Extra: asyncpg
|
|
24
|
+
Requires-Dist: asyncpg<1,>=0.31; extra == 'asyncpg'
|
|
25
|
+
Provides-Extra: psycopg
|
|
26
|
+
Provides-Extra: telemetry
|
|
27
|
+
Requires-Dist: opentelemetry-api<2,>=1.44; extra == 'telemetry'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# `stablemates-workhorse`
|
|
31
|
+
|
|
32
|
+
The Python clients, worker runtimes, and dashboard host for the Workhorse durable job queue for
|
|
33
|
+
PostgreSQL.
|
|
34
|
+
|
|
35
|
+
> **Public beta:** Workhorse is usable for evaluation and early production adoption. A 0.x minor
|
|
36
|
+
> release may change behaviour, so read the changelog before you upgrade. It will not ask you to
|
|
37
|
+
> recreate your database: migrations are ordered, and inside a major line a migration only adds, so
|
|
38
|
+
> a running deployment upgrades in place.
|
|
39
|
+
|
|
40
|
+
An AI agent should read [the Workhorse documentation index](https://workhorse.run/llms.txt) first.
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install stablemates-workhorse
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Install the schema once, as a deployment step. The application never installs or migrates it.
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npx --package @stablemates/workhorse@0.1.0 workhorse schema install
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The machine that runs that deployment step needs Node.js 22 or newer. The application itself needs
|
|
55
|
+
no Node.js.
|
|
56
|
+
|
|
57
|
+
Pin that version to the `stablemates-workhorse` version the application depends on. The two are
|
|
58
|
+
released together from one commit, so the numbers match. A schema tool older than the application
|
|
59
|
+
leaves a schema the application refuses to start against.
|
|
60
|
+
|
|
61
|
+
Runtime processes verify compatibility instead of changing the schema. Call
|
|
62
|
+
`assert_schema_compatible(connection)` at startup. Call `assert_schema_compatible_psycopg` or
|
|
63
|
+
`assert_schema_compatible_asyncpg` when the application is asynchronous.
|
|
64
|
+
|
|
65
|
+
Requires Python 3.12 through 3.14 and PostgreSQL 15 through 18.
|
|
66
|
+
|
|
67
|
+
## Run one job
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from __future__ import annotations
|
|
71
|
+
|
|
72
|
+
import os
|
|
73
|
+
|
|
74
|
+
import psycopg
|
|
75
|
+
|
|
76
|
+
from workhorse import Queue, Worker
|
|
77
|
+
|
|
78
|
+
database_url = os.environ["DATABASE_URL"]
|
|
79
|
+
|
|
80
|
+
with psycopg.connect(database_url) as application_connection:
|
|
81
|
+
job_id = Queue(application_connection).enqueue("email.welcome", {"to": "ada@example.com"})
|
|
82
|
+
application_connection.commit()
|
|
83
|
+
|
|
84
|
+
with psycopg.connect(database_url, autocommit=True) as worker_connection:
|
|
85
|
+
worker = Worker(worker_connection).handle(
|
|
86
|
+
"email.welcome",
|
|
87
|
+
lambda payload, _context: {"deliveredTo": payload["to"]},
|
|
88
|
+
)
|
|
89
|
+
assert worker.run_once() is True # Production worker processes call run().
|
|
90
|
+
|
|
91
|
+
print(job_id)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Handlers receive at-least-once delivery. Use stable provider idempotency keys around external
|
|
95
|
+
effects; named checkpoints prevent completed application stages from running after a later restart.
|
|
96
|
+
|
|
97
|
+
## Package boundary
|
|
98
|
+
|
|
99
|
+
This distribution provides synchronous Psycopg and asynchronous Psycopg or asyncpg clients and
|
|
100
|
+
workers. Application clients use caller-owned connections and transactions. Workers use dedicated
|
|
101
|
+
connections for claims and lifecycle calls. The package never installs or migrates the shared
|
|
102
|
+
PostgreSQL schema.
|
|
103
|
+
|
|
104
|
+
## Next
|
|
105
|
+
|
|
106
|
+
- Follow the [quickstart](https://workhorse.run/docs/quickstart) and deploy
|
|
107
|
+
[worker processes](https://workhorse.run/docs/worker-processes).
|
|
108
|
+
- Read the [API reference](https://workhorse.run/docs/api) and
|
|
109
|
+
[compatibility policy](https://workhorse.run/docs/compatibility).
|
|
110
|
+
- Use the [operations guide](https://workhorse.run/docs/operations) for telemetry, health, and
|
|
111
|
+
maintenance.
|
|
112
|
+
- Browse the [repository](https://github.com/stablemates/workhorse) or report a problem in
|
|
113
|
+
[GitHub issues](https://github.com/stablemates/workhorse/issues).
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
Apache-2.0. See `LICENSE` and `NOTICE` in the package.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# `stablemates-workhorse`
|
|
2
|
+
|
|
3
|
+
The Python clients, worker runtimes, and dashboard host for the Workhorse durable job queue for
|
|
4
|
+
PostgreSQL.
|
|
5
|
+
|
|
6
|
+
> **Public beta:** Workhorse is usable for evaluation and early production adoption. A 0.x minor
|
|
7
|
+
> release may change behaviour, so read the changelog before you upgrade. It will not ask you to
|
|
8
|
+
> recreate your database: migrations are ordered, and inside a major line a migration only adds, so
|
|
9
|
+
> a running deployment upgrades in place.
|
|
10
|
+
|
|
11
|
+
An AI agent should read [the Workhorse documentation index](https://workhorse.run/llms.txt) first.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install stablemates-workhorse
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Install the schema once, as a deployment step. The application never installs or migrates it.
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx --package @stablemates/workhorse@0.1.0 workhorse schema install
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The machine that runs that deployment step needs Node.js 22 or newer. The application itself needs
|
|
26
|
+
no Node.js.
|
|
27
|
+
|
|
28
|
+
Pin that version to the `stablemates-workhorse` version the application depends on. The two are
|
|
29
|
+
released together from one commit, so the numbers match. A schema tool older than the application
|
|
30
|
+
leaves a schema the application refuses to start against.
|
|
31
|
+
|
|
32
|
+
Runtime processes verify compatibility instead of changing the schema. Call
|
|
33
|
+
`assert_schema_compatible(connection)` at startup. Call `assert_schema_compatible_psycopg` or
|
|
34
|
+
`assert_schema_compatible_asyncpg` when the application is asynchronous.
|
|
35
|
+
|
|
36
|
+
Requires Python 3.12 through 3.14 and PostgreSQL 15 through 18.
|
|
37
|
+
|
|
38
|
+
## Run one job
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from __future__ import annotations
|
|
42
|
+
|
|
43
|
+
import os
|
|
44
|
+
|
|
45
|
+
import psycopg
|
|
46
|
+
|
|
47
|
+
from workhorse import Queue, Worker
|
|
48
|
+
|
|
49
|
+
database_url = os.environ["DATABASE_URL"]
|
|
50
|
+
|
|
51
|
+
with psycopg.connect(database_url) as application_connection:
|
|
52
|
+
job_id = Queue(application_connection).enqueue("email.welcome", {"to": "ada@example.com"})
|
|
53
|
+
application_connection.commit()
|
|
54
|
+
|
|
55
|
+
with psycopg.connect(database_url, autocommit=True) as worker_connection:
|
|
56
|
+
worker = Worker(worker_connection).handle(
|
|
57
|
+
"email.welcome",
|
|
58
|
+
lambda payload, _context: {"deliveredTo": payload["to"]},
|
|
59
|
+
)
|
|
60
|
+
assert worker.run_once() is True # Production worker processes call run().
|
|
61
|
+
|
|
62
|
+
print(job_id)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Handlers receive at-least-once delivery. Use stable provider idempotency keys around external
|
|
66
|
+
effects; named checkpoints prevent completed application stages from running after a later restart.
|
|
67
|
+
|
|
68
|
+
## Package boundary
|
|
69
|
+
|
|
70
|
+
This distribution provides synchronous Psycopg and asynchronous Psycopg or asyncpg clients and
|
|
71
|
+
workers. Application clients use caller-owned connections and transactions. Workers use dedicated
|
|
72
|
+
connections for claims and lifecycle calls. The package never installs or migrates the shared
|
|
73
|
+
PostgreSQL schema.
|
|
74
|
+
|
|
75
|
+
## Next
|
|
76
|
+
|
|
77
|
+
- Follow the [quickstart](https://workhorse.run/docs/quickstart) and deploy
|
|
78
|
+
[worker processes](https://workhorse.run/docs/worker-processes).
|
|
79
|
+
- Read the [API reference](https://workhorse.run/docs/api) and
|
|
80
|
+
[compatibility policy](https://workhorse.run/docs/compatibility).
|
|
81
|
+
- Use the [operations guide](https://workhorse.run/docs/operations) for telemetry, health, and
|
|
82
|
+
maintenance.
|
|
83
|
+
- Browse the [repository](https://github.com/stablemates/workhorse) or report a problem in
|
|
84
|
+
[GitHub issues](https://github.com/stablemates/workhorse/issues).
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
Apache-2.0. See `LICENSE` and `NOTICE` in the package.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import sys
|
|
5
|
+
from uuid import uuid4
|
|
6
|
+
|
|
7
|
+
import asyncpg # type: ignore[import-untyped]
|
|
8
|
+
import psycopg
|
|
9
|
+
|
|
10
|
+
from workhorse import AsyncQueue
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
async def run(database_url: str) -> None:
|
|
14
|
+
suffix = uuid4().hex
|
|
15
|
+
async with (
|
|
16
|
+
await psycopg.AsyncConnection.connect(database_url) as connection,
|
|
17
|
+
connection.transaction(),
|
|
18
|
+
):
|
|
19
|
+
await AsyncQueue.from_psycopg(connection).enqueue(
|
|
20
|
+
f"python-example-psycopg-{suffix}",
|
|
21
|
+
{"driver": "psycopg"},
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
connection = await asyncpg.connect(database_url)
|
|
25
|
+
try:
|
|
26
|
+
transaction = connection.transaction()
|
|
27
|
+
await transaction.start()
|
|
28
|
+
await AsyncQueue.from_asyncpg(connection).enqueue(
|
|
29
|
+
f"python-example-asyncpg-{suffix}",
|
|
30
|
+
{"driver": "asyncpg"},
|
|
31
|
+
)
|
|
32
|
+
await transaction.commit()
|
|
33
|
+
finally:
|
|
34
|
+
await connection.close()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
if __name__ == "__main__":
|
|
38
|
+
asyncio.run(run(sys.argv[1]))
|
|
39
|
+
print("Python async driver example completed")
|