Clear inbox queue when full

main
Bob Mottram 2020-05-22 11:48:13 +00:00
parent b749b37187
commit 83345a6d84
2 changed files with 23 additions and 4 deletions

View File

@ -64,6 +64,7 @@ from posts import createDirectMessagePost
from posts import populateRepliesJson
from posts import addToField
from posts import expireCache
from inbox import clearQueueItems
from inbox import inboxPermittedMessage
from inbox import inboxMessageHasParams
from inbox import runInboxQueue
@ -820,9 +821,10 @@ class PubServer(BaseHTTPRequestHandler):
else:
print('Queue: Inbox queue is full')
self._503()
self.server.POSTbusy = False
clearQueueItems(self.server.baseDir, self.server.inboxQueue)
if not self.server.restartInboxQueueInProgress:
self.server.restartInboxQueue = True
self.server.POSTbusy = False
return 2
# Convert the headers needed for signature verification to dict

View File

@ -2212,6 +2212,26 @@ def inboxAfterCapabilities(recentPostsCache: {}, maxRecentPosts: int,
return True
def clearQueueItems(baseDir: str, queue: []) -> None:
"""Clears the queue for each account and appends filenames
"""
ctr = 0
queue.clear()
for subdir, dirs, files in os.walk(baseDir + '/accounts'):
for account in dirs:
queueDir = baseDir + '/accounts/' + account + '/queue'
if os.path.isdir(queueDir):
for queuesubdir, queuedirs, queuefiles in os.walk(queueDir):
for qfile in queuefiles:
try:
os.remove(os.path.join(queueDir, qfile))
ctr += 1
except BaseException:
pass
if ctr > 0:
print('Removed ' + str(ctr) + ' inbox queue items')
def restoreQueueItems(baseDir: str, queue: []) -> None:
"""Checks the queue for each account and appends filenames
"""
@ -2220,11 +2240,8 @@ def restoreQueueItems(baseDir: str, queue: []) -> None:
for account in dirs:
queueDir = baseDir + '/accounts/' + account + '/queue'
if os.path.isdir(queueDir):
print('Searching inbox queue ' + queueDir)
for queuesubdir, queuedirs, queuefiles in os.walk(queueDir):
for qfile in queuefiles:
print('Adding inbox queue file ' +
os.path.join(queueDir, qfile))
queue.append(os.path.join(queueDir, qfile))
if len(queue) > 0:
print('Restored ' + str(len(queue)) + ' inbox queue items')