mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-11-13 10:26:01 +00:00
fixed code quality
This commit is contained in:
@@ -49,12 +49,12 @@ function init(server, prismaClient) {
|
||||
// Accept the WebSocket connection for Bull Board
|
||||
wss.handleUpgrade(request, socket, head, (ws) => {
|
||||
ws.on("message", (message) => {
|
||||
// Echo back for Bull Board WebSocket
|
||||
try {
|
||||
ws.send(message);
|
||||
} catch (err) {
|
||||
// Ignore send errors (connection may be closed)
|
||||
}
|
||||
// Echo back for Bull Board WebSocket
|
||||
try {
|
||||
ws.send(message);
|
||||
} catch (_err) {
|
||||
// Ignore send errors (connection may be closed)
|
||||
}
|
||||
});
|
||||
|
||||
ws.on("error", (err) => {
|
||||
@@ -160,9 +160,7 @@ function init(server, prismaClient) {
|
||||
err.message?.includes("read ECONNRESET")
|
||||
) {
|
||||
// Connection reset errors are common and expected
|
||||
console.log(
|
||||
`[agent-ws] connection reset for ${apiId}`,
|
||||
);
|
||||
console.log(`[agent-ws] connection reset for ${apiId}`);
|
||||
} else {
|
||||
// Log other errors for debugging
|
||||
console.error(
|
||||
@@ -181,7 +179,10 @@ function init(server, prismaClient) {
|
||||
}
|
||||
|
||||
// Try to close the connection gracefully if still open
|
||||
if (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING) {
|
||||
if (
|
||||
ws.readyState === WebSocket.OPEN ||
|
||||
ws.readyState === WebSocket.CONNECTING
|
||||
) {
|
||||
try {
|
||||
ws.close(1000); // Normal closure
|
||||
} catch {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Timezone utility functions for consistent timestamp handling
|
||||
*
|
||||
*
|
||||
* This module provides timezone-aware timestamp functions that use
|
||||
* the TZ environment variable for consistent timezone handling across
|
||||
* the application. If TZ is not set, defaults to UTC.
|
||||
@@ -22,32 +22,16 @@ function get_timezone() {
|
||||
*/
|
||||
function get_current_time() {
|
||||
const tz = get_timezone();
|
||||
|
||||
|
||||
// If UTC, use Date.now() which is always UTC
|
||||
if (tz === "UTC" || tz === "Etc/UTC") {
|
||||
return new Date();
|
||||
}
|
||||
|
||||
|
||||
// For other timezones, we need to create a date string with timezone info
|
||||
// and parse it. This ensures the date represents the correct time in that timezone.
|
||||
const now = new Date();
|
||||
const formatter = new Intl.DateTimeFormat("en-US", {
|
||||
timeZone: tz,
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
hour12: false,
|
||||
});
|
||||
|
||||
const parts = formatter.formatToParts(now);
|
||||
const date_str = `${parts.find((p) => p.type === "year").value}-${parts.find((p) => p.type === "month").value}-${parts.find((p) => p.type === "day").value}T${parts.find((p) => p.type === "hour").value}:${parts.find((p) => p.type === "minute").value}:${parts.find((p) => p.type === "second").value}`;
|
||||
|
||||
// Create date in UTC, then adjust to represent the same moment in the target timezone
|
||||
// This is a bit tricky - we'll use a simpler approach: store as UTC but display in timezone
|
||||
// For database storage, we always store UTC timestamps
|
||||
// The timezone is primarily used for display purposes
|
||||
return new Date();
|
||||
}
|
||||
|
||||
@@ -88,7 +72,7 @@ function parse_date(date_string, fallback = null) {
|
||||
return fallback || get_current_time();
|
||||
}
|
||||
return date;
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
return fallback || get_current_time();
|
||||
}
|
||||
}
|
||||
@@ -121,4 +105,3 @@ module.exports = {
|
||||
parse_date,
|
||||
format_date_for_display,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user