@avalw/search-worker 2.3.3 → 2.3.4
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/index.js +18 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @avalw/search-worker v2.3.
|
|
2
|
+
* @avalw/search-worker v2.3.4
|
|
3
3
|
* Distributed Cache Worker for AVALW Search Network
|
|
4
4
|
*
|
|
5
5
|
* Workers connect to the coordinator via WebSocket and serve as
|
|
@@ -425,6 +425,7 @@ class SearchWorker {
|
|
|
425
425
|
this.reconnectTimeout = null;
|
|
426
426
|
this.reconnectAttempts = 0;
|
|
427
427
|
this.maxReconnectAttempts = 10;
|
|
428
|
+
this.shouldReconnect = true; // Flag to control auto-reconnect
|
|
428
429
|
|
|
429
430
|
// Smart cache configuration
|
|
430
431
|
// Size: 500MB - 2GB (default 500MB)
|
|
@@ -555,7 +556,11 @@ class SearchWorker {
|
|
|
555
556
|
this.isConnected = false;
|
|
556
557
|
this._stopHeartbeat();
|
|
557
558
|
this.onDisconnected(this);
|
|
558
|
-
|
|
559
|
+
|
|
560
|
+
// Only reconnect if flag is true (not manually disconnected)
|
|
561
|
+
if (this.shouldReconnect) {
|
|
562
|
+
this._scheduleReconnect();
|
|
563
|
+
}
|
|
559
564
|
});
|
|
560
565
|
|
|
561
566
|
this.ws.on('error', (error) => {
|
|
@@ -564,7 +569,9 @@ class SearchWorker {
|
|
|
564
569
|
|
|
565
570
|
} catch (e) {
|
|
566
571
|
this.onError(`Connection failed: ${e.message}`);
|
|
567
|
-
this.
|
|
572
|
+
if (this.shouldReconnect) {
|
|
573
|
+
this._scheduleReconnect();
|
|
574
|
+
}
|
|
568
575
|
}
|
|
569
576
|
}
|
|
570
577
|
|
|
@@ -793,6 +800,11 @@ class SearchWorker {
|
|
|
793
800
|
|
|
794
801
|
// Schedule reconnection
|
|
795
802
|
_scheduleReconnect() {
|
|
803
|
+
// Check if reconnect is disabled (manual disconnect)
|
|
804
|
+
if (!this.shouldReconnect) {
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
|
|
796
808
|
if (this.reconnectTimeout) {
|
|
797
809
|
clearTimeout(this.reconnectTimeout);
|
|
798
810
|
}
|
|
@@ -814,6 +826,9 @@ class SearchWorker {
|
|
|
814
826
|
|
|
815
827
|
// Disconnect from coordinator
|
|
816
828
|
disconnect() {
|
|
829
|
+
// Disable auto-reconnect FIRST
|
|
830
|
+
this.shouldReconnect = false;
|
|
831
|
+
|
|
817
832
|
this._stopHeartbeat();
|
|
818
833
|
|
|
819
834
|
// Stop cache cleanup process
|