mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
Add SSE heartbeat to prevent Cloudflare 524 timeout
This commit is contained in:
1 parent
ffa7e413d4
commit
b56f1fdf7e
3 files changed
+17
No files matched your search
@@ -3,6 +3,9 @@ import { stream } from 'hono/streaming'
|
|||||||
import { sseAggregator } from '../services/sse-aggregator'
|
import { sseAggregator } from '../services/sse-aggregator'
|
||||||
import { SSESubscribeSchema } from '@opencode-manager/shared/schemas'
|
import { SSESubscribeSchema } from '@opencode-manager/shared/schemas'
|
||||||
import { logger } from '../utils/logger'
|
import { logger } from '../utils/logger'
|
||||||
|
import { DEFAULTS } from '@opencode-manager/shared/config'
|
||||||
|
|
||||||
|
const { HEARTBEAT_INTERVAL_MS } = DEFAULTS.SSE
|
||||||
|
|
||||||
export function createSSERoutes() {
|
export function createSSERoutes() {
|
||||||
const app = new Hono()
|
const app = new Hono()
|
||||||
@@ -36,7 +39,16 @@ export function createSSERoutes() {
|
|||||||
directories
|
directories
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const heartbeatInterval = setInterval(() => {
|
||||||
|
try {
|
||||||
|
writeSSE('heartbeat', JSON.stringify({ timestamp: Date.now() }))
|
||||||
|
} catch {
|
||||||
|
clearInterval(heartbeatInterval)
|
||||||
|
}
|
||||||
|
}, HEARTBEAT_INTERVAL_MS)
|
||||||
|
|
||||||
writer.onAbort(() => {
|
writer.onAbort(() => {
|
||||||
|
clearInterval(heartbeatInterval)
|
||||||
cleanup()
|
cleanup()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -207,6 +207,10 @@ class SSEManager {
|
|||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.eventSource.addEventListener('heartbeat', () => {
|
||||||
|
// Heartbeat received - connection is alive
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private disconnect(): void {
|
private disconnect(): void {
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ export const DEFAULTS = {
|
|||||||
RECONNECT_DELAY_MS: 1000,
|
RECONNECT_DELAY_MS: 1000,
|
||||||
MAX_RECONNECT_DELAY_MS: 30000,
|
MAX_RECONNECT_DELAY_MS: 30000,
|
||||||
IDLE_GRACE_PERIOD_MS: 5000,
|
IDLE_GRACE_PERIOD_MS: 5000,
|
||||||
|
HEARTBEAT_INTERVAL_MS: 60000,
|
||||||
},
|
},
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user