This repository has been archived by the owner on Nov 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build healthcheck into index.js (#455)
* Build healthcheck into index.js * Add "Alternative modes" to README * Fix uncaught reject in Sentry flush
- Loading branch information
Showing
6 changed files
with
55 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
import { defaultConfig } from './config/config' | ||
import { Status } from './utils/status' | ||
import { status } from './utils/status' | ||
import { createRedis } from './utils/utils' | ||
|
||
const healthStatus = new Status('HLTH') | ||
|
||
void createRedis(defaultConfig).then(async (redis) => { | ||
const ping = await redis.get('@posthog-plugin-server/ping') | ||
if (ping) { | ||
healthStatus.info('💚', `Redis key @posthog-plugin-server/ping found with value ${ping}`) | ||
process.exit(0) | ||
} else { | ||
healthStatus.error('💔', 'Redis key @posthog-plugin-server/ping not found! Plugin server seems to be offline') | ||
process.exit(1) | ||
export async function healthcheck(): Promise<boolean> { | ||
const redis = await createRedis(defaultConfig) | ||
try { | ||
const ping = await redis.get('@posthog-plugin-server/ping') | ||
if (ping) { | ||
status.info('💚', `Redis key @posthog-plugin-server/ping found with value ${ping}`) | ||
return true | ||
} else { | ||
status.error('💔', 'Redis key @posthog-plugin-server/ping not found! Plugin server seems to be offline') | ||
return false | ||
} | ||
} catch (error) { | ||
status.error('💥', 'An unexpected error occurred:', error) | ||
return false | ||
} finally { | ||
redis.disconnect() | ||
} | ||
}) | ||
} | ||
|
||
export async function healthcheckWithExit(): Promise<never> { | ||
process.exit((await healthcheck()) ? 0 : 1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters