Skip to content

Commit

Permalink
make label provider optional
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Jan 5, 2024
1 parent 58ab837 commit 83a0c23
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
3 changes: 1 addition & 2 deletions packages/bsky/src/ingester/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface IngesterConfigValues {
redisSentinelHosts?: string[]
redisPassword?: string
repoProvider: string
labelProvider: string
labelProvider?: string
ingesterPartitionCount: number
ingesterNamespace?: string
ingesterSubLockId?: number
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 2 additions & 8 deletions packages/bsky/src/ingester/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AtpAgent from '@atproto/api'
import { PrimaryDatabase } from '../db'
import { Redis } from '../redis'
import { IngesterConfig } from './config'
Expand All @@ -10,8 +9,7 @@ export class IngesterContext {
db: PrimaryDatabase
redis: Redis
cfg: IngesterConfig
labelAgent: AtpAgent
labelSubscription: LabelSubscription
labelSubscription?: LabelSubscription
},
) {}

Expand All @@ -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
}
}
Expand Down
11 changes: 5 additions & 6 deletions packages/bsky/src/ingester/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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, {
Expand Down Expand Up @@ -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<void> {
await this.ctx.labelSubscription.destroy()
await this.ctx.labelSubscription?.destroy()
await this.sub.destroy()
clearInterval(this.subStatsInterval)
await this.ctx.redis.destroy()
Expand Down
5 changes: 4 additions & 1 deletion packages/bsky/src/ingester/label-subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ export class LabelSubscription {
promise: Promise<void> = 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
Expand Down

0 comments on commit 83a0c23

Please sign in to comment.