@rocket.chat/houston 0.27.0-next.2 → 2.1.8
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/LICENSE +1 -1
- package/README.md +108 -15
- package/bin/houston +62 -0
- package/data/docs/ARCHITECTURE.md +387 -0
- package/data/docs/automation.md +107 -0
- package/data/docs/e2ee.md +76 -0
- package/data/docs/eks.md +258 -0
- package/data/docs/gui.md +282 -0
- package/data/docs/guide.md +669 -0
- package/data/docs/kubernetes.md +138 -0
- package/data/docs/troubleshooting.md +193 -0
- package/data/docs/upgrading.md +84 -0
- package/data/docs/voice.md +253 -0
- package/data/iam/engineer-policy.json +11 -0
- package/data/iam/engineer-rbac.yaml +42 -0
- package/data/iam/operator-policy.json +211 -0
- package/data/loadtest/badbot.js +22 -0
- package/data/loadtest/common.js +168 -0
- package/data/loadtest/custom.js +20 -0
- package/data/loadtest/journey.js +58 -0
- package/data/loadtest/login.js +18 -0
- package/data/loadtest/messages.js +13 -0
- package/data/loadtest/mixed.js +39 -0
- package/data/loadtest/read.js +12 -0
- package/data/loadtest/webhook.js +20 -0
- package/data/monitoring/houston-logs.json +98 -0
- package/data/monitoring/k6-loadtest.json +610 -0
- package/data/monitoring/mongodb-exporter.json +3007 -0
- package/data/monitoring/node-exporter-full.json +16114 -0
- package/data/monitoring/rocketchat-metrics.json +6471 -0
- package/data/presets/airgapped.yaml +16 -0
- package/data/presets/default.yaml +9 -0
- package/data/seed/avatar-0.png +0 -0
- package/data/seed/avatar-1.png +0 -0
- package/data/seed/avatar-2.png +0 -0
- package/data/seed/avatar-3.png +0 -0
- package/data/seed/avatar-4.png +0 -0
- package/data/seed/avatar-5.png +0 -0
- package/data/seed/avatar-6.png +0 -0
- package/data/seed/avatar-7.png +0 -0
- package/data/seed/seed-metrics.csv +3 -0
- package/data/seed/seed-preview.png +0 -0
- package/data/seed/seed-report.pdf +32 -0
- package/data/seed/seed-runbook.txt +3 -0
- package/data/skill/SKILL.md +399 -0
- package/data/versions.yaml +55 -0
- package/data/voice/freeswitch/drachtio.xml +52 -0
- package/data/voice/freeswitch/public.xml +87 -0
- package/data/webui/app.css +2003 -0
- package/data/webui/index.html +678 -0
- package/data/webui/js/api.js +561 -0
- package/data/webui/js/boot.js +44 -0
- package/data/webui/js/clusters-tail.js +1377 -0
- package/data/webui/js/clusters.js +896 -0
- package/data/webui/js/create.js +276 -0
- package/data/webui/js/detail.js +507 -0
- package/data/webui/js/jobs.js +636 -0
- package/data/webui/js/logs.js +634 -0
- package/data/webui/js/main.js +14 -0
- package/data/webui/js/options.js +408 -0
- package/data/webui/js/people.js +438 -0
- package/data/webui/js/perf.js +303 -0
- package/data/webui/js/render.js +438 -0
- package/data/webui/js/shared.js +3 -0
- package/data/webui/js/state.js +583 -0
- package/data/webui/js/theme.js +123 -0
- package/data/webui/js/util.js +584 -0
- package/dist/cli/app.js +593 -0
- package/dist/cli/capabilities.js +76 -0
- package/dist/cli/cell-widths.js +495 -0
- package/dist/cli/entry.js +10 -0
- package/dist/cli/error-panel.js +492 -0
- package/dist/cli/handlers/actor.js +84 -0
- package/dist/cli/handlers/https.js +614 -0
- package/dist/cli/handlers/prompt.js +299 -0
- package/dist/cli/handlers/users.js +226 -0
- package/dist/cli/handlers.js +3678 -0
- package/dist/cli/help.js +183 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/perf.js +810 -0
- package/dist/cli/render.js +254 -0
- package/dist/cli/serve.js +858 -0
- package/dist/cli/spec-data.js +2593 -0
- package/dist/cli/spec-types.js +8 -0
- package/dist/cli/usage-error.js +520 -0
- package/dist/cli/wire.js +70 -0
- package/dist/core/audit.js +346 -0
- package/dist/core/backup-compat.js +85 -0
- package/dist/core/backup.js +1639 -0
- package/dist/core/cluster.js +1398 -0
- package/dist/core/configimport.js +344 -0
- package/dist/core/data.js +267 -0
- package/dist/core/database-of.js +82 -0
- package/dist/core/diagnose.js +159 -0
- package/dist/core/doctor.js +1518 -0
- package/dist/core/edge/acme.js +338 -0
- package/dist/core/edge/engine.js +500 -0
- package/dist/core/edge/networks.js +174 -0
- package/dist/core/edge/paths.js +107 -0
- package/dist/core/edge/routes.js +251 -0
- package/dist/core/edge/routeyml.js +195 -0
- package/dist/core/edge/runtime.js +493 -0
- package/dist/core/edge/spec.js +305 -0
- package/dist/core/edge/types.js +202 -0
- package/dist/core/eks-docs.js +135 -0
- package/dist/core/eks.js +2240 -0
- package/dist/core/envvars.js +562 -0
- package/dist/core/eventlog.js +541 -0
- package/dist/core/firstrun.js +153 -0
- package/dist/core/journal.js +691 -0
- package/dist/core/kube/ask.js +231 -0
- package/dist/core/kube/capabilities.js +269 -0
- package/dist/core/kube/certmanager.js +452 -0
- package/dist/core/kube/chart.js +413 -0
- package/dist/core/kube/cluster.js +196 -0
- package/dist/core/kube/context.js +545 -0
- package/dist/core/kube/endpoints.js +448 -0
- package/dist/core/kube/exec.js +195 -0
- package/dist/core/kube/forward.js +732 -0
- package/dist/core/kube/grafana-ingress.js +110 -0
- package/dist/core/kube/ingress.js +218 -0
- package/dist/core/kube/manifests.js +361 -0
- package/dist/core/kube/monitoring.js +768 -0
- package/dist/core/kube/names.js +237 -0
- package/dist/core/kube/namespace.js +678 -0
- package/dist/core/kube/operator.js +941 -0
- package/dist/core/kube/probe.js +202 -0
- package/dist/core/kube/reachability.js +163 -0
- package/dist/core/kube/release.js +439 -0
- package/dist/core/kube/replicaset.js +180 -0
- package/dist/core/kube/scale.js +398 -0
- package/dist/core/kube/status.js +633 -0
- package/dist/core/kube/tools.js +238 -0
- package/dist/core/kube/transfer.js +173 -0
- package/dist/core/kube/workspace.js +423 -0
- package/dist/core/lifecycle/admin.js +64 -0
- package/dist/core/lifecycle/create-docker.js +1533 -0
- package/dist/core/lifecycle/create-k8s.js +939 -0
- package/dist/core/lifecycle/destroy.js +339 -0
- package/dist/core/lifecycle/inspect.js +635 -0
- package/dist/core/lifecycle/naming.js +298 -0
- package/dist/core/lifecycle/notes.js +726 -0
- package/dist/core/lifecycle/ownership.js +313 -0
- package/dist/core/lifecycle/payload.js +401 -0
- package/dist/core/lifecycle/ports.js +388 -0
- package/dist/core/lifecycle/preconditions.js +367 -0
- package/dist/core/lifecycle/pruning.js +551 -0
- package/dist/core/lifecycle/ready.js +753 -0
- package/dist/core/lifecycle/request.js +525 -0
- package/dist/core/lifecycle/seeding.js +281 -0
- package/dist/core/lifecycle/sizing.js +392 -0
- package/dist/core/lifecycle/state.js +286 -0
- package/dist/core/lifecycle/tlsplan.js +704 -0
- package/dist/core/lifecycle/types.js +232 -0
- package/dist/core/loadtest.js +995 -0
- package/dist/core/migrate.js +612 -0
- package/dist/core/monitor.js +494 -0
- package/dist/core/postready.js +969 -0
- package/dist/core/promote.js +804 -0
- package/dist/core/rcapi.js +1285 -0
- package/dist/core/recovery.js +75 -0
- package/dist/core/runner/engine.js +394 -0
- package/dist/core/runner/host.js +298 -0
- package/dist/core/runner/locks.js +129 -0
- package/dist/core/runner/paths.js +173 -0
- package/dist/core/runner/ports.js +172 -0
- package/dist/core/runner/queries.js +612 -0
- package/dist/core/runner/record.js +563 -0
- package/dist/core/scaleseed.js +271 -0
- package/dist/core/seed-db.js +208 -0
- package/dist/core/sessions.js +472 -0
- package/dist/core/skill.js +326 -0
- package/dist/core/sso-identities.js +172 -0
- package/dist/core/sso.js +703 -0
- package/dist/core/tls-local.js +311 -0
- package/dist/core/tls.js +878 -0
- package/dist/core/topology.js +482 -0
- package/dist/core/upgrade.js +868 -0
- package/dist/core/users.js +739 -0
- package/dist/lib/audit.js +100 -0
- package/dist/lib/close-matches.js +238 -0
- package/dist/lib/compose.js +672 -0
- package/dist/lib/config.js +1398 -0
- package/dist/lib/context.js +18 -0
- package/dist/lib/errors.js +305 -0
- package/dist/lib/events.js +208 -0
- package/dist/lib/float-text.js +126 -0
- package/dist/lib/format.js +1320 -0
- package/dist/lib/home.js +325 -0
- package/dist/lib/journal.js +122 -0
- package/dist/lib/json-text.js +733 -0
- package/dist/lib/jsonout.js +382 -0
- package/dist/lib/lock.js +516 -0
- package/dist/lib/login-name.js +202 -0
- package/dist/lib/map-limit.js +29 -0
- package/dist/lib/mkdir-parents.js +90 -0
- package/dist/lib/mongo-kernel.js +67 -0
- package/dist/lib/monitoring.js +492 -0
- package/dist/lib/platform-name.js +59 -0
- package/dist/lib/presets/common.js +390 -0
- package/dist/lib/presets/composite.js +326 -0
- package/dist/lib/presets/e2ee.js +143 -0
- package/dist/lib/presets/email.js +172 -0
- package/dist/lib/presets/guides.js +27 -0
- package/dist/lib/presets/index.js +490 -0
- package/dist/lib/presets/keycloak.js +369 -0
- package/dist/lib/presets/ldap.js +1285 -0
- package/dist/lib/presets/livechat.js +220 -0
- package/dist/lib/presets/multi-instance.js +124 -0
- package/dist/lib/presets/oidc.js +161 -0
- package/dist/lib/presets/public.js +496 -0
- package/dist/lib/presets/registry.js +64 -0
- package/dist/lib/presets/s3-minio.js +300 -0
- package/dist/lib/presets/saml.js +149 -0
- package/dist/lib/presets/scenario.js +51 -0
- package/dist/lib/presets/types.js +86 -0
- package/dist/lib/presets/voice-pbx.js +320 -0
- package/dist/lib/presets/voice.js +345 -0
- package/dist/lib/presets/webhooks.js +182 -0
- package/dist/lib/redact.js +106 -0
- package/dist/lib/seed-options.js +68 -0
- package/dist/lib/seed-profiles.js +59 -0
- package/dist/lib/targz.js +1383 -0
- package/dist/lib/teammode.js +25 -0
- package/dist/lib/tempdir.js +162 -0
- package/dist/lib/unicode-tables.js +2335 -0
- package/dist/lib/version-spec.js +357 -0
- package/dist/lib/versions.js +463 -0
- package/dist/lib/yaml-dump.js +1361 -0
- package/dist/perf/baseline.js +168 -0
- package/dist/perf/constrain.js +296 -0
- package/dist/perf/k6.js +235 -0
- package/dist/perf/mongoprof.js +171 -0
- package/dist/perf/rcmetrics.js +178 -0
- package/dist/perf/report.js +386 -0
- package/dist/perf/resources.js +224 -0
- package/dist/perf/slo.js +111 -0
- package/dist/perf/timeline.js +187 -0
- package/dist/perf/timings.js +85 -0
- package/dist/perf/verdict.js +201 -0
- package/dist/seams/aws-cli.js +126 -0
- package/dist/seams/docker-cli.js +280 -0
- package/dist/seams/exec.js +861 -0
- package/dist/seams/fs/lock.js +528 -0
- package/dist/seams/kubectl.js +83 -0
- package/dist/seams/rc-http.js +921 -0
- package/dist/seed/apply.js +190 -0
- package/dist/seed/assets.js +76 -0
- package/dist/seed/check.js +391 -0
- package/dist/seed/client.js +172 -0
- package/dist/seed/executor.js +726 -0
- package/dist/seed/history.js +281 -0
- package/dist/seed/kinds.js +91 -0
- package/dist/seed/plan.js +432 -0
- package/dist/seed/receipt.js +339 -0
- package/dist/seed/repairs.js +75 -0
- package/dist/seed/verification.js +363 -0
- package/dist/seed/wording.js +248 -0
- package/dist/web/app.js +326 -0
- package/dist/web/jobs.js +510 -0
- package/dist/web/route-deps.js +211 -0
- package/dist/web/route-table.js +213 -0
- package/dist/web/routes/backup.js +244 -0
- package/dist/web/routes/clusters.js +303 -0
- package/dist/web/routes/data.js +187 -0
- package/dist/web/routes/edge.js +82 -0
- package/dist/web/routes/index.js +63 -0
- package/dist/web/routes/jobs.js +95 -0
- package/dist/web/routes/logs.js +297 -0
- package/dist/web/routes/meta.js +191 -0
- package/dist/web/routes/people.js +151 -0
- package/dist/web/routes/perf.js +95 -0
- package/dist/web/routes/repros.js +550 -0
- package/dist/web/routes/session.js +361 -0
- package/dist/web/routes/spa.js +198 -0
- package/dist/web/security.js +475 -0
- package/dist/web/signin.js +246 -0
- package/package.json +67 -32
- package/.eslintrc +0 -94
- package/.swcrc +0 -18
- package/dist/bin.js +0 -3
- package/dist/cli.js +0 -184
- package/dist/commands/createBranch.js +0 -192
- package/src/bin.js +0 -4
- package/src/cli.ts +0 -25
- package/src/commands/createBranch.ts +0 -25
- package/src-old/logs.js +0 -323
- package/src-old/md.js +0 -191
- package/src-old/release-table.js +0 -60
- package/src-old/set-version.js +0 -614
- package/src-old/utils.js +0 -15
package/dist/web/jobs.js
ADDED
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.JobManager = exports.Job = exports.POOL_OF = exports.STOPPABLE_KINDS = exports.JOB_KINDS = exports.ACTIVE_STATUSES = exports.MAX_QUEUED_PER_KIND = exports.MAX_QUEUED_PER_POOL = exports.KEEP_RESULTS = exports.MAX_EVENTS_PER_JOB = exports.MAX_JOBS = void 0;
|
|
37
|
+
exports.installJobs = installJobs;
|
|
38
|
+
const promises_1 = require("node:timers/promises");
|
|
39
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
40
|
+
const node_perf_hooks_1 = require("node:perf_hooks");
|
|
41
|
+
const auditService = __importStar(require("../core/audit"));
|
|
42
|
+
const context_1 = require("../lib/context");
|
|
43
|
+
const errors_1 = require("../lib/errors");
|
|
44
|
+
const events_1 = require("../lib/events");
|
|
45
|
+
const exec_1 = require("../seams/exec");
|
|
46
|
+
exports.MAX_JOBS = 100;
|
|
47
|
+
exports.MAX_EVENTS_PER_JOB = 2000;
|
|
48
|
+
exports.KEEP_RESULTS = 10;
|
|
49
|
+
exports.MAX_QUEUED_PER_POOL = 32;
|
|
50
|
+
exports.MAX_QUEUED_PER_KIND = exports.MAX_QUEUED_PER_POOL;
|
|
51
|
+
exports.ACTIVE_STATUSES = new Set(['queued', 'running']);
|
|
52
|
+
/**
|
|
53
|
+
* EVERY JOB KIND THE ROUTE LAYER MAY SUBMIT.
|
|
54
|
+
*
|
|
55
|
+
* A closed tuple, so `POOL_OF` below is a TOTAL map and a kind with no pool decision is
|
|
56
|
+
* a compile error rather than a silent `undefined` -- which is what "unpooled" looks
|
|
57
|
+
* like at runtime and is indistinguishable from "somebody decided it need not be".
|
|
58
|
+
*
|
|
59
|
+
* A test guarding this would have to PARSE the route modules to find the submit sites,
|
|
60
|
+
* count them (`>= 14`, or "the parser drifted"), and match each kind to the callable beside
|
|
61
|
+
* it. Nothing about that walk could see a kind whose literal was built rather than written,
|
|
62
|
+
* and its own failure mode was a silent narrowing. Here the kind is a type: a submit site
|
|
63
|
+
* cannot name a kind that is not in this list, and this list cannot grow a member without a
|
|
64
|
+
* pool.
|
|
65
|
+
*/
|
|
66
|
+
exports.JOB_KINDS = Object.freeze([
|
|
67
|
+
'backup',
|
|
68
|
+
'capacity',
|
|
69
|
+
'clear-scale',
|
|
70
|
+
'cluster-create',
|
|
71
|
+
'cluster-delete',
|
|
72
|
+
'cluster-prepare',
|
|
73
|
+
'cluster-sweep',
|
|
74
|
+
'config-import',
|
|
75
|
+
'create',
|
|
76
|
+
'env',
|
|
77
|
+
'loadtest',
|
|
78
|
+
'monitor',
|
|
79
|
+
'monitor-off',
|
|
80
|
+
'prune',
|
|
81
|
+
'ready',
|
|
82
|
+
'restore',
|
|
83
|
+
'rollback',
|
|
84
|
+
'scale',
|
|
85
|
+
'seed',
|
|
86
|
+
'state',
|
|
87
|
+
'teardown',
|
|
88
|
+
'up',
|
|
89
|
+
'upgrade',
|
|
90
|
+
]);
|
|
91
|
+
/**
|
|
92
|
+
* The kinds a Stop may end, each because its code was read for what a Stop leaves behind.
|
|
93
|
+
* A stop is raised into every wait the job has, and a kind whose catches turn it into an
|
|
94
|
+
* ordinary failure carries on into its failure handling: an upgrade half rolled itself
|
|
95
|
+
* back, a load test left the API rate limiter off, a cluster build left CloudFormation
|
|
96
|
+
* building with nothing in houston watching it. Those stay unstoppable until read the same
|
|
97
|
+
* way. These four are the ones that get stuck waiting, and leave a workspace to delete.
|
|
98
|
+
*/
|
|
99
|
+
exports.STOPPABLE_KINDS = new Set(['create', 'up', 'ready', 'state']);
|
|
100
|
+
/**
|
|
101
|
+
* Kind -> ceiling, TOTAL.
|
|
102
|
+
*
|
|
103
|
+
* `Record<JobKind, PoolName>` is the invariant: adding a kind to `JOB_KINDS` without a
|
|
104
|
+
* row here does not compile (TS2741, "Property '<kind>' is missing"), and a row for a
|
|
105
|
+
* kind nothing submits does not compile either (TS2353). Without the type this would be two
|
|
106
|
+
* hand-kept sets and a source walk that had to be told to expect at least fourteen
|
|
107
|
+
* submit sites.
|
|
108
|
+
*/
|
|
109
|
+
exports.POOL_OF = {
|
|
110
|
+
// Engine-heavy: each costs a container engine a whole workspace.
|
|
111
|
+
create: 'heavy',
|
|
112
|
+
up: 'heavy',
|
|
113
|
+
restore: 'heavy',
|
|
114
|
+
rollback: 'heavy',
|
|
115
|
+
upgrade: 'heavy',
|
|
116
|
+
backup: 'heavy',
|
|
117
|
+
scale: 'heavy',
|
|
118
|
+
'clear-scale': 'heavy',
|
|
119
|
+
teardown: 'heavy',
|
|
120
|
+
prune: 'heavy',
|
|
121
|
+
monitor: 'heavy',
|
|
122
|
+
'monitor-off': 'heavy',
|
|
123
|
+
seed: 'heavy',
|
|
124
|
+
'config-import': 'heavy',
|
|
125
|
+
// Measurement: a pool of one, or the two runs measure each other.
|
|
126
|
+
loadtest: 'measure',
|
|
127
|
+
capacity: 'measure',
|
|
128
|
+
// Deliberately unpooled. `ready`, `state` and `env` are what the dashboard polls
|
|
129
|
+
// every few seconds; the four cluster verbs are cloud round trips that hold no local
|
|
130
|
+
// engine and take ten to twenty minutes, so a local ceiling would only queue them
|
|
131
|
+
// behind each other for no resource they contend for.
|
|
132
|
+
ready: 'none',
|
|
133
|
+
state: 'none',
|
|
134
|
+
env: 'none',
|
|
135
|
+
'cluster-create': 'none',
|
|
136
|
+
'cluster-delete': 'none',
|
|
137
|
+
'cluster-prepare': 'none',
|
|
138
|
+
'cluster-sweep': 'none',
|
|
139
|
+
};
|
|
140
|
+
class Pool {
|
|
141
|
+
constructor(size) {
|
|
142
|
+
this.size = size;
|
|
143
|
+
this.used = 0;
|
|
144
|
+
this.waiters = [];
|
|
145
|
+
}
|
|
146
|
+
tryAcquire() {
|
|
147
|
+
if (this.used >= this.size)
|
|
148
|
+
return false;
|
|
149
|
+
this.used += 1;
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
/** True with a slot; false if `signal` was aborted first, holding no slot. */
|
|
153
|
+
acquire(signal) {
|
|
154
|
+
if (this.tryAcquire())
|
|
155
|
+
return Promise.resolve(true);
|
|
156
|
+
return new Promise((resolve) => {
|
|
157
|
+
const granted = () => {
|
|
158
|
+
signal?.removeEventListener('abort', gaveUp);
|
|
159
|
+
resolve(true);
|
|
160
|
+
};
|
|
161
|
+
const gaveUp = () => {
|
|
162
|
+
const at = this.waiters.indexOf(granted);
|
|
163
|
+
if (at < 0)
|
|
164
|
+
return;
|
|
165
|
+
this.waiters.splice(at, 1);
|
|
166
|
+
resolve(false);
|
|
167
|
+
};
|
|
168
|
+
this.waiters.push(granted);
|
|
169
|
+
signal?.addEventListener('abort', gaveUp, { once: true });
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
release() {
|
|
173
|
+
const next = this.waiters.shift();
|
|
174
|
+
if (next !== undefined)
|
|
175
|
+
next();
|
|
176
|
+
else
|
|
177
|
+
this.used -= 1;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const MEASURE_POOL = new Pool(1);
|
|
181
|
+
const HEAVY_POOL = new Pool(Math.max(2, Math.floor((Number(process.env.HOUSTON_CPU_COUNT) || 4) / 2)));
|
|
182
|
+
function slotsFor(kind) {
|
|
183
|
+
const pool = exports.POOL_OF[kind];
|
|
184
|
+
if (pool === 'measure')
|
|
185
|
+
return MEASURE_POOL;
|
|
186
|
+
if (pool === 'heavy')
|
|
187
|
+
return HEAVY_POOL;
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
function logJobStarted(jobId, kind, label, verb) {
|
|
191
|
+
try {
|
|
192
|
+
const eventlog = require('../core/eventlog');
|
|
193
|
+
eventlog.jobStarted(jobId, kind, label, verb);
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
// A durable log is best-effort and must never break the operation it describes.
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function logJobEnded(job, kind) {
|
|
200
|
+
try {
|
|
201
|
+
const eventlog = require('../core/eventlog');
|
|
202
|
+
eventlog.jobEnded(job.id, kind, job.label, job.status, job.error ?? '', job.verb);
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
// The same boundary: a call-time import and a best-effort write.
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
class Job {
|
|
209
|
+
constructor(id, kind, label = '', actor = '', queued = false) {
|
|
210
|
+
this.id = id;
|
|
211
|
+
this.kind = kind;
|
|
212
|
+
this.label = label;
|
|
213
|
+
this.actor = actor;
|
|
214
|
+
this.events = [];
|
|
215
|
+
this.startedAt = Date.now() / 1000;
|
|
216
|
+
this.finishedAt = null;
|
|
217
|
+
this.result = null;
|
|
218
|
+
this.error = null;
|
|
219
|
+
this.errorKind = null;
|
|
220
|
+
this.resultDropped = false;
|
|
221
|
+
/**
|
|
222
|
+
* A cluster build's region. Its label is only the cluster's NAME, and a name is unique per
|
|
223
|
+
* region, not per account: matching on the name alone hid a different, billing cluster of
|
|
224
|
+
* the same name in another region while this one was built.
|
|
225
|
+
*/
|
|
226
|
+
this.region = '';
|
|
227
|
+
/**
|
|
228
|
+
* What the job does, where its kind is two things: a teardown deletes or takes down, a state
|
|
229
|
+
* job stops, starts or restarts. Activity and the rail could not tell them apart.
|
|
230
|
+
*/
|
|
231
|
+
this.verb = '';
|
|
232
|
+
/** Who pressed Stop, once somebody has; the job then ends at its next wait. */
|
|
233
|
+
this.stoppedBy = '';
|
|
234
|
+
/** Whether its own cleanup said it took everything back (`NOTHING_LEFT`). */
|
|
235
|
+
this.nothingLeft = false;
|
|
236
|
+
/**
|
|
237
|
+
* A create's audit line, held until it settles the workspace's name (or ends without one),
|
|
238
|
+
* so History names the workspace rather than the version asked for. Null once written.
|
|
239
|
+
*/
|
|
240
|
+
this.auditOnName = null;
|
|
241
|
+
this.stopper = new AbortController();
|
|
242
|
+
this.emitted = 0;
|
|
243
|
+
this.emit = (item) => {
|
|
244
|
+
// A create names its workspace once it has settled the name (`announceName`); until then
|
|
245
|
+
// it is labelled with the version asked for, which no workspace answers to.
|
|
246
|
+
if (item.code === 'workspace-name' && typeof item.data.workspace === 'string') {
|
|
247
|
+
this.label = item.data.workspace;
|
|
248
|
+
this.writeHeldAudit();
|
|
249
|
+
}
|
|
250
|
+
if (item.code === events_1.NOTHING_LEFT)
|
|
251
|
+
this.nothingLeft = true;
|
|
252
|
+
this.events.push(item);
|
|
253
|
+
this.emitted += 1;
|
|
254
|
+
const overflow = this.events.length - exports.MAX_EVENTS_PER_JOB;
|
|
255
|
+
if (overflow > 0)
|
|
256
|
+
this.events.splice(0, overflow);
|
|
257
|
+
};
|
|
258
|
+
this.status = queued ? 'queued' : 'running';
|
|
259
|
+
}
|
|
260
|
+
get nEvents() {
|
|
261
|
+
return this.emitted;
|
|
262
|
+
}
|
|
263
|
+
/** The held audit line, with the label as it stands; once. */
|
|
264
|
+
writeHeldAudit() {
|
|
265
|
+
const write = this.auditOnName;
|
|
266
|
+
this.auditOnName = null;
|
|
267
|
+
write?.(this.label);
|
|
268
|
+
}
|
|
269
|
+
forgetResult() {
|
|
270
|
+
if (this.result === null && !this.resultDropped)
|
|
271
|
+
return;
|
|
272
|
+
this.result = null;
|
|
273
|
+
this.resultDropped = true;
|
|
274
|
+
for (const item of this.events) {
|
|
275
|
+
if (item.terminal) {
|
|
276
|
+
delete item.data.result;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
summary() {
|
|
281
|
+
return {
|
|
282
|
+
id: this.id,
|
|
283
|
+
kind: this.kind,
|
|
284
|
+
label: this.label,
|
|
285
|
+
actor: this.actor,
|
|
286
|
+
status: this.status,
|
|
287
|
+
started_at: this.startedAt,
|
|
288
|
+
finished_at: this.finishedAt,
|
|
289
|
+
n_events: this.nEvents,
|
|
290
|
+
error: this.error,
|
|
291
|
+
error_kind: this.errorKind,
|
|
292
|
+
result_dropped: this.resultDropped,
|
|
293
|
+
region: this.region,
|
|
294
|
+
verb: this.verb,
|
|
295
|
+
stoppable: exports.STOPPABLE_KINDS.has(this.kind) && exports.ACTIVE_STATUSES.has(this.status),
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
snapshot(since) {
|
|
299
|
+
const first = this.emitted - this.events.length;
|
|
300
|
+
const start = Math.max(0, since - first);
|
|
301
|
+
return [this.events.slice(start).map(events_1.asDict), !exports.ACTIVE_STATUSES.has(this.status), this.emitted];
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
exports.Job = Job;
|
|
305
|
+
class JobManager {
|
|
306
|
+
constructor() {
|
|
307
|
+
this.jobs = new Map();
|
|
308
|
+
this.running = new Map();
|
|
309
|
+
this.draining = false;
|
|
310
|
+
this.nextId = 0;
|
|
311
|
+
/** A queue is its own async resource, as a worker pool would be. */
|
|
312
|
+
this.scheduler = new node_async_hooks_1.AsyncResource('houston-job-scheduler');
|
|
313
|
+
}
|
|
314
|
+
get(jobId) {
|
|
315
|
+
return this.jobs.get(jobId);
|
|
316
|
+
}
|
|
317
|
+
listJobs() {
|
|
318
|
+
return [...this.jobs.values()].reverse().map((job) => job.summary());
|
|
319
|
+
}
|
|
320
|
+
submit(kind, target, options = {}) {
|
|
321
|
+
if (this.draining) {
|
|
322
|
+
throw new errors_1.ConflictError('houston is shutting down and is not accepting new work');
|
|
323
|
+
}
|
|
324
|
+
const request = (0, context_1.currentContext)();
|
|
325
|
+
const actor = options.actor || request.actor;
|
|
326
|
+
const label = options.label ?? '';
|
|
327
|
+
const pool = slotsFor(kind);
|
|
328
|
+
if (pool !== undefined) {
|
|
329
|
+
const waiting = [...this.jobs.values()].filter((candidate) => candidate.status === 'queued' && slotsFor(candidate.kind) === pool).length;
|
|
330
|
+
if (waiting >= exports.MAX_QUEUED_PER_POOL) {
|
|
331
|
+
throw new errors_1.ConflictError(`${waiting} job(s) are already waiting for a free slot. Let those finish first`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
this.nextId += 1;
|
|
335
|
+
const id = `job_${this.nextId.toString(16).padStart(10, '0')}`;
|
|
336
|
+
const job = new Job(id, kind, label, actor, pool !== undefined);
|
|
337
|
+
job.region = options.region ?? '';
|
|
338
|
+
job.verb = options.verb ?? '';
|
|
339
|
+
if (options.auditWhenNamed === true) {
|
|
340
|
+
job.auditOnName = (named) => auditService.audit(actor, kind, named, { origin: request.origin, outcome: 'accepted' });
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
auditService.audit(actor, kind, label, { origin: request.origin, outcome: 'accepted' });
|
|
344
|
+
}
|
|
345
|
+
this.jobs.set(id, job);
|
|
346
|
+
this.evict();
|
|
347
|
+
this.trimResults();
|
|
348
|
+
const captured = { actor, origin: request.origin, jobId: id, workspace: label };
|
|
349
|
+
const task = (0, promises_1.setImmediate)()
|
|
350
|
+
.then(async () => this.scheduler.runInAsyncScope(() => (0, context_1.runWithContext)(captured, () => this.run(job, kind, target, pool))))
|
|
351
|
+
.finally(() => this.running.delete(id));
|
|
352
|
+
this.running.set(id, task);
|
|
353
|
+
return job;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Stop a queued or running job: every wait in it rejects (see `stoppable`), so it unwinds
|
|
357
|
+
* through its own cleanup and ends as stopped. What it had done stays done. False if it
|
|
358
|
+
* had already ended.
|
|
359
|
+
*/
|
|
360
|
+
stop(jobId, actor) {
|
|
361
|
+
const job = this.jobs.get(jobId);
|
|
362
|
+
if (job === undefined || !exports.ACTIVE_STATUSES.has(job.status))
|
|
363
|
+
return false;
|
|
364
|
+
if (!exports.STOPPABLE_KINDS.has(job.kind))
|
|
365
|
+
return false;
|
|
366
|
+
if (job.stoppedBy === '') {
|
|
367
|
+
job.stoppedBy = actor || 'someone';
|
|
368
|
+
job.emit((0, events_1.event)(`stopping — asked by ${job.stoppedBy}`, { phase: 'done', level: 'warn' }));
|
|
369
|
+
auditService.audit(actor, 'job-stop', `${job.kind} ${job.label}`.trim(), {
|
|
370
|
+
origin: (0, context_1.currentContext)().origin,
|
|
371
|
+
});
|
|
372
|
+
job.stopper.abort();
|
|
373
|
+
}
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
/** How many jobs are still running. */
|
|
377
|
+
active() {
|
|
378
|
+
return this.running.size;
|
|
379
|
+
}
|
|
380
|
+
async drain(timeoutMs = 25000) {
|
|
381
|
+
this.draining = true;
|
|
382
|
+
const deadline = node_perf_hooks_1.performance.now() + timeoutMs;
|
|
383
|
+
const pending = [...this.running.entries()];
|
|
384
|
+
for (const [, task] of pending) {
|
|
385
|
+
const remaining = Math.max(0, deadline - node_perf_hooks_1.performance.now());
|
|
386
|
+
let timer;
|
|
387
|
+
try {
|
|
388
|
+
await Promise.race([
|
|
389
|
+
task,
|
|
390
|
+
new Promise((resolve) => {
|
|
391
|
+
timer = setTimeout(resolve, remaining);
|
|
392
|
+
}),
|
|
393
|
+
]);
|
|
394
|
+
}
|
|
395
|
+
finally {
|
|
396
|
+
if (timer !== undefined)
|
|
397
|
+
clearTimeout(timer);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return pending.filter(([id]) => this.running.has(id)).map(([id]) => id);
|
|
401
|
+
}
|
|
402
|
+
async run(job, kind, target, pool) {
|
|
403
|
+
let slot = false;
|
|
404
|
+
try {
|
|
405
|
+
logJobStarted(job.id, kind, job.label, job.verb);
|
|
406
|
+
if (pool !== undefined) {
|
|
407
|
+
slot = pool.tryAcquire();
|
|
408
|
+
if (!slot) {
|
|
409
|
+
job.emit((0, events_1.event)(`waiting for a free ${kind} slot — something else is using the machine`, {
|
|
410
|
+
phase: 'queued',
|
|
411
|
+
}));
|
|
412
|
+
slot = await pool.acquire(job.stopper.signal);
|
|
413
|
+
}
|
|
414
|
+
// Stopped while queued: it ends without running at all.
|
|
415
|
+
if (job.stopper.signal.aborted)
|
|
416
|
+
throw new exec_1.Interrupted();
|
|
417
|
+
job.status = 'running';
|
|
418
|
+
}
|
|
419
|
+
const result = await (0, exec_1.stoppable)(job.stopper.signal, async () => await target(job.emit));
|
|
420
|
+
job.result = result;
|
|
421
|
+
job.finishedAt = Date.now() / 1000;
|
|
422
|
+
job.status = 'done';
|
|
423
|
+
job.emit((0, events_1.event)('done', { phase: 'done', terminal: true, data: { result } }));
|
|
424
|
+
}
|
|
425
|
+
catch (caught) {
|
|
426
|
+
job.finishedAt = Date.now() / 1000;
|
|
427
|
+
job.status = 'error';
|
|
428
|
+
if (job.stopper.signal.aborted) {
|
|
429
|
+
// The reason is the Stop -- but a houston error raised on the way out keeps its own
|
|
430
|
+
// words, which may be the only place a recovery instruction is written down.
|
|
431
|
+
// What it had done stays -- unless its cleanup has just said it took all of it back,
|
|
432
|
+
// where saying so contradicted the line above it.
|
|
433
|
+
const stopped = `stopped by ${job.stoppedBy} before it finished; ` +
|
|
434
|
+
(job.nothingLeft ? 'nothing of it was left' : 'what it had done stays');
|
|
435
|
+
job.error = caught instanceof errors_1.ReproError ? `${caught.message} (${stopped})` : stopped;
|
|
436
|
+
job.errorKind = 'Stopped';
|
|
437
|
+
job.emit((0, events_1.event)(job.error, {
|
|
438
|
+
phase: 'done',
|
|
439
|
+
level: 'error',
|
|
440
|
+
terminal: true,
|
|
441
|
+
data: { error: job.error, kind: 'Stopped' },
|
|
442
|
+
}));
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
const error = caught instanceof Error ? caught : new Error((0, errors_1.errorText)(caught));
|
|
446
|
+
job.error = error.message || (0, errors_1.errorText)(caught);
|
|
447
|
+
job.errorKind = caught instanceof errors_1.ReproError ? caught.constructor.name : 'InternalError';
|
|
448
|
+
job.emit((0, events_1.event)(caught instanceof errors_1.ReproError ? error.message : `internal error: ${error.message}`, {
|
|
449
|
+
phase: 'done',
|
|
450
|
+
level: 'error',
|
|
451
|
+
terminal: true,
|
|
452
|
+
data: caught instanceof errors_1.ReproError
|
|
453
|
+
? { error: error.message, kind: caught.constructor.name }
|
|
454
|
+
: { error: error.message },
|
|
455
|
+
}));
|
|
456
|
+
}
|
|
457
|
+
finally {
|
|
458
|
+
// A create that ended before it named its workspace is still on record, by the label it had.
|
|
459
|
+
job.writeHeldAudit();
|
|
460
|
+
auditService.audit(job.actor, kind, job.label, {
|
|
461
|
+
origin: (0, context_1.currentContext)().origin,
|
|
462
|
+
outcome: job.errorKind === 'Stopped' ? 'stopped' : job.status,
|
|
463
|
+
});
|
|
464
|
+
logJobEnded(job, kind);
|
|
465
|
+
if (pool !== undefined && slot)
|
|
466
|
+
pool.release();
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
trimResults() {
|
|
470
|
+
const finished = [...this.jobs.values()].filter((job) => !exports.ACTIVE_STATUSES.has(job.status));
|
|
471
|
+
const drop = finished.slice(0, Math.max(0, finished.length - exports.KEEP_RESULTS));
|
|
472
|
+
for (const job of drop)
|
|
473
|
+
job.forgetResult();
|
|
474
|
+
}
|
|
475
|
+
evict() {
|
|
476
|
+
for (const [id, job] of this.jobs) {
|
|
477
|
+
if (this.jobs.size <= exports.MAX_JOBS)
|
|
478
|
+
return;
|
|
479
|
+
if (!exports.ACTIVE_STATUSES.has(job.status))
|
|
480
|
+
this.jobs.delete(id);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
exports.JobManager = JobManager;
|
|
485
|
+
/**
|
|
486
|
+
* Attach one registry to one Fastify application and drain it during shutdown.
|
|
487
|
+
*
|
|
488
|
+
* Routes reach the registry through the decorated application, never a module global,
|
|
489
|
+
* so two in-process servers cannot read or stop each other's jobs.
|
|
490
|
+
*/
|
|
491
|
+
function installJobs(app, { manager = new JobManager(), drainTimeoutMs = 25000, onStopping, onAbandoned, } = {}) {
|
|
492
|
+
app.decorate('jobs', manager);
|
|
493
|
+
// A job's SSE response stays open until the job finishes. onClose runs only
|
|
494
|
+
// after those HTTP responses close, so draining there waits on itself.
|
|
495
|
+
app.addHook('preClose', async () => {
|
|
496
|
+
let abandoned = await manager.drain(drainTimeoutMs);
|
|
497
|
+
if (abandoned.length > 0) {
|
|
498
|
+
// STOPPED, then given a moment to unwind through their own cleanup, rather than left
|
|
499
|
+
// running in a server whose listener is already closed. What cannot be stopped is
|
|
500
|
+
// reported, and `serve` ends without it (`cli/serve`).
|
|
501
|
+
const stopping = abandoned.filter((id) => manager.stop(id, 'serve shutdown'));
|
|
502
|
+
if (stopping.length > 0)
|
|
503
|
+
onStopping?.(stopping);
|
|
504
|
+
abandoned = await manager.drain(Math.min(drainTimeoutMs, 10000));
|
|
505
|
+
}
|
|
506
|
+
if (abandoned.length > 0)
|
|
507
|
+
onAbandoned?.(abandoned);
|
|
508
|
+
});
|
|
509
|
+
return manager;
|
|
510
|
+
}
|