@hotmeshio/hotmesh 0.32.0 → 0.33.0
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.
- package/build/package.json +1 -1
- package/build/services/dba/index.d.ts +86 -0
- package/build/services/dba/index.js +119 -0
- package/build/services/dba/retention/batch.d.ts +7 -0
- package/build/services/dba/retention/batch.js +170 -0
- package/build/services/dba/retention/index.d.ts +4 -0
- package/build/services/dba/retention/index.js +12 -0
- package/build/services/dba/retention/overview.d.ts +6 -0
- package/build/services/dba/retention/overview.js +52 -0
- package/build/services/dba/retention/pressure.d.ts +9 -0
- package/build/services/dba/retention/pressure.js +58 -0
- package/build/services/dba/retention/session.d.ts +25 -0
- package/build/services/dba/retention/session.js +87 -0
- package/build/services/dba/retention/sql.d.ts +55 -0
- package/build/services/dba/retention/sql.js +188 -0
- package/build/services/dba/retention/survey.d.ts +6 -0
- package/build/services/dba/retention/survey.js +289 -0
- package/build/services/escalations/client.d.ts +4 -0
- package/build/services/escalations/client.js +4 -0
- package/build/types/dba.d.ts +3 -0
- package/build/types/index.d.ts +1 -0
- package/build/types/retention.d.ts +282 -0
- package/build/types/retention.js +2 -0
- package/package.json +1 -1
package/build/types/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { CacheMode } from './cache';
|
|
|
6
6
|
export { CollationFaultType, CollationStage } from './collator';
|
|
7
7
|
export { ActivityConfig, DurableActivityContext, WorkflowOutboundCallsInterceptor, WorkflowOutboundCallsInterceptorContext, ActivityInboundCallsInterceptor, ActivityWorkflowDataType, ChildResponseType, ClientConfig, ClientWorkflow, ContextType, Connection, ProxyResponseType, ProxyType, Registry, SignalOptions, FindJobsOptions, FindOptions, FindWhereOptions, FindWhereQuery, HookOptions, SearchResults, WorkflowConfig, WorkerConfig, WorkerOptions, WorkflowContext, WorkflowSearchOptions, WorkflowSearchSchema, WorkflowDataType, WorkflowOptions, WorkflowInboundCallsInterceptor, InterceptorRegistry, } from './durable';
|
|
8
8
|
export { PruneOptions, PruneResult, } from './dba';
|
|
9
|
+
export { DeleteRetentionBatchOptions, ReadRetentionOverviewOptions, ReadRetentionPressureOptions, RetentionApp, RetentionAttributeEstimate, RetentionBatchResult, RetentionCriteria, RetentionEscalationReference, RetentionEntityCount, RetentionHealth, RetentionHistogramBucket, RetentionLongTransaction, RetentionOverview, RetentionPressure, RetentionProtectedCounts, RetentionReplicationSlot, RetentionSurvey, RetentionTableStats, RetentionTarget, RetentionTargetOverview, RetentionTargetSurvey, RetentionWatermark, SurveyRetentionOptions, } from './retention';
|
|
9
10
|
export { DurableChildErrorType, DurableProxyErrorType, DurableSleepErrorType, DurableWaitForAllErrorType, DurableWaitForErrorType, } from './error';
|
|
10
11
|
export { ActivityAction, ActivityDetail, ActivityInputMap, ActivityTaskCompletedAttributes, ActivityTaskFailedAttributes, ActivityTaskScheduledAttributes, ChildWorkflowExecutionCompletedAttributes, ChildWorkflowExecutionFailedAttributes, ChildWorkflowExecutionStartedAttributes, DependencyExport, DurableJobExport, ExecutionExportOptions, ExportCycles, ExportFields, ExportItem, ExportMode, ExportOptions, ExportTransitions, JobAction, JobActionExport, JobAttributesRow, JobExport, JobRow, JobTimeline, StreamHistoryEntry, TimelineType, TimerFiredAttributes, TimerStartedAttributes, TransitionType, WorkflowEventAttributes, WorkflowEventCategory, WorkflowEventType, WorkflowExecution, WorkflowExecutionCompletedAttributes, WorkflowExecutionEvent, WorkflowExecutionFailedAttributes, WorkflowExecutionSignaledAttributes, WorkflowExecutionStartedAttributes, WorkflowExecutionStatus, WorkflowExecutionSummary, } from './exporter';
|
|
11
12
|
export { HookCondition, HookConditions, HookGate, HookInterface, HookRule, HookRules, HookSignal, } from './hook';
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { PostgresClientType } from './postgres';
|
|
2
|
+
/**
|
|
3
|
+
* A table family that accumulates rows once work completes.
|
|
4
|
+
*
|
|
5
|
+
* - `jobs` — completed jobs and their `jobs_attributes` rows
|
|
6
|
+
* - `engine_streams` — processed engine stream messages
|
|
7
|
+
* - `worker_streams` — processed worker stream messages
|
|
8
|
+
* - `escalations` — ended (`resolved`, `cancelled`, `expired`) rows of
|
|
9
|
+
* `public.hmsh_escalations` for the app
|
|
10
|
+
*/
|
|
11
|
+
export type RetentionTarget = 'jobs' | 'engine_streams' | 'worker_streams' | 'escalations';
|
|
12
|
+
/**
|
|
13
|
+
* A table outside the engine that holds escalation ids. An escalation is
|
|
14
|
+
* kept while any row here names it with `openColumn` still null, such as an
|
|
15
|
+
* outcome a relay has yet to deliver. Identifiers are plain SQL names.
|
|
16
|
+
*/
|
|
17
|
+
export interface RetentionEscalationReference {
|
|
18
|
+
/** Schema-qualified table, e.g. `public.lt_durable_waits`. */
|
|
19
|
+
table: string;
|
|
20
|
+
/** Column holding the escalation id. */
|
|
21
|
+
column: string;
|
|
22
|
+
/** Column that is null while the reference is still open, e.g. `delivered_at`. */
|
|
23
|
+
openColumn: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Which rows of one target are in scope. Every bound is an absolute
|
|
27
|
+
* timestamp, so a survey and the batches that follow it select the
|
|
28
|
+
* same rows no matter when each one runs.
|
|
29
|
+
*/
|
|
30
|
+
export interface RetentionCriteria {
|
|
31
|
+
target: RetentionTarget;
|
|
32
|
+
/**
|
|
33
|
+
* Rows completed (jobs), processed (streams) or ended (escalations)
|
|
34
|
+
* strictly before this instant are in scope. ISO 8601 or a Postgres
|
|
35
|
+
* timestamptz literal.
|
|
36
|
+
*/
|
|
37
|
+
before: string;
|
|
38
|
+
/**
|
|
39
|
+
* The instant the scope was frozen. A job is in scope only when its
|
|
40
|
+
* engine retention (`expired_at`) ended before this instant.
|
|
41
|
+
* Defaults to the database clock when the call runs.
|
|
42
|
+
*/
|
|
43
|
+
asOf?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Streams only. Dead-lettered messages are kept unless this is true.
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
includeDeadLettered?: boolean;
|
|
49
|
+
/** Escalations only. Keep escalations still named by an open reference. */
|
|
50
|
+
references?: RetentionEscalationReference[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Position of the last row a batch visited. Batches walk each target
|
|
54
|
+
* oldest first; passing the previous watermark continues the walk
|
|
55
|
+
* without revisiting rows that were kept.
|
|
56
|
+
*/
|
|
57
|
+
export interface RetentionWatermark {
|
|
58
|
+
/** `expired_at` of the last visited row, at full database precision. */
|
|
59
|
+
at: string;
|
|
60
|
+
/** Job id, or stream message id. */
|
|
61
|
+
id: string;
|
|
62
|
+
/** Stream name (streams only). */
|
|
63
|
+
stream?: string;
|
|
64
|
+
}
|
|
65
|
+
/** Rows a survey found in scope but kept, by reason. */
|
|
66
|
+
export interface RetentionProtectedCounts {
|
|
67
|
+
/** Jobs still running (`expired_at` not yet set). */
|
|
68
|
+
open?: number;
|
|
69
|
+
/** Completed jobs whose engine retention has not ended. */
|
|
70
|
+
inRetention?: number;
|
|
71
|
+
/** Jobs completed on or after `before`. */
|
|
72
|
+
newerThanCutoff?: number;
|
|
73
|
+
/** Jobs whose workflow has a pending escalation. */
|
|
74
|
+
pendingEscalation?: number;
|
|
75
|
+
/** Jobs whose root or parent workflow is still running. */
|
|
76
|
+
openOrigin?: number;
|
|
77
|
+
/** Streams: messages processed on or after `before`. */
|
|
78
|
+
newerThanCutoffMessages?: number;
|
|
79
|
+
/** Streams: dead-lettered messages kept by default. */
|
|
80
|
+
deadLettered?: number;
|
|
81
|
+
/** Streams: messages not yet processed. */
|
|
82
|
+
unprocessed?: number;
|
|
83
|
+
/** Escalations: rows still pending (never eligible). */
|
|
84
|
+
pending?: number;
|
|
85
|
+
/** Escalations: ended on or after `before`. */
|
|
86
|
+
newerThanCutoffEnded?: number;
|
|
87
|
+
/** Escalations: named by an open reference (see `references`). */
|
|
88
|
+
openReference?: number;
|
|
89
|
+
}
|
|
90
|
+
export interface RetentionHistogramBucket {
|
|
91
|
+
/** Start of the bucket (ISO 8601). */
|
|
92
|
+
bucket: string;
|
|
93
|
+
count: number;
|
|
94
|
+
}
|
|
95
|
+
export interface RetentionEntityCount {
|
|
96
|
+
entity: string | null;
|
|
97
|
+
count: number;
|
|
98
|
+
}
|
|
99
|
+
/** Storage statistics summed over a table's partitions. */
|
|
100
|
+
export interface RetentionTableStats {
|
|
101
|
+
table: string;
|
|
102
|
+
liveRows: number;
|
|
103
|
+
deadRows: number;
|
|
104
|
+
totalBytes: number;
|
|
105
|
+
indexBytes: number;
|
|
106
|
+
lastAutovacuum: string | null;
|
|
107
|
+
lastAutoanalyze: string | null;
|
|
108
|
+
}
|
|
109
|
+
export interface RetentionAttributeEstimate {
|
|
110
|
+
/** Attribute rows that would be deleted with the eligible jobs. */
|
|
111
|
+
rows: number;
|
|
112
|
+
/** True when counted; false when projected from a sample. */
|
|
113
|
+
exact: boolean;
|
|
114
|
+
/** Mean attribute rows per eligible job. */
|
|
115
|
+
perJob: number;
|
|
116
|
+
/** Jobs inspected to produce the figure. */
|
|
117
|
+
sampled: number;
|
|
118
|
+
}
|
|
119
|
+
export interface RetentionTargetSurvey {
|
|
120
|
+
target: RetentionTarget;
|
|
121
|
+
before: string;
|
|
122
|
+
asOf: string;
|
|
123
|
+
includeDeadLettered: boolean;
|
|
124
|
+
/** Rows that a batch walk would delete. */
|
|
125
|
+
eligible: number;
|
|
126
|
+
/** Completion (jobs) or processing (streams) time of the oldest eligible row. */
|
|
127
|
+
oldest: string | null;
|
|
128
|
+
/** Completion (jobs) or processing (streams) time of the newest eligible row. */
|
|
129
|
+
newest: string | null;
|
|
130
|
+
protected: RetentionProtectedCounts;
|
|
131
|
+
histogram: RetentionHistogramBucket[];
|
|
132
|
+
/** Jobs only: eligible jobs by entity, largest first. */
|
|
133
|
+
byEntity?: RetentionEntityCount[];
|
|
134
|
+
/** Escalations only: eligible rows by role, largest first (in `entity`). */
|
|
135
|
+
byRole?: RetentionEntityCount[];
|
|
136
|
+
/** Jobs only. */
|
|
137
|
+
attributes?: RetentionAttributeEstimate;
|
|
138
|
+
/** Projected bytes held by eligible rows (heap and indexes). */
|
|
139
|
+
estimatedBytes: number;
|
|
140
|
+
tables: RetentionTableStats[];
|
|
141
|
+
}
|
|
142
|
+
export interface RetentionReplicationSlot {
|
|
143
|
+
name: string;
|
|
144
|
+
plugin: string | null;
|
|
145
|
+
active: boolean;
|
|
146
|
+
/** Bytes of WAL the slot still holds; null when not readable. */
|
|
147
|
+
lagBytes: number | null;
|
|
148
|
+
}
|
|
149
|
+
export interface RetentionLongTransaction {
|
|
150
|
+
pid: number;
|
|
151
|
+
seconds: number;
|
|
152
|
+
state: string | null;
|
|
153
|
+
query: string | null;
|
|
154
|
+
}
|
|
155
|
+
export interface RetentionHealth {
|
|
156
|
+
serverVersion: string;
|
|
157
|
+
/** Unprocessed stream messages (the engine backlog). */
|
|
158
|
+
backlog: {
|
|
159
|
+
engine: number;
|
|
160
|
+
worker: number;
|
|
161
|
+
};
|
|
162
|
+
replicationSlots: RetentionReplicationSlot[] | null;
|
|
163
|
+
longTransactions: RetentionLongTransaction[] | null;
|
|
164
|
+
}
|
|
165
|
+
export interface RetentionSurvey {
|
|
166
|
+
appId: string;
|
|
167
|
+
schema: string;
|
|
168
|
+
surveyedAt: string;
|
|
169
|
+
targets: RetentionTargetSurvey[];
|
|
170
|
+
health: RetentionHealth;
|
|
171
|
+
}
|
|
172
|
+
export interface SurveyRetentionOptions {
|
|
173
|
+
appId: string;
|
|
174
|
+
/** A connected client. The caller owns its lifetime. */
|
|
175
|
+
client: PostgresClientType;
|
|
176
|
+
criteria: RetentionCriteria[];
|
|
177
|
+
/** Histogram bucket width. @default 'week' */
|
|
178
|
+
bucket?: 'day' | 'week' | 'month';
|
|
179
|
+
/**
|
|
180
|
+
* Count attribute rows exactly at or below this many eligible jobs;
|
|
181
|
+
* project from a sample above it. @default 5000
|
|
182
|
+
*/
|
|
183
|
+
exactAttributeJobs?: number;
|
|
184
|
+
/** Jobs sampled for the attribute projection. @default 500 */
|
|
185
|
+
attributeSampleJobs?: number;
|
|
186
|
+
/** Per-statement timeout for survey queries. @default 120000 */
|
|
187
|
+
statementTimeoutMs?: number;
|
|
188
|
+
}
|
|
189
|
+
export interface DeleteRetentionBatchOptions {
|
|
190
|
+
appId: string;
|
|
191
|
+
/** A connected client, not inside a transaction. The caller owns its lifetime. */
|
|
192
|
+
client: PostgresClientType;
|
|
193
|
+
/** `asOf` is required so every batch of a walk shares one frozen scope. */
|
|
194
|
+
criteria: RetentionCriteria & {
|
|
195
|
+
asOf: string;
|
|
196
|
+
};
|
|
197
|
+
/** Continue after this row. Omit to start from the oldest. */
|
|
198
|
+
after?: RetentionWatermark | null;
|
|
199
|
+
/** Maximum jobs (with their attributes) or stream messages to delete. */
|
|
200
|
+
limit: number;
|
|
201
|
+
/**
|
|
202
|
+
* Rows completed (jobs) or processed (streams) within this many days of
|
|
203
|
+
* the database clock are never deleted, whatever `before` says. A second
|
|
204
|
+
* guard inside the query, so a caller bug cannot reach younger rows.
|
|
205
|
+
* @default 0
|
|
206
|
+
*/
|
|
207
|
+
minimumAgeDays?: number;
|
|
208
|
+
/** @default 2000 */
|
|
209
|
+
lockTimeoutMs?: number;
|
|
210
|
+
/** @default 30000 */
|
|
211
|
+
statementTimeoutMs?: number;
|
|
212
|
+
/**
|
|
213
|
+
* Run the batch and roll it back. Measures cost without deleting.
|
|
214
|
+
* @default false
|
|
215
|
+
*/
|
|
216
|
+
rehearse?: boolean;
|
|
217
|
+
}
|
|
218
|
+
export interface RetentionBatchResult {
|
|
219
|
+
target: RetentionTarget;
|
|
220
|
+
/** Jobs or stream messages deleted (or that would be, when rehearsed). */
|
|
221
|
+
deleted: number;
|
|
222
|
+
/** Jobs only: attribute rows deleted with them. */
|
|
223
|
+
attributesDeleted: number;
|
|
224
|
+
/** Last visited row; pass as `after` to continue. */
|
|
225
|
+
watermark: RetentionWatermark | null;
|
|
226
|
+
/** True when fewer than `limit` rows remained in scope. */
|
|
227
|
+
done: boolean;
|
|
228
|
+
rehearsed: boolean;
|
|
229
|
+
/** Wall time of the transaction in milliseconds. */
|
|
230
|
+
ms: number;
|
|
231
|
+
}
|
|
232
|
+
export interface ReadRetentionPressureOptions {
|
|
233
|
+
appId: string;
|
|
234
|
+
client: PostgresClientType;
|
|
235
|
+
/** Count sessions waiting on locks held by this backend pid. */
|
|
236
|
+
blockerPid?: number;
|
|
237
|
+
}
|
|
238
|
+
/** Signals a caller checks between batches to decide whether to slow down. */
|
|
239
|
+
export interface RetentionPressure {
|
|
240
|
+
backlog: {
|
|
241
|
+
engine: number;
|
|
242
|
+
worker: number;
|
|
243
|
+
};
|
|
244
|
+
/** Largest WAL lag across replication slots; null when not readable. */
|
|
245
|
+
maxReplicationLagBytes: number | null;
|
|
246
|
+
/** Sessions waiting on `blockerPid`; 0 when not requested. */
|
|
247
|
+
blockedSessions: number;
|
|
248
|
+
/** Dead rows summed per target table. */
|
|
249
|
+
deadRows: Record<RetentionTarget, number>;
|
|
250
|
+
readAt: string;
|
|
251
|
+
}
|
|
252
|
+
/** A HotMesh app schema that holds jobs and stream tables. */
|
|
253
|
+
export interface RetentionApp {
|
|
254
|
+
schema: string;
|
|
255
|
+
tables: RetentionTarget[];
|
|
256
|
+
}
|
|
257
|
+
export interface ReadRetentionOverviewOptions {
|
|
258
|
+
appId: string;
|
|
259
|
+
client: PostgresClientType;
|
|
260
|
+
}
|
|
261
|
+
/** A cheap, index-only look at one target. */
|
|
262
|
+
export interface RetentionTargetOverview {
|
|
263
|
+
target: RetentionTarget;
|
|
264
|
+
/**
|
|
265
|
+
* Jobs: completion time of the finished job whose engine retention ends
|
|
266
|
+
* first. Streams: processing time of the oldest processed message.
|
|
267
|
+
* Null when the table holds none.
|
|
268
|
+
*/
|
|
269
|
+
oldest: string | null;
|
|
270
|
+
tables: RetentionTableStats[];
|
|
271
|
+
}
|
|
272
|
+
/** Sizes and oldest ages for every target, read from indexes and statistics. */
|
|
273
|
+
export interface RetentionOverview {
|
|
274
|
+
appId: string;
|
|
275
|
+
schema: string;
|
|
276
|
+
readAt: string;
|
|
277
|
+
targets: RetentionTargetOverview[];
|
|
278
|
+
backlog: {
|
|
279
|
+
engine: number;
|
|
280
|
+
worker: number;
|
|
281
|
+
};
|
|
282
|
+
}
|