Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit 7aaad77

Browse files
committed
env vars from a file
1 parent faa1646 commit 7aaad77

File tree

6 files changed

+47
-11
lines changed

6 files changed

+47
-11
lines changed

pnpm-lock.yaml

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

substream-listener/.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SVIX_TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTI3NjcxODYsImV4cCI6MjAyODEyNzE4NiwibmJmIjoxNzEyNzY3MTg2LCJpc3MiOiJzdml4LXNlcnZlciIsInN1YiI6Im9yZ18yM3JiOFlkR3FNVDBxSXpwZ0d3ZFhmSGlyTXUifQ.Gnj4vMl0qls2Q6ks690ZEUAW7h6VsgUHc6iwFWNPa1I"

substream-listener/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.1",
44
"scripts": {
55
"start": "tsx ./src/index.mts",
6-
"dev": "tsx --watch ./src/index.mts | pino-pretty"
6+
"dev": "tsx --env-file .env --watch ./src/index.mts | pino-pretty"
77
},
88
"dependencies": {
99
"@connectrpc/connect-node": "1.4.0",
@@ -18,7 +18,9 @@
1818
"prom-client": "^15.1.2",
1919
"svix": "^1.21.0",
2020
"uWebSockets.js": "github:uNetworking/uWebSockets.js#semver:^20",
21-
"viem": "^2.9.31"
21+
"viem": "^2.9.31",
22+
"znv": "^0.4.0",
23+
"zod": "^3.23.6"
2224
},
2325
"devDependencies": {
2426
"@tsconfig/node20": "^20.1.4",

substream-listener/src/index.mts

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import {
88
} from "./prometheus.mjs";
99
import { logger } from "./logger.mjs";
1010
import { createScheduler } from "./scheduler.mjs";
11+
import { REDIS_HOST, REDIS_PASSWORD, REDIS_PORT } from "./utils.mjs";
1112

1213
const { schedule, start, stop, readiness } = createScheduler({
1314
queueName: "substream-sink-scheduler",
1415
logger: logger.child({ module: "substream-sink-scheduler" }),
1516
redis: {
16-
host: "localhost",
17-
port: 6379,
18-
password: undefined,
17+
host: REDIS_HOST,
18+
port: REDIS_PORT,
19+
password: REDIS_PASSWORD,
1920
},
2021
});
2122

substream-listener/src/scheduler.mts

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ import path from "node:path";
1818
import { Svix } from "svix";
1919
import { Address } from "viem";
2020
import { bullMqRedis } from "./prometheus.mjs";
21+
import { SVIX_HOST_URL, SVIX_TOKEN } from "./utils.mjs";
2122

2223
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
2324
const __dirname = path.dirname(__filename);
2425

25-
const svix = new Svix(
26-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTI3NjcxODYsImV4cCI6MjAyODEyNzE4NiwibmJmIjoxNzEyNzY3MTg2LCJpc3MiOiJzdml4LXNlcnZlciIsInN1YiI6Im9yZ18yM3JiOFlkR3FNVDBxSXpwZ0d3ZFhmSGlyTXUifQ.Gnj4vMl0qls2Q6ks690ZEUAW7h6VsgUHc6iwFWNPa1I",
27-
{
28-
serverUrl: "http://localhost:8071",
29-
},
30-
);
26+
const svix = new Svix(SVIX_TOKEN, {
27+
serverUrl: SVIX_HOST_URL,
28+
});
3129

3230
const spkgPath = path.join(
3331
__dirname,
@@ -81,6 +79,7 @@ export function createScheduler(config: {
8179

8280
async function initQueueAndWorkers() {
8381
if (!redisConnection) {
82+
logger.error("Redis connection not initialized");
8483
return;
8584
}
8685

@@ -253,6 +252,7 @@ export function createScheduler(config: {
253252
host: config.redis.host,
254253
port: config.redis.port,
255254
password: config.redis?.password,
255+
connectionName: config.queueName,
256256
retryStrategy(times) {
257257
return Math.min(times * 500, 2000);
258258
},

substream-listener/src/utils.mts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { parseEnv } from "znv";
2+
import { z } from "zod";
3+
4+
export const {
5+
REDIS_HOST,
6+
REDIS_PASSWORD,
7+
REDIS_PORT,
8+
SVIX_TOKEN,
9+
SVIX_HOST_URL,
10+
} = parseEnv(process.env, {
11+
REDIS_HOST: z.string().default("localhost"),
12+
REDIS_PORT: z.number().default(6379),
13+
REDIS_PASSWORD: z.string().optional(),
14+
SVIX_TOKEN: z.string(),
15+
SVIX_HOST_URL: z.string().default("http://localhost:8071"),
16+
});

0 commit comments

Comments
 (0)