@xeonr/pipelines-sdk 0.2.0 → 0.4.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/README.md +231 -22
- package/dist/auth.d.ts +1 -1
- package/dist/client.d.ts +73 -10
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +47 -4
- package/dist/client.js.map +1 -1
- package/dist/gen/xeonr/pipelines/private/v1/attempt_pb.d.ts +179 -16
- package/dist/gen/xeonr/pipelines/private/v1/attempt_pb.d.ts.map +1 -1
- package/dist/gen/xeonr/pipelines/private/v1/attempt_pb.js +45 -28
- package/dist/gen/xeonr/pipelines/private/v1/attempt_pb.js.map +1 -1
- package/dist/gen/xeonr/pipelines/private/v1/step_local_pb.d.ts +136 -17
- package/dist/gen/xeonr/pipelines/private/v1/step_local_pb.d.ts.map +1 -1
- package/dist/gen/xeonr/pipelines/private/v1/step_local_pb.js +42 -35
- package/dist/gen/xeonr/pipelines/private/v1/step_local_pb.js.map +1 -1
- package/dist/gen/xeonr/pipelines/private/v1/worker_pb.d.ts +224 -8
- package/dist/gen/xeonr/pipelines/private/v1/worker_pb.d.ts.map +1 -1
- package/dist/gen/xeonr/pipelines/private/v1/worker_pb.js +43 -9
- package/dist/gen/xeonr/pipelines/private/v1/worker_pb.js.map +1 -1
- package/dist/gen/xeonr/pipelines/v1/common_pb.d.ts +64 -8
- package/dist/gen/xeonr/pipelines/v1/common_pb.d.ts.map +1 -1
- package/dist/gen/xeonr/pipelines/v1/common_pb.js +62 -5
- package/dist/gen/xeonr/pipelines/v1/common_pb.js.map +1 -1
- package/dist/gen/xeonr/pipelines/v1/definition_pb.d.ts +312 -9
- package/dist/gen/xeonr/pipelines/v1/definition_pb.d.ts.map +1 -1
- package/dist/gen/xeonr/pipelines/v1/definition_pb.js +100 -7
- package/dist/gen/xeonr/pipelines/v1/definition_pb.js.map +1 -1
- package/dist/gen/xeonr/pipelines/v1/pipelines_pb.d.ts +1072 -0
- package/dist/gen/xeonr/pipelines/v1/pipelines_pb.d.ts.map +1 -0
- package/dist/gen/xeonr/pipelines/v1/pipelines_pb.js +299 -0
- package/dist/gen/xeonr/pipelines/v1/pipelines_pb.js.map +1 -0
- package/dist/gen/xeonr/pipelines/v1/pools_pb.d.ts +103 -8
- package/dist/gen/xeonr/pipelines/v1/pools_pb.d.ts.map +1 -1
- package/dist/gen/xeonr/pipelines/v1/pools_pb.js +32 -24
- package/dist/gen/xeonr/pipelines/v1/pools_pb.js.map +1 -1
- package/dist/gen/xeonr/pipelines/v1/queues_pb.d.ts +711 -0
- package/dist/gen/xeonr/pipelines/v1/queues_pb.d.ts.map +1 -0
- package/dist/gen/xeonr/pipelines/v1/queues_pb.js +185 -0
- package/dist/gen/xeonr/pipelines/v1/queues_pb.js.map +1 -0
- package/dist/gen/xeonr/pipelines/v1/registry_pb.d.ts +92 -23
- package/dist/gen/xeonr/pipelines/v1/registry_pb.d.ts.map +1 -1
- package/dist/gen/xeonr/pipelines/v1/registry_pb.js +36 -33
- package/dist/gen/xeonr/pipelines/v1/registry_pb.js.map +1 -1
- package/dist/gen/xeonr/pipelines/v1/runs_pb.d.ts +1191 -33
- package/dist/gen/xeonr/pipelines/v1/runs_pb.d.ts.map +1 -1
- package/dist/gen/xeonr/pipelines/v1/runs_pb.js +419 -35
- package/dist/gen/xeonr/pipelines/v1/runs_pb.js.map +1 -1
- package/dist/gen/xeonr/pipelines/v1/schedule_targets_pb.d.ts +194 -0
- package/dist/gen/xeonr/pipelines/v1/schedule_targets_pb.d.ts.map +1 -0
- package/dist/gen/xeonr/pipelines/v1/schedule_targets_pb.js +100 -0
- package/dist/gen/xeonr/pipelines/v1/schedule_targets_pb.js.map +1 -0
- package/dist/gen/xeonr/pipelines/v1/schedules_pb.d.ts +1186 -0
- package/dist/gen/xeonr/pipelines/v1/schedules_pb.d.ts.map +1 -0
- package/dist/gen/xeonr/pipelines/v1/schedules_pb.js +335 -0
- package/dist/gen/xeonr/pipelines/v1/schedules_pb.js.map +1 -0
- package/dist/gen/xeonr/pipelines/v1/secrets_pb.d.ts +32 -5
- package/dist/gen/xeonr/pipelines/v1/secrets_pb.d.ts.map +1 -1
- package/dist/gen/xeonr/pipelines/v1/secrets_pb.js +12 -3
- package/dist/gen/xeonr/pipelines/v1/secrets_pb.js.map +1 -1
- package/dist/gen/xeonr/pipelines/v1/sinks_pb.d.ts +270 -27
- package/dist/gen/xeonr/pipelines/v1/sinks_pb.d.ts.map +1 -1
- package/dist/gen/xeonr/pipelines/v1/sinks_pb.js +163 -24
- package/dist/gen/xeonr/pipelines/v1/sinks_pb.js.map +1 -1
- package/dist/gen/xeonr/pipelines/v1/tenant_policies_pb.d.ts +391 -0
- package/dist/gen/xeonr/pipelines/v1/tenant_policies_pb.d.ts.map +1 -0
- package/dist/gen/xeonr/pipelines/v1/tenant_policies_pb.js +100 -0
- package/dist/gen/xeonr/pipelines/v1/tenant_policies_pb.js.map +1 -0
- package/dist/gen/xeonr/platform/v1/options_pb.d.ts +137 -1
- package/dist/gen/xeonr/platform/v1/options_pb.d.ts.map +1 -1
- package/dist/gen/xeonr/platform/v1/options_pb.js +104 -1
- package/dist/gen/xeonr/platform/v1/options_pb.js.map +1 -1
- package/dist/handler.d.ts +51 -1
- package/dist/handler.d.ts.map +1 -1
- package/dist/handler.js +27 -0
- package/dist/handler.js.map +1 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/queues.d.ts +158 -0
- package/dist/queues.d.ts.map +1 -0
- package/dist/queues.js +117 -0
- package/dist/queues.js.map +1 -0
- package/dist/reporter.d.ts +120 -0
- package/dist/reporter.d.ts.map +1 -0
- package/dist/reporter.js +323 -0
- package/dist/reporter.js.map +1 -0
- package/dist/schedules.d.ts +193 -0
- package/dist/schedules.d.ts.map +1 -0
- package/dist/schedules.js +126 -0
- package/dist/schedules.js.map +1 -0
- package/dist/testing/cron.d.ts +33 -0
- package/dist/testing/cron.d.ts.map +1 -0
- package/dist/testing/cron.js +177 -0
- package/dist/testing/cron.js.map +1 -0
- package/dist/testing/index.d.ts +229 -7
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1304 -103
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/pipelines.d.ts +99 -0
- package/dist/testing/pipelines.d.ts.map +1 -0
- package/dist/testing/pipelines.js +445 -0
- package/dist/testing/pipelines.js.map +1 -0
- package/dist/testing/queues.d.ts +49 -0
- package/dist/testing/queues.d.ts.map +1 -0
- package/dist/testing/queues.js +72 -0
- package/dist/testing/queues.js.map +1 -0
- package/dist/testing/schedules.d.ts +125 -0
- package/dist/testing/schedules.d.ts.map +1 -0
- package/dist/testing/schedules.js +422 -0
- package/dist/testing/schedules.js.map +1 -0
- package/dist/worker.d.ts +48 -7
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +59 -9
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
package/dist/queues.d.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { MessageInitShape } from "@bufbuild/protobuf";
|
|
2
|
+
import type { Client } from "@connectrpc/connect";
|
|
3
|
+
import type { RunState } from "./gen/xeonr/pipelines/v1/common_pb.js";
|
|
4
|
+
import type { RetrySchema } from "./gen/xeonr/pipelines/v1/definition_pb.js";
|
|
5
|
+
import { QueuesService } from "./gen/xeonr/pipelines/v1/queues_pb.js";
|
|
6
|
+
import type { GetQueueStatsResponse, Queue } from "./gen/xeonr/pipelines/v1/queues_pb.js";
|
|
7
|
+
import type { Run } from "./gen/xeonr/pipelines/v1/runs_pb.js";
|
|
8
|
+
import type { Connection } from "./transport.js";
|
|
9
|
+
/** Options for {@link QueuesClient}. */
|
|
10
|
+
export type QueuesClientOptions = Connection & {
|
|
11
|
+
/**
|
|
12
|
+
* The tenant (team URN) whose queues these are: a team the calling service
|
|
13
|
+
* account is a member of. A queue's owner always names it.
|
|
14
|
+
*/
|
|
15
|
+
tenant: string;
|
|
16
|
+
/** Bound on each call. Default 30 s. */
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* A queue as a service declares it for its tenant. Every field but `name` is optional and
|
|
21
|
+
* takes the contract's default (no cap, no rate limit, the platform's retry
|
|
22
|
+
* and timeout, priority 1).
|
|
23
|
+
*/
|
|
24
|
+
export interface QueueDecl {
|
|
25
|
+
/** `^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$`; `default` is the tenant's default queue. */
|
|
26
|
+
name: string;
|
|
27
|
+
description?: string;
|
|
28
|
+
/** Caps the queue's claimed and running attempts, all lanes together. */
|
|
29
|
+
maxConcurrency?: number;
|
|
30
|
+
/** Caps one lane's claimed and running attempts in the queue (the jobs with no fairness key, or those of one key). */
|
|
31
|
+
maxConcurrencyPerTenant?: number;
|
|
32
|
+
/** At most `limit` attempts claimed per sliding `windowMs`, retries included. */
|
|
33
|
+
rateLimit?: {
|
|
34
|
+
limit: number;
|
|
35
|
+
windowMs: number;
|
|
36
|
+
};
|
|
37
|
+
/** The retry of a job that gives none, and the most a job may ask for. */
|
|
38
|
+
defaultRetry?: MessageInitShape<typeof RetrySchema>;
|
|
39
|
+
/** The timeout of a job that gives none, and the most a job may ask for. */
|
|
40
|
+
defaultTimeoutMs?: number;
|
|
41
|
+
/** Lower first, across a tenant's queues a worker could claim from. Zero means 1. */
|
|
42
|
+
priority?: number;
|
|
43
|
+
}
|
|
44
|
+
/** A queue to read: by id, or by name among the client's tenant's queues. */
|
|
45
|
+
export type QueueRef = {
|
|
46
|
+
id: string;
|
|
47
|
+
} | {
|
|
48
|
+
name: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* The client for `QueuesService`: the lanes a tenant's jobs are admitted
|
|
52
|
+
* through, with their limits and fairness. Needs `pipelines:queue:edit` to
|
|
53
|
+
* change queues and `pipelines:queue:read` to read them.
|
|
54
|
+
*
|
|
55
|
+
* Jobs name a queue with `PipelinesClient.createJob({ queue })`; a job with
|
|
56
|
+
* none goes to the tenant's `default` queue.
|
|
57
|
+
*/
|
|
58
|
+
export declare class QueuesClient {
|
|
59
|
+
/** The generated client, for anything not wrapped here. */
|
|
60
|
+
readonly queues: Client<typeof QueuesService>;
|
|
61
|
+
private readonly runs;
|
|
62
|
+
readonly tenant: string;
|
|
63
|
+
private readonly timeoutMs;
|
|
64
|
+
constructor(opts: QueuesClientOptions);
|
|
65
|
+
/**
|
|
66
|
+
* Sets a queue (`SetQueue`): creates it, or replaces every writable field
|
|
67
|
+
* of the one with that owner and name. Pause and resume are separate.
|
|
68
|
+
*/
|
|
69
|
+
setQueue(decl: QueueDecl, signal?: AbortSignal): Promise<{
|
|
70
|
+
queue: Queue;
|
|
71
|
+
created: boolean;
|
|
72
|
+
}>;
|
|
73
|
+
/** Reads one queue (`GetQueue`). The `default` queue reads as unlimited until it is set. */
|
|
74
|
+
getQueue(ref: QueueRef, signal?: AbortSignal): Promise<Queue>;
|
|
75
|
+
/** Lists the tenant's queues (`ListQueues`), by priority then name. */
|
|
76
|
+
listQueues(input?: {
|
|
77
|
+
cursor?: string;
|
|
78
|
+
limit?: number;
|
|
79
|
+
}, signal?: AbortSignal): Promise<{
|
|
80
|
+
queues: Queue[];
|
|
81
|
+
nextCursor: string;
|
|
82
|
+
}>;
|
|
83
|
+
/** Pauses a queue (`MarkQueuePaused`): it accepts jobs and starts none. Idempotent. */
|
|
84
|
+
pauseQueue(queueId: string, reason?: string, signal?: AbortSignal): Promise<Queue>;
|
|
85
|
+
/** Resumes a paused queue (`MarkQueueResumed`). Idempotent. */
|
|
86
|
+
resumeQueue(queueId: string, signal?: AbortSignal): Promise<Queue>;
|
|
87
|
+
/** How a queue is doing now (`GetQueueStats`). */
|
|
88
|
+
getQueueStats(queueId: string, input?: {
|
|
89
|
+
windowMs?: number;
|
|
90
|
+
}, signal?: AbortSignal): Promise<GetQueueStatsResponse>;
|
|
91
|
+
/**
|
|
92
|
+
* Lists the jobs that went through a queue (`ListQueueJobs`), newest
|
|
93
|
+
* first. With `states: [RunState.FAILED]` it lists the dead letters.
|
|
94
|
+
*/
|
|
95
|
+
listQueueJobs(queueId: string, input?: {
|
|
96
|
+
states?: RunState[];
|
|
97
|
+
cursor?: string;
|
|
98
|
+
limit?: number;
|
|
99
|
+
}, signal?: AbortSignal): Promise<{
|
|
100
|
+
runs: Run[];
|
|
101
|
+
nextCursor: string;
|
|
102
|
+
}>;
|
|
103
|
+
/**
|
|
104
|
+
* Deletes a queue (`DeleteQueue`). Refused while jobs wait unless
|
|
105
|
+
* `cancelWaiting`. Returns how many jobs were cancelled.
|
|
106
|
+
*/
|
|
107
|
+
deleteQueue(queueId: string, input?: {
|
|
108
|
+
cancelWaiting?: boolean;
|
|
109
|
+
}, signal?: AbortSignal): Promise<number>;
|
|
110
|
+
/**
|
|
111
|
+
* Enqueues a dead letter again: `RetryNode` on the job's run, node `job`.
|
|
112
|
+
* The new attempt is offered on the job's queue under its settings now.
|
|
113
|
+
*/
|
|
114
|
+
requeueJob(runId: string, signal?: AbortSignal): Promise<Run>;
|
|
115
|
+
private opts;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Declares a tenant's queues, typically at start: `SetQueue` for each,
|
|
119
|
+
* replacing every writable field, so the code is the source of truth and
|
|
120
|
+
* repeating it changes nothing. A queue's pause survives.
|
|
121
|
+
*/
|
|
122
|
+
export declare function declareQueues(client: QueuesClient, decls: readonly QueueDecl[], signal?: AbortSignal): Promise<Queue[]>;
|
|
123
|
+
/** The SetQueue message for a declaration. */
|
|
124
|
+
export declare function queueInit(tenant: string, d: QueueDecl): {
|
|
125
|
+
priority: number;
|
|
126
|
+
defaultTimeout?: import("@bufbuild/protobuf/wkt").Duration;
|
|
127
|
+
defaultRetry?: import("./gen/xeonr/pipelines/v1/definition_pb.js").Retry | {
|
|
128
|
+
readonly $typeName?: never;
|
|
129
|
+
max?: number;
|
|
130
|
+
when?: import("./gen/xeonr/pipelines/v1/common_pb.js").FailureClass[];
|
|
131
|
+
backoff?: (import("./gen/xeonr/pipelines/v1/definition_pb.js").Backoff | {
|
|
132
|
+
readonly $typeName?: never;
|
|
133
|
+
initial?: (import("@bufbuild/protobuf/wkt").Duration | {
|
|
134
|
+
readonly $typeName?: never;
|
|
135
|
+
seconds?: bigint;
|
|
136
|
+
nanos?: number;
|
|
137
|
+
}) | undefined;
|
|
138
|
+
max?: (import("@bufbuild/protobuf/wkt").Duration | {
|
|
139
|
+
readonly $typeName?: never;
|
|
140
|
+
seconds?: bigint;
|
|
141
|
+
nanos?: number;
|
|
142
|
+
}) | undefined;
|
|
143
|
+
multiplier?: number;
|
|
144
|
+
}) | undefined;
|
|
145
|
+
};
|
|
146
|
+
rateLimit?: {
|
|
147
|
+
limit: number;
|
|
148
|
+
window: import("@bufbuild/protobuf/wkt").Duration;
|
|
149
|
+
};
|
|
150
|
+
owner: {
|
|
151
|
+
tenant: string;
|
|
152
|
+
};
|
|
153
|
+
name: string;
|
|
154
|
+
description: string;
|
|
155
|
+
maxConcurrency: number;
|
|
156
|
+
maxConcurrencyPerTenant: number;
|
|
157
|
+
};
|
|
158
|
+
//# sourceMappingURL=queues.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queues.d.ts","sourceRoot":"","sources":["../src/queues.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAG3D,OAAO,KAAK,EAAE,MAAM,EAAa,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,uCAAuC,CAAC;AAE1F,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,qCA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AAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE;QAAE,aAAa,CAAC,EAAE,OAAO,CAAA;KAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlH;;;OAGG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;IAInE,OAAO,CAAC,IAAI;CAGb;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAI7H;AAED,8CAA8C;AAC9C,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYrD"}
|
package/dist/queues.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { durationFromMs } from "@bufbuild/protobuf/wkt";
|
|
2
|
+
import { createClient } from "@connectrpc/connect";
|
|
3
|
+
import { QueuesService } from "./gen/xeonr/pipelines/v1/queues_pb.js";
|
|
4
|
+
import { RunsService } from "./gen/xeonr/pipelines/v1/runs_pb.js";
|
|
5
|
+
import { transportOf } from "./transport.js";
|
|
6
|
+
/**
|
|
7
|
+
* The client for `QueuesService`: the lanes a tenant's jobs are admitted
|
|
8
|
+
* through, with their limits and fairness. Needs `pipelines:queue:edit` to
|
|
9
|
+
* change queues and `pipelines:queue:read` to read them.
|
|
10
|
+
*
|
|
11
|
+
* Jobs name a queue with `PipelinesClient.createJob({ queue })`; a job with
|
|
12
|
+
* none goes to the tenant's `default` queue.
|
|
13
|
+
*/
|
|
14
|
+
export class QueuesClient {
|
|
15
|
+
/** The generated client, for anything not wrapped here. */
|
|
16
|
+
queues;
|
|
17
|
+
runs;
|
|
18
|
+
tenant;
|
|
19
|
+
timeoutMs;
|
|
20
|
+
constructor(opts) {
|
|
21
|
+
const transport = transportOf(opts);
|
|
22
|
+
this.queues = createClient(QueuesService, transport);
|
|
23
|
+
this.runs = createClient(RunsService, transport);
|
|
24
|
+
if (!opts.tenant)
|
|
25
|
+
throw new TypeError("QueuesClient: tenant is required");
|
|
26
|
+
this.tenant = opts.tenant;
|
|
27
|
+
this.timeoutMs = opts.timeoutMs ?? 30_000;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Sets a queue (`SetQueue`): creates it, or replaces every writable field
|
|
31
|
+
* of the one with that owner and name. Pause and resume are separate.
|
|
32
|
+
*/
|
|
33
|
+
async setQueue(decl, signal) {
|
|
34
|
+
const res = await this.queues.setQueue({ queue: queueInit(this.tenant, decl) }, this.opts(signal));
|
|
35
|
+
return { queue: required(res.queue), created: res.created };
|
|
36
|
+
}
|
|
37
|
+
/** Reads one queue (`GetQueue`). The `default` queue reads as unlimited until it is set. */
|
|
38
|
+
async getQueue(ref, signal) {
|
|
39
|
+
const queue = "id" in ref
|
|
40
|
+
? { case: "queueId", value: ref.id }
|
|
41
|
+
: { case: "byName", value: { owner: { tenant: this.tenant }, name: ref.name } };
|
|
42
|
+
return required((await this.queues.getQueue({ queue }, this.opts(signal))).queue);
|
|
43
|
+
}
|
|
44
|
+
/** Lists the tenant's queues (`ListQueues`), by priority then name. */
|
|
45
|
+
async listQueues(input = {}, signal) {
|
|
46
|
+
const res = await this.queues.listQueues({ tenant: this.tenant, cursor: input.cursor ?? "", limit: input.limit ?? 0 }, this.opts(signal));
|
|
47
|
+
return { queues: res.queues, nextCursor: res.nextCursor };
|
|
48
|
+
}
|
|
49
|
+
/** Pauses a queue (`MarkQueuePaused`): it accepts jobs and starts none. Idempotent. */
|
|
50
|
+
async pauseQueue(queueId, reason = "", signal) {
|
|
51
|
+
return required((await this.queues.markQueuePaused({ queueId, reason }, this.opts(signal))).queue);
|
|
52
|
+
}
|
|
53
|
+
/** Resumes a paused queue (`MarkQueueResumed`). Idempotent. */
|
|
54
|
+
async resumeQueue(queueId, signal) {
|
|
55
|
+
return required((await this.queues.markQueueResumed({ queueId }, this.opts(signal))).queue);
|
|
56
|
+
}
|
|
57
|
+
/** How a queue is doing now (`GetQueueStats`). */
|
|
58
|
+
async getQueueStats(queueId, input = {}, signal) {
|
|
59
|
+
return this.queues.getQueueStats({ queueId, ...(input.windowMs ? { window: durationFromMs(input.windowMs) } : {}) }, this.opts(signal));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Lists the jobs that went through a queue (`ListQueueJobs`), newest
|
|
63
|
+
* first. With `states: [RunState.FAILED]` it lists the dead letters.
|
|
64
|
+
*/
|
|
65
|
+
async listQueueJobs(queueId, input = {}, signal) {
|
|
66
|
+
const res = await this.queues.listQueueJobs({ queueId, states: input.states ?? [], cursor: input.cursor ?? "", limit: input.limit ?? 0 }, this.opts(signal));
|
|
67
|
+
return { runs: res.runs, nextCursor: res.nextCursor };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Deletes a queue (`DeleteQueue`). Refused while jobs wait unless
|
|
71
|
+
* `cancelWaiting`. Returns how many jobs were cancelled.
|
|
72
|
+
*/
|
|
73
|
+
async deleteQueue(queueId, input = {}, signal) {
|
|
74
|
+
return (await this.queues.deleteQueue({ queueId, cancelWaiting: input.cancelWaiting ?? false }, this.opts(signal))).cancelledJobs;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Enqueues a dead letter again: `RetryNode` on the job's run, node `job`.
|
|
78
|
+
* The new attempt is offered on the job's queue under its settings now.
|
|
79
|
+
*/
|
|
80
|
+
async requeueJob(runId, signal) {
|
|
81
|
+
return required((await this.runs.retryNode({ runId, nodeId: "job" }, this.opts(signal))).run);
|
|
82
|
+
}
|
|
83
|
+
opts(signal) {
|
|
84
|
+
return { timeoutMs: this.timeoutMs, ...(signal ? { signal } : {}) };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Declares a tenant's queues, typically at start: `SetQueue` for each,
|
|
89
|
+
* replacing every writable field, so the code is the source of truth and
|
|
90
|
+
* repeating it changes nothing. A queue's pause survives.
|
|
91
|
+
*/
|
|
92
|
+
export async function declareQueues(client, decls, signal) {
|
|
93
|
+
const out = [];
|
|
94
|
+
for (const d of decls)
|
|
95
|
+
out.push((await client.setQueue(d, signal)).queue);
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
/** The SetQueue message for a declaration. */
|
|
99
|
+
export function queueInit(tenant, d) {
|
|
100
|
+
return {
|
|
101
|
+
owner: { tenant },
|
|
102
|
+
name: d.name,
|
|
103
|
+
description: d.description ?? "",
|
|
104
|
+
maxConcurrency: d.maxConcurrency ?? 0,
|
|
105
|
+
maxConcurrencyPerTenant: d.maxConcurrencyPerTenant ?? 0,
|
|
106
|
+
...(d.rateLimit ? { rateLimit: { limit: d.rateLimit.limit, window: durationFromMs(d.rateLimit.windowMs) } } : {}),
|
|
107
|
+
...(d.defaultRetry ? { defaultRetry: d.defaultRetry } : {}),
|
|
108
|
+
...(d.defaultTimeoutMs ? { defaultTimeout: durationFromMs(d.defaultTimeoutMs) } : {}),
|
|
109
|
+
priority: d.priority ?? 0,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function required(v) {
|
|
113
|
+
if (v === undefined)
|
|
114
|
+
throw new Error("pipelines-api answered without the queue");
|
|
115
|
+
return v;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=queues.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queues.js","sourceRoot":"","sources":["../src/queues.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAInD,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAEtE,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC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AAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjH,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3D,GAAG,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrF,QAAQ,EAAE,CAAC,CAAC,QAAQ,IAAI,CAAC;KAC1B,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAI,CAAgB;IACnC,IAAI,CAAC,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IACjF,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -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 service'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;CAClB;AAED,2EAA2E;AAC3E,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;IACxC,4EAA4E;IAC5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