0
0
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:
Yakko Majuri 2022-02-17 13:39:17 +00:00 committed by GitHub
parent c7bdd31673
commit 60586bcf16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -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()

View File

@ -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')
}
}
}