manual sync by default: sync now button, auto-sync toggle
This commit is contained in:
parent
4b98779122
commit
b79689aba0
2 changed files with 62 additions and 3 deletions
|
|
@ -55,13 +55,41 @@ class ForumSync:
|
|||
if self.fdb.get_setting("forum_auto_discover", "1") == "1":
|
||||
self._enable_announce_handler()
|
||||
self._running = True
|
||||
self._thread = threading.Thread(target=self._sync_loop, daemon=True)
|
||||
self._thread.start()
|
||||
if self.fdb.get_setting("forum_auto_sync", "0") == "1":
|
||||
self._start_sync_loop()
|
||||
|
||||
def stop(self):
|
||||
self._running = False
|
||||
self._disable_announce_handler()
|
||||
|
||||
def set_auto_sync(self, enabled):
|
||||
self.fdb.set_setting("forum_auto_sync", "1" if enabled else "0")
|
||||
if enabled:
|
||||
self._start_sync_loop()
|
||||
else:
|
||||
pass # current cycle finishes, no new one starts
|
||||
|
||||
def sync_now(self):
|
||||
"""Run one sync cycle immediately. Returns count of peers synced."""
|
||||
instances = self.fdb.get_synced_instances()
|
||||
random.shuffle(instances)
|
||||
count = 0
|
||||
for inst in instances[:GOSSIP_FANOUT]:
|
||||
if not self._running:
|
||||
break
|
||||
try:
|
||||
self._sync_with(inst["instance_hash"])
|
||||
count += 1
|
||||
except Exception as e:
|
||||
print(f"[forum] sync error with {inst['instance_hash'][:16]}: {e}")
|
||||
return count
|
||||
|
||||
def _start_sync_loop(self):
|
||||
if self._thread and self._thread.is_alive():
|
||||
return
|
||||
self._thread = threading.Thread(target=self._sync_loop, daemon=True)
|
||||
self._thread.start()
|
||||
|
||||
def set_auto_discover(self, enabled):
|
||||
self.fdb.set_setting("forum_auto_discover", "1" if enabled else "0")
|
||||
if enabled:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue