mirror of
https://github.com/PostHog/posthog.git
synced 2024-12-01 04:12:23 +01:00
track when the promise manager awaits a promise (#8672)
This commit is contained in:
parent
c7bdd31673
commit
60586bcf16
@ -191,7 +191,7 @@ export async function createHub(
|
||||
const organizationManager = new OrganizationManager(db)
|
||||
const pluginsApiKeyManager = new PluginsApiKeyManager(db)
|
||||
const rootAccessManager = new RootAccessManager(db)
|
||||
const promiseManager = new PromiseManager(serverConfig)
|
||||
const promiseManager = new PromiseManager(serverConfig, statsd)
|
||||
const actionManager = new ActionManager(db)
|
||||
await actionManager.prepare()
|
||||
|
||||
|
@ -1,12 +1,16 @@
|
||||
import { StatsD } from 'hot-shots'
|
||||
|
||||
import { PluginsServerConfig } from '../../types'
|
||||
|
||||
export class PromiseManager {
|
||||
pendingPromises: Set<Promise<any>>
|
||||
config: PluginsServerConfig
|
||||
statsd?: StatsD
|
||||
|
||||
constructor(config: PluginsServerConfig) {
|
||||
constructor(config: PluginsServerConfig, statsd?: StatsD) {
|
||||
this.pendingPromises = new Set()
|
||||
this.config = config
|
||||
this.statsd = statsd
|
||||
}
|
||||
|
||||
public trackPromise(promise: Promise<any>): void {
|
||||
@ -24,6 +28,7 @@ export class PromiseManager {
|
||||
public async awaitPromisesIfNeeded(): Promise<void> {
|
||||
while (this.pendingPromises.size > this.config.MAX_PENDING_PROMISES_PER_WORKER) {
|
||||
await Promise.race(this.pendingPromises)
|
||||
this.statsd?.increment('worker_promise_manager_promises_awaited')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user