@avalw/search-worker 2.3.2 → 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 +21 -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)
|
|
@@ -529,6 +530,9 @@ class SearchWorker {
|
|
|
529
530
|
this.isConnected = true;
|
|
530
531
|
this.reconnectAttempts = 0;
|
|
531
532
|
|
|
533
|
+
// Authenticate with token
|
|
534
|
+
this._send({ type: 'auth', token: this.workerToken });
|
|
535
|
+
|
|
532
536
|
// Register cached keys
|
|
533
537
|
this._sendCacheRegistry();
|
|
534
538
|
|
|
@@ -552,7 +556,11 @@ class SearchWorker {
|
|
|
552
556
|
this.isConnected = false;
|
|
553
557
|
this._stopHeartbeat();
|
|
554
558
|
this.onDisconnected(this);
|
|
555
|
-
|
|
559
|
+
|
|
560
|
+
// Only reconnect if flag is true (not manually disconnected)
|
|
561
|
+
if (this.shouldReconnect) {
|
|
562
|
+
this._scheduleReconnect();
|
|
563
|
+
}
|
|
556
564
|
});
|
|
557
565
|
|
|
558
566
|
this.ws.on('error', (error) => {
|
|
@@ -561,7 +569,9 @@ class SearchWorker {
|
|
|
561
569
|
|
|
562
570
|
} catch (e) {
|
|
563
571
|
this.onError(`Connection failed: ${e.message}`);
|
|
564
|
-
this.
|
|
572
|
+
if (this.shouldReconnect) {
|
|
573
|
+
this._scheduleReconnect();
|
|
574
|
+
}
|
|
565
575
|
}
|
|
566
576
|
}
|
|
567
577
|
|
|
@@ -790,6 +800,11 @@ class SearchWorker {
|
|
|
790
800
|
|
|
791
801
|
// Schedule reconnection
|
|
792
802
|
_scheduleReconnect() {
|
|
803
|
+
// Check if reconnect is disabled (manual disconnect)
|
|
804
|
+
if (!this.shouldReconnect) {
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
|
|
793
808
|
if (this.reconnectTimeout) {
|
|
794
809
|
clearTimeout(this.reconnectTimeout);
|
|
795
810
|
}
|
|
@@ -811,6 +826,9 @@ class SearchWorker {
|
|
|
811
826
|
|
|
812
827
|
// Disconnect from coordinator
|
|
813
828
|
disconnect() {
|
|
829
|
+
// Disable auto-reconnect FIRST
|
|
830
|
+
this.shouldReconnect = false;
|
|
831
|
+
|
|
814
832
|
this._stopHeartbeat();
|
|
815
833
|
|
|
816
834
|
// Stop cache cleanup process
|