From 83a0c237ca9b7a52317efc199b391af5aa57d30c Mon Sep 17 00:00:00 2001 From: dholms Date: Thu, 4 Jan 2024 19:02:43 -0600 Subject: [PATCH] make label provider optional --- packages/bsky/src/ingester/config.ts | 3 +-- packages/bsky/src/ingester/context.ts | 10 ++-------- packages/bsky/src/ingester/index.ts | 11 +++++------ packages/bsky/src/ingester/label-subscription.ts | 5 ++++- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/packages/bsky/src/ingester/config.ts b/packages/bsky/src/ingester/config.ts index 2e0fc1463c2..5c157571f2a 100644 --- a/packages/bsky/src/ingester/config.ts +++ b/packages/bsky/src/ingester/config.ts @@ -9,7 +9,7 @@ export interface IngesterConfigValues { redisSentinelHosts?: string[] redisPassword?: string repoProvider: string - labelProvider: string + labelProvider?: string ingesterPartitionCount: number ingesterNamespace?: string ingesterSubLockId?: number @@ -42,7 +42,6 @@ export class IngesterConfig { overrides?.redisPassword || process.env.REDIS_PASSWORD || undefined const repoProvider = overrides?.repoProvider || process.env.REPO_PROVIDER // E.g. ws://abc.com:4000 const labelProvider = overrides?.labelProvider || process.env.LABEL_PROVIDER - assert(labelProvider) const ingesterPartitionCount = overrides?.ingesterPartitionCount || maybeParseInt(process.env.INGESTER_PARTITION_COUNT) diff --git a/packages/bsky/src/ingester/context.ts b/packages/bsky/src/ingester/context.ts index 5decec92656..797545b9f98 100644 --- a/packages/bsky/src/ingester/context.ts +++ b/packages/bsky/src/ingester/context.ts @@ -1,4 +1,3 @@ -import AtpAgent from '@atproto/api' import { PrimaryDatabase } from '../db' import { Redis } from '../redis' import { IngesterConfig } from './config' @@ -10,8 +9,7 @@ export class IngesterContext { db: PrimaryDatabase redis: Redis cfg: IngesterConfig - labelAgent: AtpAgent - labelSubscription: LabelSubscription + labelSubscription?: LabelSubscription }, ) {} @@ -27,11 +25,7 @@ export class IngesterContext { return this.opts.cfg } - get labelAgent(): AtpAgent { - return this.opts.labelAgent - } - - get labelSubscription(): LabelSubscription { + get labelSubscription(): LabelSubscription | undefined { return this.opts.labelSubscription } } diff --git a/packages/bsky/src/ingester/index.ts b/packages/bsky/src/ingester/index.ts index e4e215dc8bc..b923b92c09c 100644 --- a/packages/bsky/src/ingester/index.ts +++ b/packages/bsky/src/ingester/index.ts @@ -5,7 +5,6 @@ import { Redis } from '../redis' import { IngesterConfig } from './config' import { IngesterContext } from './context' import { IngesterSubscription } from './subscription' -import AtpAgent from '@atproto/api' import { LabelSubscription } from './label-subscription' export { IngesterConfig } from './config' @@ -28,13 +27,13 @@ export class BskyIngester { cfg: IngesterConfig }): BskyIngester { const { db, redis, cfg } = opts - const labelAgent = new AtpAgent({ service: cfg.labelProvider }) - const labelSubscription = new LabelSubscription(db, labelAgent) + const labelSubscription = cfg.labelProvider + ? new LabelSubscription(db, cfg.labelProvider) + : undefined const ctx = new IngesterContext({ db, redis, cfg, - labelAgent, labelSubscription, }) const sub = new IngesterSubscription(ctx, { @@ -73,13 +72,13 @@ export class BskyIngester { 'ingester stats', ) }, 500) - await this.ctx.labelSubscription.start() + await this.ctx.labelSubscription?.start() this.sub.run() return this } async destroy(opts?: { skipDb: boolean }): Promise { - await this.ctx.labelSubscription.destroy() + await this.ctx.labelSubscription?.destroy() await this.sub.destroy() clearInterval(this.subStatsInterval) await this.ctx.redis.destroy() diff --git a/packages/bsky/src/ingester/label-subscription.ts b/packages/bsky/src/ingester/label-subscription.ts index 23155fc14cd..d486473cf98 100644 --- a/packages/bsky/src/ingester/label-subscription.ts +++ b/packages/bsky/src/ingester/label-subscription.ts @@ -9,8 +9,11 @@ export class LabelSubscription { promise: Promise = Promise.resolve() timer: NodeJS.Timer | undefined lastLabel: number | undefined + labelAgent: AtpAgent - constructor(public db: PrimaryDatabase, public labelAgent: AtpAgent) {} + constructor(public db: PrimaryDatabase, public labelProvider: string) { + this.labelAgent = new AtpAgent({ service: labelProvider }) + } async start() { const res = await this.db.db