mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-03 06:51:00 +02:00
saving
This commit is contained in:
parent
e8c7a4f6e0
commit
ffd97375a8
160 changed files with 6704 additions and 1895 deletions
33
ts/packages/base/src/runtime/config.ts
Normal file
33
ts/packages/base/src/runtime/config.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* Effect Config contracts for process/runtime settings.
|
||||
*
|
||||
* These declarations preserve the existing environment variable names while
|
||||
* moving reads to a typed Effect boundary.
|
||||
*/
|
||||
|
||||
import { Config, Effect } from "effect";
|
||||
import * as O from "effect/Option";
|
||||
|
||||
export interface ProcessorRuntimeConfigOptions {
|
||||
readonly manageProcessSignals?: boolean;
|
||||
}
|
||||
|
||||
export const optionalStringConfig = Effect.fn("optionalStringConfig")(function* (name: string) {
|
||||
return O.getOrUndefined(yield* Config.string(name).pipe(Config.option));
|
||||
});
|
||||
|
||||
export const loadProcessorRuntimeConfig = Effect.fn("loadProcessorRuntimeConfig")(function* (
|
||||
id: string,
|
||||
options: ProcessorRuntimeConfigOptions = {},
|
||||
) {
|
||||
const natsUrl = yield* optionalStringConfig("NATS_URL");
|
||||
const pulsarHost = yield* optionalStringConfig("PULSAR_HOST");
|
||||
const metricsPort = yield* Config.number("METRICS_PORT").pipe(Config.withDefault(8000));
|
||||
|
||||
return {
|
||||
id,
|
||||
pubsubUrl: natsUrl ?? pulsarHost ?? "nats://localhost:4222",
|
||||
metricsPort,
|
||||
manageProcessSignals: options.manageProcessSignals ?? true,
|
||||
};
|
||||
});
|
||||
10
ts/packages/base/src/runtime/index.ts
Normal file
10
ts/packages/base/src/runtime/index.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
export {
|
||||
defaultMessagingRuntimeConfig,
|
||||
loadMessagingRuntimeConfig,
|
||||
type MessagingRuntimeConfig,
|
||||
} from "./messaging-config.js";
|
||||
export {
|
||||
loadProcessorRuntimeConfig,
|
||||
optionalStringConfig,
|
||||
type ProcessorRuntimeConfigOptions,
|
||||
} from "./config.js";
|
||||
41
ts/packages/base/src/runtime/messaging-config.ts
Normal file
41
ts/packages/base/src/runtime/messaging-config.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* Effect Config contracts for messaging runtime behavior.
|
||||
*/
|
||||
|
||||
import { Config, Effect } from "effect";
|
||||
|
||||
export interface MessagingRuntimeConfig {
|
||||
readonly consumerReceiveTimeoutMs: number;
|
||||
readonly consumerErrorBackoffMs: number;
|
||||
readonly rateLimitRetryMs: number;
|
||||
readonly requestTimeoutMs: number;
|
||||
}
|
||||
|
||||
export const defaultMessagingRuntimeConfig: MessagingRuntimeConfig = {
|
||||
consumerReceiveTimeoutMs: 2_000,
|
||||
consumerErrorBackoffMs: 1_000,
|
||||
rateLimitRetryMs: 10_000,
|
||||
requestTimeoutMs: 300_000,
|
||||
};
|
||||
|
||||
export const loadMessagingRuntimeConfig = Effect.fn("loadMessagingRuntimeConfig")(function* () {
|
||||
const consumerReceiveTimeoutMs = yield* Config.number("TG_CONSUMER_RECEIVE_TIMEOUT_MS").pipe(
|
||||
Config.withDefault(defaultMessagingRuntimeConfig.consumerReceiveTimeoutMs),
|
||||
);
|
||||
const consumerErrorBackoffMs = yield* Config.number("TG_CONSUMER_ERROR_BACKOFF_MS").pipe(
|
||||
Config.withDefault(defaultMessagingRuntimeConfig.consumerErrorBackoffMs),
|
||||
);
|
||||
const rateLimitRetryMs = yield* Config.number("TG_RATE_LIMIT_RETRY_MS").pipe(
|
||||
Config.withDefault(defaultMessagingRuntimeConfig.rateLimitRetryMs),
|
||||
);
|
||||
const requestTimeoutMs = yield* Config.number("TG_REQUEST_TIMEOUT_MS").pipe(
|
||||
Config.withDefault(defaultMessagingRuntimeConfig.requestTimeoutMs),
|
||||
);
|
||||
|
||||
return {
|
||||
consumerReceiveTimeoutMs,
|
||||
consumerErrorBackoffMs,
|
||||
rateLimitRetryMs,
|
||||
requestTimeoutMs,
|
||||
} satisfies MessagingRuntimeConfig;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue