11import { env } from "~/env.server" ;
22import type { RunOpsShardKnobs } from "~/v3/runOpsShards.server" ;
33
4- // Pool configuration for one run-ops store (writer + replica), resolved at the app boundary (IoC).
5- // Every value reproduces today's run-ops builder expressions. Kept separate from db.server (which
4+ // Pool configuration for one run-ops store (writer + replica). Kept separate from db.server (which
65// ~156 tests mock wholesale) so a new export breaks no mock.
76export type ResolvedPoolKnobs = {
87 writerPoolTimeout : number ;
@@ -17,65 +16,65 @@ export type ResolvedPoolKnobs = {
1716
1817type Role = "new" | "legacy" ;
1918
20- // Resolve the pool knobs for a run-ops role, reproducing today 's builder expressions exactly.
21- // descriptorKnobs (gen-2 shards only) override the pool fields.
22- // Transaction resilience is a SEPARATE mechanism (resolveTransactionResilience) and is not here .
23- export function resolveRunOpsPoolKnobs (
24- role : Role ,
25- descriptorKnobs ?: RunOpsShardKnobs
19+ // PURE: overlay a gen-2 shard's descriptor knobs on a role 's resolved defaults. This holds the only
20+ // logic (per-field override), so a test drives it with literal defaults and literal overrides —
21+ // no env import, no circular assertion against the same env expression the impl reads .
22+ export function applyPoolKnobOverrides (
23+ defaults : ResolvedPoolKnobs ,
24+ k ?: RunOpsShardKnobs
2625) : ResolvedPoolKnobs {
27- const k = descriptorKnobs ;
26+ return {
27+ writerPoolTimeout : k ?. writerPoolTimeout ?? defaults . writerPoolTimeout ,
28+ writerConnectionTimeout : k ?. writerConnectionTimeout ?? defaults . writerConnectionTimeout ,
29+ writerDriverAdapter : k ?. writerDriverAdapter ?? defaults . writerDriverAdapter ,
30+ connectionLimit : k ?. connectionLimit ?? defaults . connectionLimit ,
31+ replicaConnectionLimit : k ?. replicaConnectionLimit ?? defaults . replicaConnectionLimit ,
32+ replicaPoolTimeout : k ?. replicaPoolTimeout ?? defaults . replicaPoolTimeout ,
33+ replicaConnectionTimeout : k ?. replicaConnectionTimeout ?? defaults . replicaConnectionTimeout ,
34+ replicaDriverAdapter : k ?. replicaDriverAdapter ?? defaults . replicaDriverAdapter ,
35+ } ;
36+ }
2837
38+ // The env-derived defaults for a role, reproducing today's run-ops builder expressions exactly. A
39+ // flat mapping (no logic), verified by inspection against the former builders. Transaction
40+ // resilience is a SEPARATE mechanism (resolveTransactionResilience) and is not here.
41+ function poolKnobDefaults ( role : Role ) : ResolvedPoolKnobs {
2942 if ( role === "legacy" ) {
3043 return {
3144 writerPoolTimeout :
32- k ?. writerPoolTimeout ??
33- env . RUN_OPS_LEGACY_DATABASE_WRITER_POOL_TIMEOUT ??
34- env . DATABASE_POOL_TIMEOUT ,
45+ env . RUN_OPS_LEGACY_DATABASE_WRITER_POOL_TIMEOUT ?? env . DATABASE_POOL_TIMEOUT ,
3546 writerConnectionTimeout :
36- k ?. writerConnectionTimeout ??
37- env . RUN_OPS_LEGACY_DATABASE_WRITER_CONNECTION_TIMEOUT ??
38- env . DATABASE_CONNECTION_TIMEOUT ,
39- writerDriverAdapter :
40- k ?. writerDriverAdapter ?? env . RUN_OPS_LEGACY_DATABASE_WRITER_DRIVER_ADAPTER === "1" ,
41- connectionLimit : k ?. connectionLimit ?? env . DATABASE_CONNECTION_LIMIT ,
42- replicaConnectionLimit : k ?. replicaConnectionLimit ?? env . DATABASE_CONNECTION_LIMIT ,
47+ env . RUN_OPS_LEGACY_DATABASE_WRITER_CONNECTION_TIMEOUT ?? env . DATABASE_CONNECTION_TIMEOUT ,
48+ writerDriverAdapter : env . RUN_OPS_LEGACY_DATABASE_WRITER_DRIVER_ADAPTER === "1" ,
49+ connectionLimit : env . DATABASE_CONNECTION_LIMIT ,
50+ replicaConnectionLimit : env . DATABASE_CONNECTION_LIMIT ,
4351 replicaPoolTimeout :
44- k ?. replicaPoolTimeout ??
45- env . RUN_OPS_LEGACY_DATABASE_READ_REPLICA_POOL_TIMEOUT ??
46- env . DATABASE_POOL_TIMEOUT ,
52+ env . RUN_OPS_LEGACY_DATABASE_READ_REPLICA_POOL_TIMEOUT ?? env . DATABASE_POOL_TIMEOUT ,
4753 replicaConnectionTimeout :
48- k ?. replicaConnectionTimeout ??
4954 env . RUN_OPS_LEGACY_DATABASE_READ_REPLICA_CONNECTION_TIMEOUT ??
5055 env . DATABASE_CONNECTION_TIMEOUT ,
51- replicaDriverAdapter :
52- k ?. replicaDriverAdapter ?? env . RUN_OPS_LEGACY_DATABASE_REPLICA_DRIVER_ADAPTER === "1" ,
56+ replicaDriverAdapter : env . RUN_OPS_LEGACY_DATABASE_REPLICA_DRIVER_ADAPTER === "1" ,
5357 } ;
5458 }
5559
5660 return {
57- writerPoolTimeout :
58- k ?. writerPoolTimeout ?? env . RUN_OPS_DATABASE_WRITER_POOL_TIMEOUT ?? env . DATABASE_POOL_TIMEOUT ,
61+ writerPoolTimeout : env . RUN_OPS_DATABASE_WRITER_POOL_TIMEOUT ?? env . DATABASE_POOL_TIMEOUT ,
5962 writerConnectionTimeout :
60- k ?. writerConnectionTimeout ??
61- env . RUN_OPS_DATABASE_WRITER_CONNECTION_TIMEOUT ??
62- env . DATABASE_CONNECTION_TIMEOUT ,
63- writerDriverAdapter :
64- k ?. writerDriverAdapter ?? env . RUN_OPS_DATABASE_WRITER_DRIVER_ADAPTER === "1" ,
65- connectionLimit : k ?. connectionLimit ?? env . DATABASE_CONNECTION_LIMIT ,
63+ env . RUN_OPS_DATABASE_WRITER_CONNECTION_TIMEOUT ?? env . DATABASE_CONNECTION_TIMEOUT ,
64+ writerDriverAdapter : env . RUN_OPS_DATABASE_WRITER_DRIVER_ADAPTER === "1" ,
65+ connectionLimit : env . DATABASE_CONNECTION_LIMIT ,
6666 replicaConnectionLimit :
67- k ?. replicaConnectionLimit ??
68- env . RUN_OPS_DATABASE_READ_REPLICA_CONNECTION_LIMIT ??
69- env . DATABASE_CONNECTION_LIMIT ,
70- replicaPoolTimeout :
71- k ?. replicaPoolTimeout ??
72- env . RUN_OPS_DATABASE_READ_REPLICA_POOL_TIMEOUT ??
73- env . DATABASE_POOL_TIMEOUT ,
67+ env . RUN_OPS_DATABASE_READ_REPLICA_CONNECTION_LIMIT ?? env . DATABASE_CONNECTION_LIMIT ,
68+ replicaPoolTimeout : env . RUN_OPS_DATABASE_READ_REPLICA_POOL_TIMEOUT ?? env . DATABASE_POOL_TIMEOUT ,
7469 replicaConnectionTimeout :
75- k ?. replicaConnectionTimeout ??
76- env . RUN_OPS_DATABASE_READ_REPLICA_CONNECTION_TIMEOUT ??
77- env . DATABASE_CONNECTION_TIMEOUT ,
78- replicaDriverAdapter :
79- k ?. replicaDriverAdapter ?? env . RUN_OPS_DATABASE_REPLICA_DRIVER_ADAPTER === "1" ,
70+ env . RUN_OPS_DATABASE_READ_REPLICA_CONNECTION_TIMEOUT ?? env . DATABASE_CONNECTION_TIMEOUT ,
71+ replicaDriverAdapter : env . RUN_OPS_DATABASE_REPLICA_DRIVER_ADAPTER === "1" ,
8072 } ;
8173}
74+
75+ export function resolveRunOpsPoolKnobs (
76+ role : Role ,
77+ descriptorKnobs ?: RunOpsShardKnobs
78+ ) : ResolvedPoolKnobs {
79+ return applyPoolKnobOverrides ( poolKnobDefaults ( role ) , descriptorKnobs ) ;
80+ }
0 commit comments