Просмотр исходного кода

Add some jitter to the sync loop

Will Hunt 3 лет назад
Родитель
Сommit
0c1424a759
1 измененных файлов с 4 добавлено и 0 удалено
  1. 4 0
      mautrix_signal/__main__.py

+ 4 - 0
mautrix_signal/__main__.py

@@ -14,6 +14,7 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 from typing import Dict, Any
+from random import uniform
 import asyncio
 import logging
 
@@ -33,6 +34,7 @@ from .puppet import Puppet
 from .web import ProvisioningAPI
 from . import commands
 
+SYNC_JITTER=10
 
 class SignalBridge(Bridge):
     module = "mautrix_signal"
@@ -92,6 +94,8 @@ class SignalBridge(Bridge):
                 return
             log.info("Executing periodic syncs")
             for user in User.by_username.values():
+                # Add some randomness to the sync to avoid a thundering herd
+                await asyncio.sleep(uniform(-SYNC_JITTER, SYNC_JITTER))
                 try:
                     await user.sync()
                 except asyncio.CancelledError: