-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(api): /api/clean better logging #280
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Reviewer's Guide by SourceryThis pull request enhances the logging in the /api/clean route. It adds logs at various stages of the cleanup process, including the start of the cleanup, when there is nothing to clean up, and when the 'LastCleanup' event is created. Additionally, it improves error logging by providing more context. File-Level Changes
Tips
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @duyet - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 5 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
@@ -67,6 +67,8 @@ async function cleanupHangQuery( | |||
throw new Error( | |||
`Last cleanup was ${lastCleanup} less than ${QUERY_CLEANUP_MAX_DURATION_SECONDS}s` | |||
) | |||
} else { | |||
console.log('[/api/clean] Starting clean up hang queries') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider using a logging library instead of console.log
Using a logging library can provide more control over log levels and output formats, and can be configured to write to different destinations (e.g., files, external logging services).
@@ -97,6 +99,7 @@ async function cleanupHangQuery( | |||
|
|||
// Nothing to cleanup | |||
if (!killQueryResp || killQueryResp?.rows === 0) { | |||
console.log('[/api/clean] Done, nothing to cleanup') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider using a logging library instead of console.log
Using a logging library can provide more control over log levels and output formats, and can be configured to write to different destinations (e.g., files, external logging services).
return { lastCleanup, message: 'Nothing to cleanup' } | ||
} else { | ||
console.error(error) | ||
console.error('[/api/clean] Error when killing queries:', error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider using a logging library instead of console.error
Using a logging library can provide more control over log levels and output formats, and can be configured to write to different destinations (e.g., files, external logging services).
console.error('[/api/clean] Error when killing queries:', error) | |
import { Logger } from 'some-logging-library'; | |
const logger = new Logger(); | |
... | |
logger.error('[/api/clean] Error when killing queries:', error); |
@@ -126,7 +130,9 @@ async function cleanupHangQuery( | |||
], | |||
format: 'JSONEachRow', | |||
}) | |||
console.log('[/api/clean] LastCleanup event created') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider using a logging library instead of console.log
Using a logging library can provide more control over log levels and output formats, and can be configured to write to different destinations (e.g., files, external logging services).
} catch (error) { | ||
console.error("[/api/clean] 'LastCleanup' event creating error:", error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider using a logging library instead of console.error
Using a logging library can provide more control over log levels and output formats, and can be configured to write to different destinations (e.g., files, external logging services).
Summary by Sourcery
This pull request enhances the /api/clean endpoint by adding detailed logging messages to improve traceability and debugging of the cleanup process.