@xeonr/pipelines-sdk 0.1.0 → 0.3.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.
Files changed (106) hide show
  1. package/README.md +247 -24
  2. package/dist/client.d.ts +73 -3
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +48 -1
  5. package/dist/client.js.map +1 -1
  6. package/dist/errors.d.ts +42 -6
  7. package/dist/errors.d.ts.map +1 -1
  8. package/dist/errors.js +45 -2
  9. package/dist/errors.js.map +1 -1
  10. package/dist/gen/xeonr/pipelines/private/v1/attempt_pb.d.ts +173 -12
  11. package/dist/gen/xeonr/pipelines/private/v1/attempt_pb.d.ts.map +1 -1
  12. package/dist/gen/xeonr/pipelines/private/v1/attempt_pb.js +45 -28
  13. package/dist/gen/xeonr/pipelines/private/v1/attempt_pb.js.map +1 -1
  14. package/dist/gen/xeonr/pipelines/private/v1/step_local_pb.d.ts +136 -17
  15. package/dist/gen/xeonr/pipelines/private/v1/step_local_pb.d.ts.map +1 -1
  16. package/dist/gen/xeonr/pipelines/private/v1/step_local_pb.js +42 -35
  17. package/dist/gen/xeonr/pipelines/private/v1/step_local_pb.js.map +1 -1
  18. package/dist/gen/xeonr/pipelines/private/v1/worker_pb.d.ts +346 -15
  19. package/dist/gen/xeonr/pipelines/private/v1/worker_pb.d.ts.map +1 -1
  20. package/dist/gen/xeonr/pipelines/private/v1/worker_pb.js +105 -10
  21. package/dist/gen/xeonr/pipelines/private/v1/worker_pb.js.map +1 -1
  22. package/dist/gen/xeonr/pipelines/v1/common_pb.d.ts +38 -6
  23. package/dist/gen/xeonr/pipelines/v1/common_pb.d.ts.map +1 -1
  24. package/dist/gen/xeonr/pipelines/v1/common_pb.js +37 -5
  25. package/dist/gen/xeonr/pipelines/v1/common_pb.js.map +1 -1
  26. package/dist/gen/xeonr/pipelines/v1/definition_pb.d.ts +280 -5
  27. package/dist/gen/xeonr/pipelines/v1/definition_pb.d.ts.map +1 -1
  28. package/dist/gen/xeonr/pipelines/v1/definition_pb.js +100 -7
  29. package/dist/gen/xeonr/pipelines/v1/definition_pb.js.map +1 -1
  30. package/dist/gen/xeonr/pipelines/v1/pipelines_pb.d.ts +1100 -0
  31. package/dist/gen/xeonr/pipelines/v1/pipelines_pb.d.ts.map +1 -0
  32. package/dist/gen/xeonr/pipelines/v1/pipelines_pb.js +298 -0
  33. package/dist/gen/xeonr/pipelines/v1/pipelines_pb.js.map +1 -0
  34. package/dist/gen/xeonr/pipelines/v1/pools_pb.d.ts +120 -1
  35. package/dist/gen/xeonr/pipelines/v1/pools_pb.d.ts.map +1 -1
  36. package/dist/gen/xeonr/pipelines/v1/pools_pb.js +36 -11
  37. package/dist/gen/xeonr/pipelines/v1/pools_pb.js.map +1 -1
  38. package/dist/gen/xeonr/pipelines/v1/queues_pb.d.ts +769 -0
  39. package/dist/gen/xeonr/pipelines/v1/queues_pb.d.ts.map +1 -0
  40. package/dist/gen/xeonr/pipelines/v1/queues_pb.js +190 -0
  41. package/dist/gen/xeonr/pipelines/v1/queues_pb.js.map +1 -0
  42. package/dist/gen/xeonr/pipelines/v1/registry_pb.d.ts +60 -0
  43. package/dist/gen/xeonr/pipelines/v1/registry_pb.d.ts.map +1 -1
  44. package/dist/gen/xeonr/pipelines/v1/registry_pb.js +21 -16
  45. package/dist/gen/xeonr/pipelines/v1/registry_pb.js.map +1 -1
  46. package/dist/gen/xeonr/pipelines/v1/runs_pb.d.ts +867 -4
  47. package/dist/gen/xeonr/pipelines/v1/runs_pb.d.ts.map +1 -1
  48. package/dist/gen/xeonr/pipelines/v1/runs_pb.js +243 -27
  49. package/dist/gen/xeonr/pipelines/v1/runs_pb.js.map +1 -1
  50. package/dist/gen/xeonr/pipelines/v1/schedules_pb.d.ts +1110 -0
  51. package/dist/gen/xeonr/pipelines/v1/schedules_pb.d.ts.map +1 -0
  52. package/dist/gen/xeonr/pipelines/v1/schedules_pb.js +295 -0
  53. package/dist/gen/xeonr/pipelines/v1/schedules_pb.js.map +1 -0
  54. package/dist/gen/xeonr/pipelines/v1/secrets_pb.d.ts +8 -3
  55. package/dist/gen/xeonr/pipelines/v1/secrets_pb.d.ts.map +1 -1
  56. package/dist/gen/xeonr/pipelines/v1/secrets_pb.js +1 -1
  57. package/dist/gen/xeonr/pipelines/v1/secrets_pb.js.map +1 -1
  58. package/dist/gen/xeonr/platform/v1/options_pb.d.ts +123 -1
  59. package/dist/gen/xeonr/platform/v1/options_pb.d.ts.map +1 -1
  60. package/dist/gen/xeonr/platform/v1/options_pb.js +90 -1
  61. package/dist/gen/xeonr/platform/v1/options_pb.js.map +1 -1
  62. package/dist/handler.d.ts +50 -0
  63. package/dist/handler.d.ts.map +1 -1
  64. package/dist/handler.js +27 -0
  65. package/dist/handler.js.map +1 -1
  66. package/dist/index.d.ts +13 -1
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +7 -1
  69. package/dist/index.js.map +1 -1
  70. package/dist/logship.d.ts +60 -10
  71. package/dist/logship.d.ts.map +1 -1
  72. package/dist/logship.js +171 -28
  73. package/dist/logship.js.map +1 -1
  74. package/dist/queues.d.ts +171 -0
  75. package/dist/queues.d.ts.map +1 -0
  76. package/dist/queues.js +135 -0
  77. package/dist/queues.js.map +1 -0
  78. package/dist/reporter.d.ts +120 -0
  79. package/dist/reporter.d.ts.map +1 -0
  80. package/dist/reporter.js +323 -0
  81. package/dist/reporter.js.map +1 -0
  82. package/dist/schedules.d.ts +201 -0
  83. package/dist/schedules.d.ts.map +1 -0
  84. package/dist/schedules.js +127 -0
  85. package/dist/schedules.js.map +1 -0
  86. package/dist/testing/cron.d.ts +33 -0
  87. package/dist/testing/cron.d.ts.map +1 -0
  88. package/dist/testing/cron.js +177 -0
  89. package/dist/testing/cron.js.map +1 -0
  90. package/dist/testing/index.d.ts +142 -4
  91. package/dist/testing/index.d.ts.map +1 -1
  92. package/dist/testing/index.js +843 -44
  93. package/dist/testing/index.js.map +1 -1
  94. package/dist/testing/queues.d.ts +46 -0
  95. package/dist/testing/queues.d.ts.map +1 -0
  96. package/dist/testing/queues.js +70 -0
  97. package/dist/testing/queues.js.map +1 -0
  98. package/dist/testing/schedules.d.ts +113 -0
  99. package/dist/testing/schedules.d.ts.map +1 -0
  100. package/dist/testing/schedules.js +419 -0
  101. package/dist/testing/schedules.js.map +1 -0
  102. package/dist/worker.d.ts +78 -8
  103. package/dist/worker.d.ts.map +1 -1
  104. package/dist/worker.js +163 -33
  105. package/dist/worker.js.map +1 -1
  106. package/package.json +1 -1
@@ -0,0 +1,120 @@
1
+ import type { JsonObject } from "@bufbuild/protobuf";
2
+ import type { Client } from "@connectrpc/connect";
3
+ import type { AttemptRef, WorkerService } from "./gen/xeonr/pipelines/private/v1/worker_pb.js";
4
+ /** A stage of a handler's work, declared in its manifest. */
5
+ export interface StageDef {
6
+ /** `^[a-z][a-z0-9_.-]{0,63}$`; unique in the handler. */
7
+ key: string;
8
+ /** What a person reads ("Reading folders"). */
9
+ name: string;
10
+ /** Its share of the overall progress. Default 1. */
11
+ weight?: number;
12
+ }
13
+ /** Item counts and a note, for `ctx.progress`. */
14
+ export interface ProgressUpdate {
15
+ processed?: number;
16
+ /** Zero or unset is unknown. */
17
+ total?: number;
18
+ failed?: number;
19
+ /** 0 to 1; derived from processed / total when unset and total is known. */
20
+ fraction?: number;
21
+ /** What the handler is doing now (at most 255 characters). */
22
+ message?: string;
23
+ }
24
+ /** One issue: a structured, non-fatal problem with an item of the work. */
25
+ export interface IssueInput {
26
+ severity?: "info" | "warning" | "error";
27
+ /** The human-readable thing it is about ("The Matrix (1999)/movie.mkv"). */
28
+ subject?: string;
29
+ /** The product's machine handle for it, for a deep link. */
30
+ subjectKind?: string;
31
+ subjectId?: string;
32
+ /** One sentence that stands on its own. */
33
+ message: string;
34
+ /** Anything more, as JSON; at most 16 KiB. */
35
+ detail?: JsonObject;
36
+ }
37
+ /** A span in progress, from `ctx.span`. */
38
+ export interface SpanHandle {
39
+ readonly traceId: string;
40
+ readonly spanId: string;
41
+ setAttribute(key: string, value: string | number | boolean): void;
42
+ /** Runs `fn` inside a child span. */
43
+ span<T>(name: string, fn: (span: SpanHandle) => Promise<T> | T, attributes?: JsonObject): Promise<T>;
44
+ }
45
+ /** What a reporter needs from its worker. */
46
+ export interface ReporterDeps {
47
+ api: Client<typeof WorkerService>;
48
+ ref: AttemptRef;
49
+ stages: readonly StageDef[];
50
+ debug: (message: string, fields?: Record<string, unknown>) => void;
51
+ /** How often progress, issues and spans are sent at most. Default 1 s. */
52
+ intervalMs?: number;
53
+ }
54
+ /**
55
+ * Reports an attempt's progress, issues and spans on the worker surface
56
+ * (`SetProgress`, `AppendIssues`, `ReportSpans`).
57
+ *
58
+ * - Progress is coalesced: the latest value about once a second, and the
59
+ * last one before the attempt completes ({@link finish}). A stage change is
60
+ * sent at once, in order.
61
+ * - Issues are batched (up to 100 a call) and spans too (up to 1000).
62
+ * - Nothing here can fail the handler: every error is logged at debug and
63
+ * dropped. `failed_precondition` (the attempt is no longer this worker's)
64
+ * stops all reporting; the heartbeat deals with the attempt itself.
65
+ */
66
+ export declare class AttemptReporter {
67
+ private readonly api;
68
+ private readonly ref;
69
+ private readonly declared;
70
+ private readonly interval;
71
+ private readonly debug;
72
+ private stopped;
73
+ private chain;
74
+ private stageKey;
75
+ private stageName;
76
+ private progressState;
77
+ private reported;
78
+ private dirty;
79
+ private lastSent;
80
+ private progressTimer;
81
+ private issues;
82
+ private spans;
83
+ private batchTimer;
84
+ readonly traceId: string;
85
+ constructor(deps: ReporterDeps);
86
+ /** The stage the attempt is in, or "" before any. */
87
+ get stage(): string;
88
+ /**
89
+ * Enters a stage (finishing the one before), or moves the current one to
90
+ * `state`. A key the manifest does not declare is added at run time with
91
+ * weight 0, named `name` (default the key).
92
+ */
93
+ setStage(key: string, opts?: {
94
+ name?: string;
95
+ state?: "running" | "succeeded" | "failed" | "skipped";
96
+ message?: string;
97
+ }): void;
98
+ /** Reports progress within the current stage (or the attempt). Coalesced. */
99
+ progress(update: ProgressUpdate): void;
100
+ /** Queues an issue. Batched. */
101
+ issue(input: IssueInput): void;
102
+ /** Runs `fn` inside a span of this attempt's trace. */
103
+ span<T>(name: string, fn: (span: SpanHandle) => Promise<T> | T, attributes?: JsonObject, parent?: string): Promise<T>;
104
+ /**
105
+ * The last reports before CompleteAttempt: the current stage finished as
106
+ * `outcome`, pending progress, issues and spans, waiting at most
107
+ * `timeoutMs`. Never throws.
108
+ */
109
+ finish(outcome: "succeeded" | "failed", timeoutMs: number): Promise<void>;
110
+ /** Stops reporting; nothing more is sent. */
111
+ stop(): void;
112
+ private flushProgress;
113
+ private progressRequest;
114
+ private armBatches;
115
+ private flushBatches;
116
+ private send;
117
+ /** Sends in order, one call at a time; failures are dropped. */
118
+ private enqueue;
119
+ }
120
+ //# sourceMappingURL=reporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reporter.d.ts","sourceRoot":"","sources":["../src/reporter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAoB,MAAM,oBAAoB,CAAC;AAEvE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAIlD,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAyC,MAAM,+CAA+C,CAAC;AAGtI,6DAA6D;AAC7D,MAAM,WAAW,QAAQ;IACvB,yDAAyD;IACzD,GAAG,EAAE,MAAM,CAAC;IACZ,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,kDAAkD;AAClD,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gCAAgC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAC;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,OAAO,CAAC,CAAC,CAAC;IAwCjH;;;;OAIG;IACG,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB/E,6CAA6C;IAC7C,IAAI,IAAI,IAAI;IASZ,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,eAAe;IAgBvB,OAAO,CAAC,UAAU;IASlB,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,IAAI;IAKZ,gEAAgE;IAChE,OAAO,CAAC,OAAO;CAYhB"}
@@ -0,0 +1,323 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { timestampFromMs } from "@bufbuild/protobuf/wkt";
3
+ import { errorKind } from "./errors.js";
4
+ import { IssueSeverity } from "./gen/xeonr/pipelines/private/v1/attempt_pb.js";
5
+ import { StageState } from "./gen/xeonr/pipelines/v1/runs_pb.js";
6
+ const STAGE_KEY = /^[a-z][a-z0-9_.-]{0,63}$/;
7
+ const SUBJECT_KIND = /^[a-z0-9][a-z0-9._-]*$/;
8
+ const MAX_COUNT = 1_000_000_000_000;
9
+ const encoder = new TextEncoder();
10
+ /**
11
+ * Reports an attempt's progress, issues and spans on the worker surface
12
+ * (`SetProgress`, `AppendIssues`, `ReportSpans`).
13
+ *
14
+ * - Progress is coalesced: the latest value about once a second, and the
15
+ * last one before the attempt completes ({@link finish}). A stage change is
16
+ * sent at once, in order.
17
+ * - Issues are batched (up to 100 a call) and spans too (up to 1000).
18
+ * - Nothing here can fail the handler: every error is logged at debug and
19
+ * dropped. `failed_precondition` (the attempt is no longer this worker's)
20
+ * stops all reporting; the heartbeat deals with the attempt itself.
21
+ */
22
+ export class AttemptReporter {
23
+ api;
24
+ ref;
25
+ declared;
26
+ interval;
27
+ debug;
28
+ stopped = false;
29
+ chain = Promise.resolve();
30
+ stageKey = "";
31
+ stageName = "";
32
+ progressState = {
33
+ processed: 0,
34
+ total: 0,
35
+ failed: 0,
36
+ fraction: undefined,
37
+ message: "",
38
+ };
39
+ reported = false;
40
+ dirty = false;
41
+ lastSent = 0;
42
+ progressTimer;
43
+ issues = [];
44
+ spans = [];
45
+ batchTimer;
46
+ traceId = randomBytes(16).toString("hex");
47
+ constructor(deps) {
48
+ this.api = deps.api;
49
+ this.ref = deps.ref;
50
+ this.declared = new Map(deps.stages.map((s) => [s.key, s]));
51
+ this.interval = deps.intervalMs ?? 1_000;
52
+ this.debug = deps.debug;
53
+ }
54
+ /** The stage the attempt is in, or "" before any. */
55
+ get stage() {
56
+ return this.stageKey;
57
+ }
58
+ /**
59
+ * Enters a stage (finishing the one before), or moves the current one to
60
+ * `state`. A key the manifest does not declare is added at run time with
61
+ * weight 0, named `name` (default the key).
62
+ */
63
+ setStage(key, opts = {}) {
64
+ if (!STAGE_KEY.test(key)) {
65
+ this.debug("ignored a stage with an invalid key", { key });
66
+ return;
67
+ }
68
+ if (key !== this.stageKey) {
69
+ this.stageKey = key;
70
+ this.stageName = this.declared.has(key) ? "" : clip(opts.name ?? key, 128);
71
+ this.progressState = { processed: 0, total: 0, failed: 0, fraction: undefined, message: "" };
72
+ }
73
+ if (opts.message !== undefined)
74
+ this.progressState.message = clip(opts.message, 255);
75
+ const state = stageState(opts.state);
76
+ // A stage move is sent at once, after anything pending, so none is skipped.
77
+ this.flushProgress();
78
+ this.send(this.progressRequest(state));
79
+ }
80
+ /** Reports progress within the current stage (or the attempt). Coalesced. */
81
+ progress(update) {
82
+ if (this.stopped)
83
+ return;
84
+ const p = this.progressState;
85
+ if (update.processed !== undefined)
86
+ p.processed = count(update.processed);
87
+ if (update.total !== undefined)
88
+ p.total = count(update.total);
89
+ if (update.failed !== undefined)
90
+ p.failed = count(update.failed);
91
+ if (update.fraction !== undefined)
92
+ p.fraction = Number.isFinite(update.fraction) ? Math.min(1, Math.max(0, update.fraction)) : undefined;
93
+ if (update.message !== undefined)
94
+ p.message = clip(update.message, 255);
95
+ this.dirty = true;
96
+ this.reported = true;
97
+ if (this.progressTimer)
98
+ return;
99
+ const wait = this.lastSent + this.interval - Date.now();
100
+ if (wait <= 0) {
101
+ this.flushProgress();
102
+ }
103
+ else {
104
+ this.progressTimer = setTimeout(() => {
105
+ this.progressTimer = undefined;
106
+ this.flushProgress();
107
+ }, wait);
108
+ this.progressTimer.unref?.();
109
+ }
110
+ }
111
+ /** Queues an issue. Batched. */
112
+ issue(input) {
113
+ if (this.stopped)
114
+ return;
115
+ const message = clip(String(input.message ?? "").trim(), 4096);
116
+ if (!message) {
117
+ this.debug("ignored an issue with no message");
118
+ return;
119
+ }
120
+ const kind = (input.subjectKind ?? "").toLowerCase().slice(0, 100);
121
+ const detail = input.detail && jsonSize(input.detail) <= 16 << 10 ? input.detail : undefined;
122
+ if (input.detail && !detail)
123
+ this.debug("dropped an issue's detail over 16 KiB");
124
+ this.issues.push({
125
+ severity: severity(input.severity),
126
+ subject: clip(input.subject ?? "", 512),
127
+ subjectKind: kind === "" || SUBJECT_KIND.test(kind) ? kind : "",
128
+ subjectId: clip((input.subjectId ?? "").replaceAll("\0", ""), 1024),
129
+ message,
130
+ ...(detail ? { detail } : {}),
131
+ stage: this.stageKey,
132
+ });
133
+ if (this.issues.length >= 100)
134
+ this.flushBatches();
135
+ else
136
+ this.armBatches();
137
+ }
138
+ /** Runs `fn` inside a span of this attempt's trace. */
139
+ span(name, fn, attributes, parent = "") {
140
+ const spanId = randomBytes(8).toString("hex");
141
+ const attrs = { ...(attributes ?? {}) };
142
+ const handle = {
143
+ traceId: this.traceId,
144
+ spanId,
145
+ setAttribute: (k, v) => {
146
+ attrs[k] = v;
147
+ },
148
+ span: (n, f, a) => this.span(n, f, a, spanId),
149
+ };
150
+ const startedAt = Date.now();
151
+ const end = (status, statusMessage = "") => {
152
+ if (this.stopped)
153
+ return;
154
+ this.spans.push({
155
+ traceId: this.traceId,
156
+ spanId,
157
+ parentSpanId: parent,
158
+ name: clip(name || "span", 255),
159
+ startedAt: timestampFromMs(startedAt),
160
+ endedAt: timestampFromMs(Math.max(Date.now(), startedAt)),
161
+ status,
162
+ statusMessage: clip(statusMessage, 1024),
163
+ ...(jsonSize(attrs) <= 16 << 10 && Object.keys(attrs).length > 0 ? { attributes: attrs } : {}),
164
+ });
165
+ if (this.spans.length >= 1000)
166
+ this.flushBatches();
167
+ else
168
+ this.armBatches();
169
+ };
170
+ return (async () => {
171
+ try {
172
+ const out = await fn(handle);
173
+ end("ok");
174
+ return out;
175
+ }
176
+ catch (err) {
177
+ end("error", err instanceof Error ? err.message : String(err));
178
+ throw err;
179
+ }
180
+ })();
181
+ }
182
+ /**
183
+ * The last reports before CompleteAttempt: the current stage finished as
184
+ * `outcome`, pending progress, issues and spans, waiting at most
185
+ * `timeoutMs`. Never throws.
186
+ */
187
+ async finish(outcome, timeoutMs) {
188
+ if (this.stopped)
189
+ return;
190
+ if (this.progressTimer)
191
+ clearTimeout(this.progressTimer);
192
+ this.progressTimer = undefined;
193
+ if (this.stageKey) {
194
+ if (outcome === "succeeded" && this.progressState.fraction === undefined && this.progressState.total === 0)
195
+ this.progressState.fraction = 1;
196
+ this.send(this.progressRequest(outcome === "succeeded" ? StageState.SUCCEEDED : StageState.FAILED));
197
+ this.dirty = false;
198
+ }
199
+ else if (this.dirty || (outcome === "succeeded" && this.reported)) {
200
+ if (outcome === "succeeded" && this.progressState.fraction === undefined && this.progressState.total === 0)
201
+ this.progressState.fraction = 1;
202
+ this.send(this.progressRequest(StageState.UNSPECIFIED));
203
+ this.dirty = false;
204
+ }
205
+ this.flushBatches();
206
+ let timer;
207
+ await Promise.race([this.chain, new Promise((r) => (timer = setTimeout(r, timeoutMs)))]);
208
+ clearTimeout(timer);
209
+ this.stop();
210
+ }
211
+ /** Stops reporting; nothing more is sent. */
212
+ stop() {
213
+ this.stopped = true;
214
+ if (this.progressTimer)
215
+ clearTimeout(this.progressTimer);
216
+ if (this.batchTimer)
217
+ clearTimeout(this.batchTimer);
218
+ this.progressTimer = this.batchTimer = undefined;
219
+ this.issues = [];
220
+ this.spans = [];
221
+ }
222
+ flushProgress() {
223
+ if (!this.dirty)
224
+ return;
225
+ this.dirty = false;
226
+ this.send(this.progressRequest(StageState.UNSPECIFIED));
227
+ }
228
+ progressRequest(state) {
229
+ const p = this.progressState;
230
+ const fraction = p.fraction ?? (p.total > 0 ? Math.min(1, p.processed / p.total) : 0);
231
+ return {
232
+ ref: this.ref,
233
+ fraction,
234
+ processed: BigInt(p.processed),
235
+ total: BigInt(p.total),
236
+ failed: BigInt(p.failed),
237
+ message: p.message,
238
+ stage: this.stageKey,
239
+ stageName: this.stageName,
240
+ stageState: state,
241
+ };
242
+ }
243
+ armBatches() {
244
+ if (this.batchTimer)
245
+ return;
246
+ this.batchTimer = setTimeout(() => {
247
+ this.batchTimer = undefined;
248
+ this.flushBatches();
249
+ }, this.interval);
250
+ this.batchTimer.unref?.();
251
+ }
252
+ flushBatches() {
253
+ if (this.batchTimer)
254
+ clearTimeout(this.batchTimer);
255
+ this.batchTimer = undefined;
256
+ while (this.issues.length > 0) {
257
+ const issues = this.issues.splice(0, 100);
258
+ this.enqueue("AppendIssues", () => this.api.appendIssues({ ref: this.ref, issues }, { timeoutMs: 10_000 }));
259
+ }
260
+ while (this.spans.length > 0) {
261
+ const spans = this.spans.splice(0, 1000);
262
+ this.enqueue("ReportSpans", () => this.api.reportSpans({ ref: this.ref, spans }, { timeoutMs: 10_000 }));
263
+ }
264
+ }
265
+ send(req) {
266
+ this.lastSent = Date.now();
267
+ this.enqueue("SetProgress", () => this.api.setProgress(req, { timeoutMs: 10_000 }));
268
+ }
269
+ /** Sends in order, one call at a time; failures are dropped. */
270
+ enqueue(what, call) {
271
+ if (this.stopped)
272
+ return;
273
+ this.chain = this.chain.then(async () => {
274
+ if (this.stopped)
275
+ return;
276
+ try {
277
+ await call();
278
+ }
279
+ catch (err) {
280
+ if (errorKind(err) === "lost")
281
+ this.stop();
282
+ this.debug(`${what} failed; dropped`, { error: err instanceof Error ? err.message : String(err) });
283
+ }
284
+ });
285
+ }
286
+ }
287
+ function stageState(s) {
288
+ switch (s) {
289
+ case "succeeded":
290
+ return StageState.SUCCEEDED;
291
+ case "failed":
292
+ return StageState.FAILED;
293
+ case "skipped":
294
+ return StageState.SKIPPED;
295
+ default:
296
+ return StageState.RUNNING;
297
+ }
298
+ }
299
+ function severity(s) {
300
+ switch (s) {
301
+ case "info":
302
+ return IssueSeverity.INFO;
303
+ case "error":
304
+ return IssueSeverity.ERROR;
305
+ default:
306
+ return IssueSeverity.WARNING;
307
+ }
308
+ }
309
+ function count(n) {
310
+ return Number.isFinite(n) ? Math.min(MAX_COUNT, Math.max(0, Math.floor(n))) : 0;
311
+ }
312
+ function clip(s, max) {
313
+ return s.length > max ? s.slice(0, max) : s;
314
+ }
315
+ function jsonSize(v) {
316
+ try {
317
+ return encoder.encode(JSON.stringify(v)).length;
318
+ }
319
+ catch {
320
+ return Infinity;
321
+ }
322
+ }
323
+ //# sourceMappingURL=reporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reporter.js","sourceRoot":"","sources":["../src/reporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAC;AAG/E,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AA6DjE,MAAM,SAAS,GAAG,0BAA0B,CAAC;AAC7C,MAAM,YAAY,GAAG,wBAAwB,CAAC;AAC9C,MAAM,SAAS,GAAG,iBAAiB,CAAC;AACpC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,eAAe;IACT,GAAG,CAAsB;IACzB,GAAG,CAAa;IAChB,QAAQ,CAAwB;IAChC,QAAQ,CAAS;IACjB,KAAK,CAAwB;IACtC,OAAO,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jC,CAAC;AACH,CAAC;AAED,SAAS,KAAK,CAAC,CAAS;IACtB,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClF,CAAC;AAED,SAAS,IAAI,CAAC,CAAS,EAAE,GAAW;IAClC,OAAO,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,QAAQ,CAAC,CAAU;IAC1B,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAClD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,201 @@
1
+ import type { JsonObject, MessageInitShape } from "@bufbuild/protobuf";
2
+ import type { Client } from "@connectrpc/connect";
3
+ import type { ResourceSchema } from "./gen/xeonr/pipelines/v1/common_pb.js";
4
+ import type { RetrySchema } from "./gen/xeonr/pipelines/v1/definition_pb.js";
5
+ import type { Run } from "./gen/xeonr/pipelines/v1/runs_pb.js";
6
+ import { MisfirePolicy, SchedulesService } from "./gen/xeonr/pipelines/v1/schedules_pb.js";
7
+ import type { ListScheduleOccurrencesResponse, Schedule } from "./gen/xeonr/pipelines/v1/schedules_pb.js";
8
+ import type { Connection } from "./transport.js";
9
+ /** Options for {@link SchedulesClient}. */
10
+ export type SchedulesClientOptions = Connection & {
11
+ /** The product (Auth application id) whose schedules these are: the caller's own. */
12
+ product: string;
13
+ /** Bound on each call. Default 30 s. */
14
+ timeoutMs?: number;
15
+ };
16
+ /** One target of an occurrence, in the JSON form an enumeration handler returns. */
17
+ export interface ScheduleTargetJson {
18
+ /** Identifies the target across occurrences ("server:42"). Unique in a list. */
19
+ key: string;
20
+ /** The team the target's run belongs to; required for a product-wide schedule. */
21
+ tenant?: string;
22
+ /** What the target's run is about. */
23
+ resource?: {
24
+ kind: string;
25
+ id: string;
26
+ json?: JsonObject;
27
+ };
28
+ /** Merged over the job's payload. At most 16 KiB. */
29
+ args?: JsonObject;
30
+ }
31
+ /** A job a schedule starts: as `createJob`, to one of the product's handlers. */
32
+ export interface ScheduleJobDecl {
33
+ handler: string;
34
+ payload?: JsonObject;
35
+ queue?: string;
36
+ retry?: MessageInitShape<typeof RetrySchema>;
37
+ timeoutMs?: number;
38
+ interruptible?: boolean;
39
+ }
40
+ /**
41
+ * A schedule as a product declares it at start. Each occurrence of `cron`
42
+ * (read in `timeZone`) starts `job` once per target: one target by default,
43
+ * the stored `enumerate.targets`, or the list the `enumerate.handler`
44
+ * returns at each occurrence (its kv output `targets`; see
45
+ * {@link defineEnumerator}).
46
+ */
47
+ export interface ScheduleDecl {
48
+ /** Unique per owner and never renamed; convention `<area>.<verb>`. */
49
+ name: string;
50
+ description?: string;
51
+ /** Five-field cron or a descriptor (`@hourly`, `@daily`). Empty is run-now only. */
52
+ cron: string;
53
+ /** The expression in plain words, shown while the declared one applies. */
54
+ cronLabel?: string;
55
+ /** IANA time zone; empty is UTC. */
56
+ timeZone?: string;
57
+ /** Default true. */
58
+ enabled?: boolean;
59
+ /** Makes it that team's own; unset is product-wide. */
60
+ tenant?: string;
61
+ job: ScheduleJobDecl;
62
+ enumerate?: {
63
+ handler: string;
64
+ maxTargets?: number;
65
+ } | {
66
+ targets: ScheduleTargetJson[];
67
+ maxTargets?: number;
68
+ };
69
+ /** Default LATEST: after an outage, fire only the most recent missed occurrence within `catchupWindowMs`. */
70
+ misfire?: MisfirePolicy;
71
+ catchupWindowMs?: number;
72
+ /** Fire although a run of the same schedule and target is still pending. Default off. */
73
+ queueWhilePending?: boolean;
74
+ /** Housekeeping whose clean runs a console hides. */
75
+ routine?: boolean;
76
+ }
77
+ /**
78
+ * The client for `SchedulesService`: cron schedules that start jobs (or
79
+ * stored pipelines) at each occurrence, once per target. Needs
80
+ * `pipelines:schedule:edit` / `pipelines:schedule:read`.
81
+ */
82
+ export declare class SchedulesClient {
83
+ /** The generated client, for anything not wrapped here. */
84
+ readonly schedules: Client<typeof SchedulesService>;
85
+ readonly product: string;
86
+ private readonly timeoutMs;
87
+ constructor(opts: SchedulesClientOptions);
88
+ /** Sets a schedule (`SetSchedule`), replacing every writable field; an owner's override is kept. */
89
+ setSchedule(decl: ScheduleDecl, signal?: AbortSignal): Promise<{
90
+ schedule: Schedule;
91
+ created: boolean;
92
+ }>;
93
+ /** Reads one schedule (`GetSchedule`), with its next occurrence computed now. */
94
+ getSchedule(ref: {
95
+ id: string;
96
+ } | {
97
+ name: string;
98
+ tenant?: string;
99
+ }, signal?: AbortSignal): Promise<Schedule>;
100
+ /** Lists this product's schedules (`ListSchedules`). */
101
+ listSchedules(input?: {
102
+ tenant?: string;
103
+ cursor?: string;
104
+ limit?: number;
105
+ }, signal?: AbortSignal): Promise<{
106
+ schedules: Schedule[];
107
+ nextCursor: string;
108
+ }>;
109
+ /** Overrides a schedule's cron and/or enabled flag (`SetScheduleOverride`); neither clears it. */
110
+ setScheduleOverride(scheduleId: string, override: {
111
+ cron?: string;
112
+ enabled?: boolean;
113
+ }, signal?: AbortSignal): Promise<Schedule>;
114
+ /** Pauses a schedule (`MarkSchedulePaused`). Run-now still works. */
115
+ pauseSchedule(scheduleId: string, signal?: AbortSignal): Promise<Schedule>;
116
+ /** Resumes a paused schedule (`MarkScheduleResumed`). */
117
+ resumeSchedule(scheduleId: string, signal?: AbortSignal): Promise<Schedule>;
118
+ /** Deletes a schedule (`DeleteSchedule`). Idempotent. */
119
+ deleteSchedule(scheduleId: string, signal?: AbortSignal): Promise<void>;
120
+ /** Runs a schedule now (`CreateScheduleRun`), for every target or one. */
121
+ runScheduleNow(scheduleId: string, input?: {
122
+ targetKey?: string;
123
+ force?: boolean;
124
+ }, signal?: AbortSignal): Promise<{
125
+ runs: Run[];
126
+ skipped: number;
127
+ }>;
128
+ /** A schedule's recent and upcoming occurrences (`ListScheduleOccurrences`). */
129
+ listScheduleOccurrences(scheduleId: string, input?: {
130
+ upcoming?: number;
131
+ cursor?: string;
132
+ limit?: number;
133
+ }, signal?: AbortSignal): Promise<ListScheduleOccurrencesResponse>;
134
+ private opts;
135
+ }
136
+ /** Declares a product's schedules, typically at start: `SetSchedule` for each. */
137
+ export declare function declareSchedules(client: SchedulesClient, decls: readonly ScheduleDecl[], signal?: AbortSignal): Promise<Schedule[]>;
138
+ /** The SetSchedule message for a declaration. */
139
+ export declare function scheduleInit(product: string, d: ScheduleDecl): {
140
+ queueWhilePending: boolean;
141
+ routine: boolean;
142
+ catchupWindow?: import("@bufbuild/protobuf/wkt").Duration;
143
+ misfire: MisfirePolicy;
144
+ enumerate?: {
145
+ maxTargets: number;
146
+ source: {
147
+ case: "handler";
148
+ value: string;
149
+ } | {
150
+ case: "list";
151
+ value: {
152
+ targets: {
153
+ args?: JsonObject;
154
+ resource?: MessageInitShape<typeof ResourceSchema>;
155
+ key: string;
156
+ tenant: string;
157
+ }[];
158
+ };
159
+ };
160
+ };
161
+ owner: {
162
+ product: string;
163
+ tenant: string;
164
+ };
165
+ name: string;
166
+ description: string;
167
+ cron: string;
168
+ cronLabel: string;
169
+ timeZone: string;
170
+ enabled: boolean;
171
+ target: {
172
+ case: "job";
173
+ value: {
174
+ interruptible: boolean;
175
+ timeout?: import("@bufbuild/protobuf/wkt").Duration;
176
+ retry?: import("./gen/xeonr/pipelines/v1/definition_pb.js").Retry | {
177
+ readonly $typeName?: never;
178
+ max?: number;
179
+ when?: import("./gen/xeonr/pipelines/v1/common_pb.js").FailureClass[];
180
+ backoff?: (import("./gen/xeonr/pipelines/v1/definition_pb.js").Backoff | {
181
+ readonly $typeName?: never;
182
+ initial?: (import("@bufbuild/protobuf/wkt").Duration | {
183
+ readonly $typeName?: never;
184
+ seconds?: bigint;
185
+ nanos?: number;
186
+ }) | undefined;
187
+ max?: (import("@bufbuild/protobuf/wkt").Duration | {
188
+ readonly $typeName?: never;
189
+ seconds?: bigint;
190
+ nanos?: number;
191
+ }) | undefined;
192
+ multiplier?: number;
193
+ }) | undefined;
194
+ };
195
+ queue: string;
196
+ payload?: JsonObject;
197
+ handler: string;
198
+ };
199
+ };
200
+ };
201
+ //# sourceMappingURL=schedules.d.ts.map