Skip to content
This repository has been archived by the owner on Nov 4, 2021. It is now read-only.

Commit

Permalink
Disable caching in shouldSendHooksTask (#177)
Browse files Browse the repository at this point in the history
* disable caching

* 0.9.14

* add guards
  • Loading branch information
mariusandra authored Feb 19, 2021
1 parent 2f0bc86 commit 96b411c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@posthog/plugin-server",
"version": "0.9.13",
"version": "0.9.14",
"description": "PostHog Plugin Server",
"types": "dist/index.d.ts",
"main": "dist/index.js",
Expand Down
58 changes: 19 additions & 39 deletions src/ingestion/process-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,48 +437,28 @@ export class EventsProcessor {
}

private async shouldSendHooksTask(team: Team): Promise<boolean> {
if (team.slack_incoming_webhook) {
return true
}
if (!this.pluginsServer.KAFKA_ENABLED) {
return false
}
const timeout = timeoutGuard(`Still running "shouldSendHooksTask". Timeout warning after 30 sec!`)
const hooksCacheKey = `@posthog/plugin-server/hooks/${team.id}`

const timeout2 = timeoutGuard(
`Still running "this.pluginsServer.redis.get(hooksCacheKey)". Timeout warning after 30 sec!`
)
const hooksCacheValue = await this.pluginsServer.redis.get(hooksCacheKey)
clearTimeout(timeout2)

let shouldSendHooksTask = false
if (hooksCacheValue) {
shouldSendHooksTask = hooksCacheValue === 'true'
} else {
if (team.slack_incoming_webhook) {
shouldSendHooksTask = true
} else if (this.pluginsServer.KAFKA_ENABLED) {
// Using KAFKA_ENABLED as a proxy for running enterprise edition
const timeout3 = timeoutGuard(`Still running "hook query". Timeout warning after 30 sec!`)
try {
const hookQueryResult = await this.db.postgresQuery(
`SELECT COUNT(*) FROM ee_hook WHERE team_id = $1 AND event = 'action_performed' LIMIT 1`,
[team.id]
)
shouldSendHooksTask = !!hookQueryResult.rows[0].count
} catch (error) {
status.info('🔔', error)
// In FOSS PostHog ee_hook does not exist. If the error is other than that, rethrow it
if (!String(error).includes('relation "ee_hook" does not exist')) {
throw error
}
} finally {
clearTimeout(timeout)
clearTimeout(timeout3)
}
try {
const hookQueryResult = await this.db.postgresQuery(
`SELECT COUNT(*) FROM ee_hook WHERE team_id = $1 AND event = 'action_performed' LIMIT 1`,
[team.id]
)
return !!hookQueryResult.rows[0].count
} catch (error) {
// In FOSS PostHog ee_hook does not exist. If the error is other than that, rethrow it
if (!String(error).includes('relation "ee_hook" does not exist')) {
throw error
}
const timeout4 = timeoutGuard(`Still running "redis set/expire". Timeout warning after 30 sec!`)
await this.pluginsServer.redis.set(hooksCacheKey, shouldSendHooksTask.toString())
await this.pluginsServer.redis.expire(hooksCacheKey, 10)
clearTimeout(timeout4)
} finally {
clearTimeout(timeout)
}
clearTimeout(timeout)
return shouldSendHooksTask
return false
}

private async createEvent(
Expand Down

0 comments on commit 96b411c

Please sign in to comment.