-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fe2 status check endpoint w/ proper redis cleanup (#2092)
- Loading branch information
Showing
13 changed files
with
212 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Redis } from 'ioredis' | ||
import type pino from 'pino' | ||
|
||
export const createRedis = async (params: { logger: pino.Logger }) => { | ||
const { logger } = params | ||
const { redisUrl } = useRuntimeConfig() | ||
if (!redisUrl?.length) { | ||
return undefined | ||
} | ||
|
||
const redis = new Redis(redisUrl) | ||
|
||
redis.on('error', (err) => { | ||
logger.error(err, 'Redis error') | ||
}) | ||
|
||
redis.on('end', () => { | ||
logger.info('Redis disconnected from server') | ||
}) | ||
|
||
// Try to ping the server | ||
const res = await redis.ping() | ||
if (res !== 'PONG') { | ||
throw new Error('Redis server did not respond to ping') | ||
} | ||
|
||
return redis | ||
} |
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
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,6 +1,28 @@ | ||
import { useRequestId } from '~/lib/core/composables/server' | ||
import { ensureError } from '@speckle/shared' | ||
import { createRedis } from '~/lib/core/helpers/redis' | ||
|
||
export default defineEventHandler((event) => { | ||
const reqId = useRequestId({ event }) | ||
return { status: 'ok', reqId } | ||
/** | ||
* Check that the deployment is fine | ||
*/ | ||
|
||
export default defineEventHandler(async () => { | ||
let redisConnected = false | ||
|
||
// Check that redis works | ||
try { | ||
const redis = await createRedis({ logger: useLogger() }) | ||
redisConnected = !!redis | ||
if (redis) { | ||
await redis.quit() | ||
} | ||
} catch (e) { | ||
const errMsg = ensureError(e).message | ||
throw createError({ | ||
statusCode: 500, | ||
fatal: true, | ||
message: `Redis connection failed: ${errMsg}` | ||
}) | ||
} | ||
|
||
return { status: 'ok', redisConnected } | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../.nuxt/tsconfig.server.json", | ||
"compilerOptions": { | ||
"verbatimModuleSyntax": true | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { Optional } from '@speckle/shared' | ||
import type pino from 'pino' | ||
import { buildLogger } from '~/server/lib/core/helpers/observability' | ||
|
||
let logger: Optional<pino.Logger> = undefined | ||
|
||
const createLogger = () => { | ||
const { | ||
public: { logLevel, logPretty, speckleServerVersion, serverName } | ||
} = useRuntimeConfig() | ||
|
||
const logger = buildLogger(logLevel, logPretty).child({ | ||
browser: false, | ||
speckleServerVersion, | ||
serverName, | ||
frontendType: 'frontend-2', | ||
serverLogger: true | ||
}) | ||
|
||
return logger | ||
} | ||
|
||
export const useLogger = () => { | ||
if (!logger) { | ||
logger = createLogger() | ||
} | ||
|
||
return logger | ||
} |
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
Oops, something went wrong.