Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Jun 20, 2024
1 parent 75a0f08 commit 03f9a4c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
16 changes: 4 additions & 12 deletions plugin-server/src/cdp/hog-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ export class HogWatcherObserver {
state,
})

// TODO: Somehow report this back to PostHog so we can display it in the UI

return state
}

Expand Down Expand Up @@ -225,22 +227,12 @@ export class HogWatcher {
})
}

getOverflowedHogFunctionIds(): HogFunctionType['id'][] {
// TODO
return []
}

isHogFunctionOverflowed(hogFunctionId: HogFunctionType['id']): boolean {
return this.getOverflowedHogFunctionIds().includes(hogFunctionId)
}

getDisabledHogFunctionIds(): HogFunctionType['id'][] {
// TODO
return []
return this.getObserver(hogFunctionId).currentState() === HogWatcherState.overflowed
}

isHogFunctionDisabled(hogFunctionId: HogFunctionType['id']): boolean {
return this.getDisabledHogFunctionIds().includes(hogFunctionId)
return this.getObserver(hogFunctionId).currentState() >= HogWatcherState.disabledForPeriod
}

private getObserver(id: HogFunctionType['id']): HogWatcherObserver {
Expand Down
32 changes: 19 additions & 13 deletions plugin-server/tests/cdp/hog-function-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ describe('HogFunctionManager', () => {
})

it('returns the hog functions', async () => {
let functionsMap = manager.getTeamHogFunctions(teamId1)
let items = manager.getTeamHogFunctions(teamId1)

expect(functionsMap).toEqual({
[hogFunctions[0].id]: {
expect(items).toEqual([
{
id: hogFunctions[0].id,
team_id: teamId1,
name: 'Test Hog Function team 1',
Expand All @@ -59,7 +59,7 @@ describe('HogFunctionManager', () => {
bytecode: null,
filters: null,
},
})
])

await hub.db.postgres.query(
PostgresUse.COMMON_WRITE,
Expand All @@ -71,18 +71,24 @@ describe('HogFunctionManager', () => {
// This is normally dispatched by django
await manager.reloadHogFunctions(teamId1, [hogFunctions[0].id])

functionsMap = manager.getTeamHogFunctions(teamId1)
items = manager.getTeamHogFunctions(teamId1)

expect(functionsMap[hogFunctions[0].id]).toMatchObject({
id: hogFunctions[0].id,
name: 'Test Hog Function team 1 updated',
})
expect(items).toMatchObject([
{
id: hogFunctions[0].id,
name: 'Test Hog Function team 1 updated',
},
])
})

it('removes disabled functions', async () => {
let functionsMap = manager.getTeamHogFunctions(teamId1)
let items = manager.getTeamHogFunctions(teamId1)

expect(functionsMap).toHaveProperty(hogFunctions[0].id)
expect(items).toMatchObject([
{
id: hogFunctions[0].id,
},
])

await hub.db.postgres.query(
PostgresUse.COMMON_WRITE,
Expand All @@ -94,8 +100,8 @@ describe('HogFunctionManager', () => {
// This is normally dispatched by django
await manager.reloadHogFunctions(teamId1, [hogFunctions[0].id])

functionsMap = manager.getTeamHogFunctions(teamId1)
items = manager.getTeamHogFunctions(teamId1)

expect(functionsMap).not.toHaveProperty(hogFunctions[0].id)
expect(items).toEqual([])
})
})

0 comments on commit 03f9a4c

Please sign in to comment.