@newhomestar/sdk 0.7.6 → 0.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/events.d.ts +1 -1
- package/dist/events.js +27 -5
- package/package.json +1 -1
package/dist/events.d.ts
CHANGED
|
@@ -305,7 +305,7 @@ export declare function withInboundEvent(db: any, msg: InboundMessage, handler:
|
|
|
305
305
|
*
|
|
306
306
|
* ## Connection lifecycle
|
|
307
307
|
*
|
|
308
|
-
* - Opens `GET /events/queue/stream?
|
|
308
|
+
* - Opens `GET /events/queue/stream?queue={queueName}` (SSE)
|
|
309
309
|
* - On message: routes → withInboundEvent() → ACK (or NACK on failure)
|
|
310
310
|
* - On keepalive (`: keepalive`): no action needed
|
|
311
311
|
* - On close/error: reconnects with exponential backoff (1s → 2s → 4s → ... → max)
|
package/dist/events.js
CHANGED
|
@@ -610,7 +610,7 @@ export async function withInboundEvent(db, msg, handler) {
|
|
|
610
610
|
*
|
|
611
611
|
* ## Connection lifecycle
|
|
612
612
|
*
|
|
613
|
-
* - Opens `GET /events/queue/stream?
|
|
613
|
+
* - Opens `GET /events/queue/stream?queue={queueName}` (SSE)
|
|
614
614
|
* - On message: routes → withInboundEvent() → ACK (or NACK on failure)
|
|
615
615
|
* - On keepalive (`: keepalive`): no action needed
|
|
616
616
|
* - On close/error: reconnects with exponential backoff (1s → 2s → 4s → ... → max)
|
|
@@ -777,7 +777,7 @@ export function startInboundConsumer(db, options) {
|
|
|
777
777
|
/** Main loop: connect, consume, reconnect */
|
|
778
778
|
async function _connect() {
|
|
779
779
|
while (!abort.signal.aborted) {
|
|
780
|
-
const streamUrl = `${eventsUrl}/events/queue/stream?
|
|
780
|
+
const streamUrl = `${eventsUrl}/events/queue/stream?queue=${encodeURIComponent(queueName)}&vt=${vt}`;
|
|
781
781
|
try {
|
|
782
782
|
console.log(`[nova/events] Connecting to SSE queue "${queueName}" ` +
|
|
783
783
|
`(attempt ${reconnectAttempt + 1})…`);
|
|
@@ -792,12 +792,33 @@ export function startInboundConsumer(db, options) {
|
|
|
792
792
|
// Successfully connected — reset reconnect counter
|
|
793
793
|
reconnectAttempt = 0;
|
|
794
794
|
console.log(`[nova/events] SSE consumer connected to queue "${queueName}"`);
|
|
795
|
-
|
|
795
|
+
// Consume the stream; catch stream-level errors separately from
|
|
796
|
+
// connection-level errors so they don't trigger exponential backoff.
|
|
797
|
+
// A stream dying mid-flight (e.g. proxy timeout) is a normal lifecycle
|
|
798
|
+
// event — reconnect immediately with a short fixed delay.
|
|
799
|
+
try {
|
|
800
|
+
await _consumeStream(response);
|
|
801
|
+
}
|
|
802
|
+
catch (streamErr) {
|
|
803
|
+
if (abort.signal.aborted)
|
|
804
|
+
return;
|
|
805
|
+
const isAbortError = streamErr?.name === 'AbortError' || streamErr?.code === 20;
|
|
806
|
+
if (isAbortError)
|
|
807
|
+
return;
|
|
808
|
+
console.error(`[nova/events] SSE stream error for queue "${queueName}":`, String(streamErr).slice(0, 300));
|
|
809
|
+
}
|
|
796
810
|
if (abort.signal.aborted) {
|
|
797
811
|
console.log(`[nova/events] SSE consumer for queue "${queueName}" shut down gracefully`);
|
|
798
812
|
return;
|
|
799
813
|
}
|
|
800
|
-
|
|
814
|
+
// Stream ended (normal close OR proxy timeout). The connection WAS
|
|
815
|
+
// established, so no exponential backoff — reconnect in a fixed 1s.
|
|
816
|
+
console.log(`[nova/events] SSE stream for queue "${queueName}" closed — reconnecting in 1000ms…`);
|
|
817
|
+
await new Promise((resolve) => {
|
|
818
|
+
const t = setTimeout(resolve, 1_000);
|
|
819
|
+
abort.signal.addEventListener('abort', () => { clearTimeout(t); resolve(); }, { once: true });
|
|
820
|
+
});
|
|
821
|
+
continue; // skip exponential backoff below
|
|
801
822
|
}
|
|
802
823
|
catch (err) {
|
|
803
824
|
if (abort.signal.aborted) {
|
|
@@ -809,7 +830,8 @@ export function startInboundConsumer(db, options) {
|
|
|
809
830
|
return;
|
|
810
831
|
console.error(`[nova/events] SSE connection error for queue "${queueName}":`, String(err).slice(0, 300));
|
|
811
832
|
}
|
|
812
|
-
// Exponential backoff
|
|
833
|
+
// Exponential backoff only for connection-level failures (fetch threw or
|
|
834
|
+
// server returned non-200). Stream-level drops use the fixed 1s above.
|
|
813
835
|
const delayMs = Math.min(1_000 * Math.pow(2, reconnectAttempt), maxReconnectDelay);
|
|
814
836
|
reconnectAttempt++;
|
|
815
837
|
console.log(`[nova/events] Reconnecting queue "${queueName}" in ${delayMs}ms…`);
|
package/package.json
CHANGED