From a9d1927eb1f5426eec25598d587b3bacc4168d2c Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 5 Jun 2021 14:36:03 +0100 Subject: [PATCH 1/2] Broch mode lapse time is somewhat random --- inbox.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/inbox.py b/inbox.py index 05ba550e9..bd02b8021 100644 --- a/inbox.py +++ b/inbox.py @@ -10,6 +10,7 @@ import json import os import datetime import time +import random from linked_data_sig import verifyJsonSignature from utils import dmAllowedFromDomain from utils import isRecentPost @@ -2730,6 +2731,9 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, # within _bounceDM lastBounceMessage = [int(time.time())] + # how long it takes for broch mode to lapse + brochLapseDays = random.randrange(7, 14) + while True: time.sleep(1) @@ -2737,7 +2741,8 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, heartBeatCtr += 1 if heartBeatCtr >= 10: # turn off broch mode after it has timed out - brochModeLapses(baseDir) + if brochModeLapses(baseDir, brochLapseDays): + brochLapseDays = random.randrange(7, 14) print('>>> Heartbeat Q:' + str(len(queue)) + ' ' + '{:%F %T}'.format(datetime.datetime.now())) heartBeatCtr = 0 From dd8b9da31c765b09f2c82ada65d43c44016eda5c Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 5 Jun 2021 14:38:57 +0100 Subject: [PATCH 2/2] Only return true if broch mode lapses --- blocking.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/blocking.py b/blocking.py index 08f3f9eb3..b7f84e8a7 100644 --- a/blocking.py +++ b/blocking.py @@ -706,9 +706,9 @@ def brochModeLapses(baseDir: str, lapseDays=7) -> bool: modifiedDate = \ datetime.strptime(lastModified, "%Y-%m-%dT%H:%M:%SZ") except BaseException: - return brochMode + return False if not modifiedDate: - return brochMode + return False currTime = datetime.datetime.utcnow() daysSinceBroch = (currTime - modifiedDate).days if daysSinceBroch >= lapseDays: @@ -717,6 +717,7 @@ def brochModeLapses(baseDir: str, lapseDays=7) -> bool: brochMode = False setConfigParam(baseDir, "brochMode", brochMode) print('Broch mode has elapsed') + return True except BaseException: pass - return brochMode + return False