unique_toolkit 2026.48.0.dev12__py3-none-any.whl → 2026.48.0.dev13__py3-none-any.whl
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.
- unique_toolkit/experimental/resources/activity_records/config.py +4 -0
- unique_toolkit/experimental/resources/activity_records/migrate.py +85 -0
- unique_toolkit/experimental/resources/activity_records/store.py +354 -0
- {unique_toolkit-2026.48.0.dev12.dist-info → unique_toolkit-2026.48.0.dev13.dist-info}/METADATA +5 -2
- {unique_toolkit-2026.48.0.dev12.dist-info → unique_toolkit-2026.48.0.dev13.dist-info}/RECORD +6 -4
- {unique_toolkit-2026.48.0.dev12.dist-info → unique_toolkit-2026.48.0.dev13.dist-info}/WHEEL +0 -0
|
@@ -16,6 +16,10 @@ from unique_toolkit.experimental.resources.activity_records.schemas import (
|
|
|
16
16
|
|
|
17
17
|
DEFAULT_MAX_DATA_SIZE_BYTES: Final = 1_048_576
|
|
18
18
|
DEFAULT_MAX_BATCH_SIZE_BYTES: Final = 8_388_608
|
|
19
|
+
OUTBOX_MAX_BACKOFF_ATTEMPTS: Final = 11
|
|
20
|
+
ACTIVITY_RECORDS_INSTALL_HINT: Final = (
|
|
21
|
+
"Install it with: uv add 'unique-toolkit[activity-records]'"
|
|
22
|
+
)
|
|
19
23
|
|
|
20
24
|
_MAX_SAFE_INTEGER: Final = 2**53 - 1
|
|
21
25
|
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Create the Activity Records outbox table from ``DATABASE_URL``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from unique_toolkit.experimental.resources.activity_records.store import (
|
|
10
|
+
ACTIVITY_EVENT_OUTBOX_INITIAL_MIGRATION_SQL,
|
|
11
|
+
connect_database,
|
|
12
|
+
outbox_columns_match,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
# Without a deadline, waiting for the advisory lock or running DDL can hang a Helm hook forever.
|
|
16
|
+
MIGRATION_COMMAND_TIMEOUT_SECONDS = 60.0
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class OutboxTableMismatch(Exception):
|
|
20
|
+
"""The table exists but a column is missing or has a wrong type."""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
async def migrate(database_url: str) -> bool:
|
|
24
|
+
"""Returns True when the table was created, False when it already existed.
|
|
25
|
+
|
|
26
|
+
Raises ``OutboxTableMismatch`` when the table does not have the expected columns."""
|
|
27
|
+
connection = await connect_database(
|
|
28
|
+
database_url, command_timeout=MIGRATION_COMMAND_TIMEOUT_SECONDS
|
|
29
|
+
)
|
|
30
|
+
try:
|
|
31
|
+
await connection.execute("BEGIN")
|
|
32
|
+
await connection.execute(
|
|
33
|
+
"SELECT pg_advisory_xact_lock(hashtext('ActivityEventOutbox'))"
|
|
34
|
+
)
|
|
35
|
+
created = not await connection.fetchval(
|
|
36
|
+
"""SELECT to_regclass(
|
|
37
|
+
format('%I."ActivityEventOutbox"', current_schema())
|
|
38
|
+
) IS NOT NULL"""
|
|
39
|
+
)
|
|
40
|
+
if created:
|
|
41
|
+
await connection.execute(ACTIVITY_EVENT_OUTBOX_INITIAL_MIGRATION_SQL)
|
|
42
|
+
if not await outbox_columns_match(connection):
|
|
43
|
+
raise OutboxTableMismatch
|
|
44
|
+
await connection.execute("COMMIT")
|
|
45
|
+
return created
|
|
46
|
+
except TimeoutError:
|
|
47
|
+
# asyncpg 0.30 queues ROLLBACK and close behind a cancel request a frozen server never answers.
|
|
48
|
+
connection.terminate()
|
|
49
|
+
raise
|
|
50
|
+
finally:
|
|
51
|
+
# Closing without COMMIT rolls the transaction back on the server.
|
|
52
|
+
await connection.close(timeout=MIGRATION_COMMAND_TIMEOUT_SECONDS)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def main() -> int:
|
|
56
|
+
database_url = os.environ.get("DATABASE_URL")
|
|
57
|
+
if not database_url:
|
|
58
|
+
print("DATABASE_URL is not set", file=sys.stderr)
|
|
59
|
+
return 1
|
|
60
|
+
try:
|
|
61
|
+
created = asyncio.run(migrate(database_url))
|
|
62
|
+
except OutboxTableMismatch:
|
|
63
|
+
print(
|
|
64
|
+
"The ActivityEventOutbox table exists but a column is missing or has a "
|
|
65
|
+
"wrong type; fix the table before the service starts",
|
|
66
|
+
file=sys.stderr,
|
|
67
|
+
)
|
|
68
|
+
return 1
|
|
69
|
+
except Exception as error:
|
|
70
|
+
# The message can echo the connection string, so print the class name only.
|
|
71
|
+
print(
|
|
72
|
+
f"Activity Records migration failed: {type(error).__name__}",
|
|
73
|
+
file=sys.stderr,
|
|
74
|
+
)
|
|
75
|
+
return 1
|
|
76
|
+
print(
|
|
77
|
+
"ActivityEventOutbox created"
|
|
78
|
+
if created
|
|
79
|
+
else "ActivityEventOutbox already exists"
|
|
80
|
+
)
|
|
81
|
+
return 0
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
if __name__ == "__main__":
|
|
85
|
+
sys.exit(main())
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
"""Run all SQL for the Activity Records outbox with fixed names and bind parameters."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import logging
|
|
7
|
+
from collections.abc import Mapping, Sequence
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from types import MappingProxyType
|
|
10
|
+
from typing import Final
|
|
11
|
+
from urllib.parse import parse_qsl, urlencode, urlsplit, urlunsplit
|
|
12
|
+
|
|
13
|
+
from unique_toolkit.experimental.resources.activity_records.config import (
|
|
14
|
+
ACTIVITY_RECORDS_INSTALL_HINT,
|
|
15
|
+
OUTBOX_MAX_BACKOFF_ATTEMPTS,
|
|
16
|
+
)
|
|
17
|
+
from unique_toolkit.experimental.resources.activity_records.json_size import json_bytes
|
|
18
|
+
from unique_toolkit.experimental.resources.activity_records.prepare import (
|
|
19
|
+
OutboxRow,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
import asyncpg # pyright: ignore[reportMissingImports]
|
|
24
|
+
except ImportError as error: # pragma: no cover
|
|
25
|
+
raise ImportError(
|
|
26
|
+
f"The Activity Records outbox needs asyncpg. {ACTIVITY_RECORDS_INSTALL_HINT}"
|
|
27
|
+
) from error
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
logger = logging.getLogger(__name__)
|
|
31
|
+
|
|
32
|
+
# The DSN parameters that asyncpg 0.30 (the declared minimum) and newer versions both read, plus
|
|
33
|
+
# application_name, a real server setting. Any other key goes to the server, which rejects it.
|
|
34
|
+
_ASYNCPG_DSN_KEYS: Final = frozenset(
|
|
35
|
+
{
|
|
36
|
+
"host",
|
|
37
|
+
"port",
|
|
38
|
+
"user",
|
|
39
|
+
"password",
|
|
40
|
+
"dbname",
|
|
41
|
+
"database",
|
|
42
|
+
"passfile",
|
|
43
|
+
"sslmode",
|
|
44
|
+
"sslcert",
|
|
45
|
+
"sslkey",
|
|
46
|
+
"sslrootcert",
|
|
47
|
+
"sslnegotiation",
|
|
48
|
+
"sslcrl",
|
|
49
|
+
"sslpassword",
|
|
50
|
+
"ssl_min_protocol_version",
|
|
51
|
+
"ssl_max_protocol_version",
|
|
52
|
+
"target_session_attrs",
|
|
53
|
+
"krbsrvname",
|
|
54
|
+
"gsslib",
|
|
55
|
+
"application_name",
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
_logged_dropped_keys: set[str] = set()
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def normalize_database_url(database_url: str) -> tuple[str, int | None]:
|
|
62
|
+
"""Return the DSN asyncpg can parse and the connect timeout from ``connect_timeout``.
|
|
63
|
+
|
|
64
|
+
``sslmode=verify`` (the chart's value) becomes ``verify-full``. Parameters asyncpg does not
|
|
65
|
+
read are dropped, and only their names are logged, once."""
|
|
66
|
+
parts = urlsplit(database_url)
|
|
67
|
+
kept: list[tuple[str, str]] = []
|
|
68
|
+
dropped: list[str] = []
|
|
69
|
+
timeout: int | None = None
|
|
70
|
+
for key, value in parse_qsl(parts.query, keep_blank_values=True):
|
|
71
|
+
if key == "connect_timeout":
|
|
72
|
+
try:
|
|
73
|
+
timeout = int(value)
|
|
74
|
+
except ValueError:
|
|
75
|
+
dropped.append(key)
|
|
76
|
+
elif key not in _ASYNCPG_DSN_KEYS:
|
|
77
|
+
dropped.append(key)
|
|
78
|
+
elif key == "sslmode" and value == "verify":
|
|
79
|
+
kept.append((key, "verify-full"))
|
|
80
|
+
else:
|
|
81
|
+
kept.append((key, value))
|
|
82
|
+
new_names = sorted(set(dropped) - _logged_dropped_keys)
|
|
83
|
+
if new_names:
|
|
84
|
+
_logged_dropped_keys.update(new_names)
|
|
85
|
+
logger.warning(
|
|
86
|
+
"Ignoring DATABASE_URL parameters that asyncpg does not support: %s",
|
|
87
|
+
", ".join(new_names),
|
|
88
|
+
)
|
|
89
|
+
dsn = urlunsplit(
|
|
90
|
+
(parts.scheme, parts.netloc, parts.path, urlencode(kept), parts.fragment)
|
|
91
|
+
)
|
|
92
|
+
# PostgreSQL reads 0 as no timeout, but asyncpg reads it as an immediate deadline.
|
|
93
|
+
return dsn, timeout if timeout is not None and timeout > 0 else None
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
async def connect_database(
|
|
97
|
+
database_url: str, *, command_timeout: float | None = None
|
|
98
|
+
) -> asyncpg.Connection:
|
|
99
|
+
dsn, timeout = normalize_database_url(database_url)
|
|
100
|
+
if timeout is None:
|
|
101
|
+
return await asyncpg.connect(dsn, command_timeout=command_timeout)
|
|
102
|
+
return await asyncpg.connect(dsn, timeout=timeout, command_timeout=command_timeout)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
# Without these a frozen database holds a query forever and a new connection waits 60 s.
|
|
106
|
+
POOL_COMMAND_TIMEOUT_SECONDS: Final = 30.0
|
|
107
|
+
POOL_CONNECT_TIMEOUT_SECONDS: Final = 10.0
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
async def create_pool(
|
|
111
|
+
database_url: str, *, min_size: int, max_size: int
|
|
112
|
+
) -> asyncpg.Pool:
|
|
113
|
+
dsn, dsn_timeout = normalize_database_url(database_url)
|
|
114
|
+
return await asyncpg.create_pool(
|
|
115
|
+
dsn,
|
|
116
|
+
min_size=min_size,
|
|
117
|
+
max_size=max_size,
|
|
118
|
+
command_timeout=POOL_COMMAND_TIMEOUT_SECONDS,
|
|
119
|
+
timeout=dsn_timeout or POOL_CONNECT_TIMEOUT_SECONDS,
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
# Copied into the producing service's migration; keep it byte for byte equal to the Node constant.
|
|
124
|
+
ACTIVITY_EVENT_OUTBOX_INITIAL_MIGRATION_SQL: Final = """-- CreateTable
|
|
125
|
+
CREATE TABLE "ActivityEventOutbox" (
|
|
126
|
+
"id" UUID NOT NULL,
|
|
127
|
+
"companyId" TEXT NOT NULL,
|
|
128
|
+
"source" TEXT NOT NULL,
|
|
129
|
+
"payload" JSONB NOT NULL,
|
|
130
|
+
"createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
131
|
+
"attempts" INTEGER NOT NULL DEFAULT 0,
|
|
132
|
+
"nextAttemptAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
133
|
+
"claimedUntil" TIMESTAMPTZ(6),
|
|
134
|
+
"claimToken" UUID,
|
|
135
|
+
"lastError" TEXT,
|
|
136
|
+
|
|
137
|
+
CONSTRAINT "ActivityEventOutbox_pkey" PRIMARY KEY ("id")
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
-- CreateIndex
|
|
141
|
+
CREATE INDEX "ActivityEventOutbox_nextAttemptAt_idx" ON "ActivityEventOutbox"("nextAttemptAt");
|
|
142
|
+
|
|
143
|
+
-- CreateIndex
|
|
144
|
+
CREATE INDEX "ActivityEventOutbox_createdAt_idx" ON "ActivityEventOutbox"("createdAt");
|
|
145
|
+
"""
|
|
146
|
+
|
|
147
|
+
# Column name to ``information_schema.columns.data_type``; extra columns are allowed.
|
|
148
|
+
ACTIVITY_EVENT_OUTBOX_COLUMNS: Final[Mapping[str, str]] = MappingProxyType(
|
|
149
|
+
{
|
|
150
|
+
"id": "uuid",
|
|
151
|
+
"companyId": "text",
|
|
152
|
+
"source": "text",
|
|
153
|
+
"payload": "jsonb",
|
|
154
|
+
"createdAt": "timestamp with time zone",
|
|
155
|
+
"attempts": "integer",
|
|
156
|
+
"nextAttemptAt": "timestamp with time zone",
|
|
157
|
+
"claimedUntil": "timestamp with time zone",
|
|
158
|
+
"claimToken": "uuid",
|
|
159
|
+
"lastError": "text",
|
|
160
|
+
}
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
# Delay after a failed publish is min(2^attempts, cap) seconds, jittered to 50-100 %.
|
|
164
|
+
OUTBOX_MAX_BACKOFF_SECONDS: Final = 15 * 60
|
|
165
|
+
# power(2, ...) overflows double precision past 2^1023, and a row retries forever.
|
|
166
|
+
_BACKOFF_EXPONENT_CEILING: Final = 20
|
|
167
|
+
# The row-count gauges read at most this many rows so a large backlog stays cheap.
|
|
168
|
+
OUTBOX_STATS_ROW_CAP: Final = 100_000
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
@dataclass(frozen=True, slots=True)
|
|
172
|
+
class ClaimedOutboxRow(OutboxRow):
|
|
173
|
+
attempts: int
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
@dataclass(frozen=True, slots=True)
|
|
177
|
+
class OutboxStats:
|
|
178
|
+
pending_rows: int
|
|
179
|
+
oldest_pending_age_seconds: float
|
|
180
|
+
rows_at_max_backoff: int
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def _affected(status: str) -> int:
|
|
184
|
+
return int(status.rsplit(" ", 1)[-1])
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
async def outbox_columns_match(executor: asyncpg.Pool | asyncpg.Connection) -> bool:
|
|
188
|
+
"""True when every column in ``ACTIVITY_EVENT_OUTBOX_COLUMNS`` exists with its type in
|
|
189
|
+
``current_schema()``. Extra columns are allowed."""
|
|
190
|
+
records = await executor.fetch(
|
|
191
|
+
"""
|
|
192
|
+
SELECT column_name AS "name", data_type AS "type"
|
|
193
|
+
FROM information_schema.columns
|
|
194
|
+
WHERE table_schema = current_schema() AND table_name = 'ActivityEventOutbox'"""
|
|
195
|
+
)
|
|
196
|
+
actual = {record["name"]: record["type"] for record in records}
|
|
197
|
+
return all(
|
|
198
|
+
actual.get(name) == type_
|
|
199
|
+
for name, type_ in ACTIVITY_EVENT_OUTBOX_COLUMNS.items()
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
class OutboxStore:
|
|
204
|
+
def __init__(self, pool: asyncpg.Pool) -> None:
|
|
205
|
+
self._pool = pool
|
|
206
|
+
|
|
207
|
+
def _connection(self) -> asyncpg.pool.PoolAcquireContext:
|
|
208
|
+
# The acquire timeout also bounds release, which pool.execute() leaves unbounded.
|
|
209
|
+
return self._pool.acquire(timeout=POOL_COMMAND_TIMEOUT_SECONDS)
|
|
210
|
+
|
|
211
|
+
async def insert(self, rows: Sequence[OutboxRow]) -> int:
|
|
212
|
+
wire = [
|
|
213
|
+
{
|
|
214
|
+
"id": row.id,
|
|
215
|
+
"companyId": row.company_id,
|
|
216
|
+
"source": row.source,
|
|
217
|
+
"payload": row.payload,
|
|
218
|
+
}
|
|
219
|
+
for row in rows
|
|
220
|
+
]
|
|
221
|
+
async with self._connection() as connection:
|
|
222
|
+
status = await connection.execute(
|
|
223
|
+
"""
|
|
224
|
+
INSERT INTO "ActivityEventOutbox" ("id", "companyId", "source", "payload")
|
|
225
|
+
SELECT r."id", r."companyId", r."source", r."payload"
|
|
226
|
+
FROM jsonb_to_recordset($1::jsonb)
|
|
227
|
+
AS r("id" uuid, "companyId" text, "source" text, "payload" jsonb)
|
|
228
|
+
ON CONFLICT ("id") DO NOTHING""",
|
|
229
|
+
json_bytes(wire).decode("utf-8"),
|
|
230
|
+
)
|
|
231
|
+
return _affected(status)
|
|
232
|
+
|
|
233
|
+
async def claim(
|
|
234
|
+
self, claim_token: str, limit: int, lease_seconds: int
|
|
235
|
+
) -> list[ClaimedOutboxRow]:
|
|
236
|
+
"""Claims due rows for ``lease_seconds``. The UPDATE commits on its own, so no lock is
|
|
237
|
+
held while publishing."""
|
|
238
|
+
async with self._connection() as connection:
|
|
239
|
+
records = await connection.fetch(
|
|
240
|
+
"""
|
|
241
|
+
UPDATE "ActivityEventOutbox"
|
|
242
|
+
SET "claimToken" = $1::uuid,
|
|
243
|
+
"claimedUntil" = now() + $2::int * interval '1 second'
|
|
244
|
+
WHERE "id" IN (
|
|
245
|
+
SELECT "id" FROM "ActivityEventOutbox"
|
|
246
|
+
WHERE "nextAttemptAt" <= now()
|
|
247
|
+
AND ("claimedUntil" IS NULL OR "claimedUntil" < now())
|
|
248
|
+
ORDER BY "nextAttemptAt"
|
|
249
|
+
LIMIT $3::int
|
|
250
|
+
FOR UPDATE SKIP LOCKED
|
|
251
|
+
)
|
|
252
|
+
RETURNING "id"::text AS "id", "companyId", "source", "payload", "attempts"
|
|
253
|
+
""",
|
|
254
|
+
claim_token,
|
|
255
|
+
lease_seconds,
|
|
256
|
+
limit,
|
|
257
|
+
)
|
|
258
|
+
return [
|
|
259
|
+
ClaimedOutboxRow(
|
|
260
|
+
id=record["id"],
|
|
261
|
+
company_id=record["companyId"],
|
|
262
|
+
source=record["source"],
|
|
263
|
+
payload=json.loads(record["payload"]),
|
|
264
|
+
attempts=record["attempts"],
|
|
265
|
+
)
|
|
266
|
+
for record in records
|
|
267
|
+
]
|
|
268
|
+
|
|
269
|
+
async def delete_claimed(self, claim_token: str, ids: Sequence[str]) -> list[str]:
|
|
270
|
+
"""Fenced by ``claim_token``: a relay whose lease expired and was re-claimed deletes
|
|
271
|
+
nothing. Returns the ids it deleted."""
|
|
272
|
+
async with self._connection() as connection:
|
|
273
|
+
records = await connection.fetch(
|
|
274
|
+
"""
|
|
275
|
+
DELETE FROM "ActivityEventOutbox"
|
|
276
|
+
WHERE "claimToken" = $1::uuid AND "id" = ANY($2::uuid[])
|
|
277
|
+
RETURNING "id"::text AS "id"
|
|
278
|
+
""",
|
|
279
|
+
claim_token,
|
|
280
|
+
list(ids),
|
|
281
|
+
)
|
|
282
|
+
return [record["id"] for record in records]
|
|
283
|
+
|
|
284
|
+
async def reschedule_with_backoff(
|
|
285
|
+
self, claim_token: str, ids: Sequence[str], last_error: str
|
|
286
|
+
) -> list[int]:
|
|
287
|
+
"""Counts an attempt and backs off. Returns each rescheduled row's new attempt count."""
|
|
288
|
+
async with self._connection() as connection:
|
|
289
|
+
records = await connection.fetch(
|
|
290
|
+
"""
|
|
291
|
+
UPDATE "ActivityEventOutbox"
|
|
292
|
+
SET "attempts" = "attempts" + 1,
|
|
293
|
+
"nextAttemptAt" = now()
|
|
294
|
+
+ least(power(2, least("attempts", $4::int)), $5::int)
|
|
295
|
+
* (0.5 + random() * 0.5) * interval '1 second',
|
|
296
|
+
"claimedUntil" = NULL,
|
|
297
|
+
"claimToken" = NULL,
|
|
298
|
+
"lastError" = $3
|
|
299
|
+
WHERE "claimToken" = $1::uuid AND "id" = ANY($2::uuid[])
|
|
300
|
+
RETURNING "attempts"
|
|
301
|
+
""",
|
|
302
|
+
claim_token,
|
|
303
|
+
list(ids),
|
|
304
|
+
last_error,
|
|
305
|
+
_BACKOFF_EXPONENT_CEILING,
|
|
306
|
+
OUTBOX_MAX_BACKOFF_SECONDS,
|
|
307
|
+
)
|
|
308
|
+
return [record["attempts"] for record in records]
|
|
309
|
+
|
|
310
|
+
async def defer(
|
|
311
|
+
self, claim_token: str, ids: Sequence[str], delay_seconds: int
|
|
312
|
+
) -> int:
|
|
313
|
+
"""Releases rows for a later try without counting an attempt, jittered to 50-100 % of
|
|
314
|
+
the delay so rows deferred together do not all come due together."""
|
|
315
|
+
async with self._connection() as connection:
|
|
316
|
+
status = await connection.execute(
|
|
317
|
+
"""
|
|
318
|
+
UPDATE "ActivityEventOutbox"
|
|
319
|
+
SET "nextAttemptAt" = now() + $3::int * (0.5 + random() * 0.5) * interval '1 second',
|
|
320
|
+
"claimedUntil" = NULL,
|
|
321
|
+
"claimToken" = NULL
|
|
322
|
+
WHERE "claimToken" = $1::uuid AND "id" = ANY($2::uuid[])""",
|
|
323
|
+
claim_token,
|
|
324
|
+
list(ids),
|
|
325
|
+
delay_seconds,
|
|
326
|
+
)
|
|
327
|
+
return _affected(status)
|
|
328
|
+
|
|
329
|
+
async def stats(self) -> OutboxStats:
|
|
330
|
+
"""Row counts are capped at ``OUTBOX_STATS_ROW_CAP``; the oldest age reads the
|
|
331
|
+
``createdAt`` index."""
|
|
332
|
+
async with self._connection() as connection:
|
|
333
|
+
record = await connection.fetchrow(
|
|
334
|
+
"""
|
|
335
|
+
WITH sample AS (SELECT "attempts" FROM "ActivityEventOutbox" LIMIT $1::int)
|
|
336
|
+
SELECT (SELECT count(*) FROM sample)::int AS "pendingRows",
|
|
337
|
+
coalesce(extract(epoch FROM now() - (SELECT min("createdAt") FROM "ActivityEventOutbox")), 0)::float8
|
|
338
|
+
AS "oldestPendingAgeSeconds",
|
|
339
|
+
(SELECT count(*) FROM sample WHERE "attempts" >= $2::int)::int
|
|
340
|
+
AS "rowsAtMaxBackoff"
|
|
341
|
+
""",
|
|
342
|
+
OUTBOX_STATS_ROW_CAP,
|
|
343
|
+
OUTBOX_MAX_BACKOFF_ATTEMPTS,
|
|
344
|
+
)
|
|
345
|
+
assert record is not None
|
|
346
|
+
return OutboxStats(
|
|
347
|
+
pending_rows=record["pendingRows"],
|
|
348
|
+
oldest_pending_age_seconds=record["oldestPendingAgeSeconds"],
|
|
349
|
+
rows_at_max_backoff=record["rowsAtMaxBackoff"],
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
async def has_expected_columns(self) -> bool:
|
|
353
|
+
async with self._connection() as connection:
|
|
354
|
+
return await outbox_columns_match(connection)
|
{unique_toolkit-2026.48.0.dev12.dist-info → unique_toolkit-2026.48.0.dev13.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: unique-toolkit
|
|
3
|
-
Version: 2026.48.0.
|
|
3
|
+
Version: 2026.48.0.dev13
|
|
4
4
|
Summary:
|
|
5
5
|
Author: Cedric Klinkert, Martin Fadler, Sadique Sheik, Fabian Schläpfer, Pascal Hauri, Ejiroghene Oki-Peter, Rami Azouz, Ricardo Visini, Sanzio Monti
|
|
6
6
|
Author-email: Cedric Klinkert <cedric.klinkert@unique.ch>, Martin Fadler <martin.fadler@unique.ch>, Sadique Sheik <sadique@unique.ch>, Fabian Schläpfer <fabian@unique.ch>, Pascal Hauri <pascal@unique.ch>, Ejiroghene Oki-Peter <oki-peter.ejiroghene@unique.ai>, Rami Azouz <rami.ext@unique.ch>, Ricardo Visini <ricardo.visini@unique.ch>, Sanzio Monti <sanzio.monti@unique.ai>
|
|
@@ -16,7 +16,7 @@ Requires-Dist: sseclient>=0.0.27,<0.0.28
|
|
|
16
16
|
Requires-Dist: openai>=1.105.0,<3
|
|
17
17
|
Requires-Dist: platformdirs>=4.0.0,<5
|
|
18
18
|
Requires-Dist: pillow>=13.0.0
|
|
19
|
-
Requires-Dist: unique-sdk>=2026.48.0.
|
|
19
|
+
Requires-Dist: unique-sdk>=2026.48.0.dev13,<2026.48.0rc0
|
|
20
20
|
Requires-Dist: jambo>=0.1.2,<0.2
|
|
21
21
|
Requires-Dist: jinja2>=3.1.6,<4
|
|
22
22
|
Requires-Dist: docxtpl>=0.20.1,<0.21
|
|
@@ -34,6 +34,8 @@ Requires-Dist: pydantic-core>=2.41.5
|
|
|
34
34
|
Requires-Dist: cachetools>=5.0,<6
|
|
35
35
|
Requires-Dist: rapidfuzz>=3.0,<4
|
|
36
36
|
Requires-Dist: pyyaml>=6.0.3
|
|
37
|
+
Requires-Dist: asyncpg>=0.30,<1 ; extra == 'activity-records'
|
|
38
|
+
Requires-Dist: unique-toolkit[monitoring]>=2026.48.0.dev13,<2026.48.0rc0 ; extra == 'activity-records'
|
|
37
39
|
Requires-Dist: fastapi>=0.133.0,<1.0.0 ; extra == 'fastapi'
|
|
38
40
|
Requires-Dist: starlette>=1.3.1,<2.0.0 ; extra == 'fastapi'
|
|
39
41
|
Requires-Dist: uvicorn>=0.37.0,<0.38 ; extra == 'fastapi'
|
|
@@ -47,6 +49,7 @@ Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.27,<2 ; extra == 'otel'
|
|
|
47
49
|
Requires-Dist: opentelemetry-instrumentation-fastapi>=0.65b0,<1 ; extra == 'otel'
|
|
48
50
|
Requires-Dist: opentelemetry-instrumentation-requests>=0.65b0,<1 ; extra == 'otel'
|
|
49
51
|
Requires-Python: >=3.12
|
|
52
|
+
Provides-Extra: activity-records
|
|
50
53
|
Provides-Extra: fastapi
|
|
51
54
|
Provides-Extra: langchain
|
|
52
55
|
Provides-Extra: monitoring
|
{unique_toolkit-2026.48.0.dev12.dist-info → unique_toolkit-2026.48.0.dev13.dist-info}/RECORD
RENAMED
|
@@ -362,10 +362,12 @@ unique_toolkit/experimental/integrations/openai/streaming/event_routing/subscrib
|
|
|
362
362
|
unique_toolkit/experimental/integrations/openai/streaming/event_routing/subscribers/progress_log_persister.py,sha256=VCYGZY3WSpI7mvVs2gO89-M0JenakW01BGfBfFkPDrw,3499
|
|
363
363
|
unique_toolkit/experimental/resources/__init__.py,sha256=KdMPaaneY0twZ-JBfwImRjXZaWT68NVuOIeqdNXFh_Y,3377
|
|
364
364
|
unique_toolkit/experimental/resources/activity_records/__init__.py,sha256=QEvl-xjtN-5oQT6v1uPlKbnfJs5EHb4f7EDhOg6UyRU,375
|
|
365
|
-
unique_toolkit/experimental/resources/activity_records/config.py,sha256=
|
|
365
|
+
unique_toolkit/experimental/resources/activity_records/config.py,sha256=28n7zPCScbaPQid_yn_eYf99qKDMN5FW7Y2H09DRDK8,3060
|
|
366
366
|
unique_toolkit/experimental/resources/activity_records/json_size.py,sha256=gfIRmI08txf0Y_wEyPTqtYrUk9FHwSouYC4R7qtdgdY,9761
|
|
367
|
+
unique_toolkit/experimental/resources/activity_records/migrate.py,sha256=LNksBdPfwRG6Xm8krShI55qA7urK19932pcuAx1xGjM,2800
|
|
367
368
|
unique_toolkit/experimental/resources/activity_records/prepare.py,sha256=PKezBDYus3M6qZluI1Nh-oTpTjU44V37r9lN9dzILNc,10269
|
|
368
369
|
unique_toolkit/experimental/resources/activity_records/schemas.py,sha256=6-jbRHJrqOjbPp9ij1etpbZjKZ6ol-TiE60vdiDkqJA,6864
|
|
370
|
+
unique_toolkit/experimental/resources/activity_records/store.py,sha256=is-tESmoo-ox7nY6WrIOXdqe8UH1QsLTydoIXxtB8WA,13342
|
|
369
371
|
unique_toolkit/experimental/resources/content_folder/__init__.py,sha256=c5MUj1xIP10L7tcM4-hG2m1_yUMVfKr_jHAncUXVNvo,2492
|
|
370
372
|
unique_toolkit/experimental/resources/content_folder/functions.py,sha256=nJle9Qnh-x1SLNetBBhTbQPu-zEBfQaHFnMq8N9RGEQ,16692
|
|
371
373
|
unique_toolkit/experimental/resources/content_folder/schemas.py,sha256=LYWRpMLFVg_iKT9dw2AyCNfTPVmKeB8erMSsgbIkZ48,5345
|
|
@@ -440,6 +442,6 @@ unique_toolkit/short_term_memory/service.py,sha256=2JMBEBn6GoyK-a0xvdcWpPft-3C74
|
|
|
440
442
|
unique_toolkit/smart_rules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
441
443
|
unique_toolkit/smart_rules/compile.py,sha256=vRe0aMJWuVIK-VsqomgxQImzke7MDmwgSxxJfYCa7zw,1386
|
|
442
444
|
unique_toolkit/test_utilities/events.py,sha256=FLrhMh0A_mQutAUjoD0FdMcVQ4Gq31r35OVGzRjvLro,6760
|
|
443
|
-
unique_toolkit-2026.48.0.
|
|
444
|
-
unique_toolkit-2026.48.0.
|
|
445
|
-
unique_toolkit-2026.48.0.
|
|
445
|
+
unique_toolkit-2026.48.0.dev13.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
|
|
446
|
+
unique_toolkit-2026.48.0.dev13.dist-info/METADATA,sha256=xzzKfQLydSIU4RmT7SSzggZ5RJlF8-t-u72x0KPhHMc,8021
|
|
447
|
+
unique_toolkit-2026.48.0.dev13.dist-info/RECORD,,
|
|
File without changes
|