Skip to content

Commit 01d9e5d

Browse files
committed
feat: scaffold packages_worker service with shared config and db helpers
Signed-off-by: Mouad BANI <mouad-mb@outlook.com>
1 parent d502547 commit 01d9e5d

6 files changed

Lines changed: 104 additions & 10 deletions

File tree

pnpm-lock.yaml

Lines changed: 38 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@crowd/packages-worker",
3+
"private": true,
4+
"scripts": {
5+
"start:packages-worker": "SERVICE=packages-worker tsx src/bin/packages-worker.ts",
6+
"start:github-repos-enricher": "SERVICE=github-repos-enricher tsx src/bin/github-repos-enricher.ts",
7+
"start:debug:packages-worker:local": "set -a && . ../../../backend/.env.dist.local && . ../../../backend/.env.override.local && set +a && SERVICE=packages-worker LOG_LEVEL=trace tsx --inspect=0.0.0.0:9233 src/bin/packages-worker.ts",
8+
"start:debug:github-repos-enricher:local": "set -a && . ../../../backend/.env.dist.local && . ../../../backend/.env.override.local && set +a && SERVICE=github-repos-enricher LOG_LEVEL=trace tsx --inspect=0.0.0.0:9234 src/bin/github-repos-enricher.ts",
9+
"dev:packages-worker:local": "nodemon --watch src --watch ../../libs --ext ts --exec pnpm run start:debug:packages-worker:local",
10+
"dev:github-repos-enricher:local": "nodemon --watch src --watch ../../libs --ext ts --exec pnpm run start:debug:github-repos-enricher:local",
11+
"lint": "npx eslint --ext .ts src --max-warnings=0",
12+
"format": "npx prettier --write \"src/**/*.ts\"",
13+
"format-check": "npx prettier --check .",
14+
"tsc-check": "tsc --noEmit"
15+
},
16+
"dependencies": {
17+
"@crowd/common": "workspace:*",
18+
"@crowd/data-access-layer": "workspace:*",
19+
"@crowd/database": "workspace:*",
20+
"@crowd/logging": "workspace:*",
21+
"tsx": "^4.7.1",
22+
"typescript": "^5.6.3"
23+
},
24+
"devDependencies": {
25+
"@types/node": "^20.8.2",
26+
"nodemon": "^3.0.1"
27+
}
28+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export function getPackagesDbConfig() {
2+
return {
3+
host: process.env.CROWD_PACKAGES_DB_WRITE_HOST,
4+
port: parseInt(process.env.CROWD_PACKAGES_DB_PORT ?? '5432', 10),
5+
database: process.env.CROWD_PACKAGES_DB_DATABASE,
6+
user: process.env.CROWD_PACKAGES_DB_USERNAME,
7+
password: process.env.CROWD_PACKAGES_DB_PASSWORD,
8+
}
9+
}
10+
11+
export function getEnricherConfig() {
12+
const rawTokens = process.env.GITHUB_TOKENS ?? ''
13+
const tokens = rawTokens.split(',').map((t) => t.trim()).filter(Boolean)
14+
15+
return {
16+
tokens,
17+
pageSize: parseInt(process.env.PAGE_SIZE ?? '200', 10),
18+
batchSize: parseInt(process.env.BATCH_SIZE ?? '50', 10),
19+
maxRetries: parseInt(process.env.MAX_RETRIES ?? '3', 10),
20+
updateIntervalHours: parseInt(process.env.UPDATE_INTERVAL_HOURS ?? '24', 10),
21+
idleSleepSec: parseInt(process.env.IDLE_SLEEP_SEC ?? '60', 10),
22+
}
23+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { getDbConnection } from '@crowd/database'
2+
import { pgpQx } from '@crowd/data-access-layer/src/queryExecutor'
3+
4+
import { getPackagesDbConfig } from './config'
5+
6+
export async function getPackagesDb() {
7+
const conn = await getDbConnection(getPackagesDbConfig())
8+
return pgpQx(conn)
9+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Shared types for the packages-worker domain.
2+
// Individual entry points define their own internal types in their respective directories.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../base.tsconfig.json",
3+
"include": ["src/**/*"]
4+
}

0 commit comments

Comments
 (0)