forked from indymedia/epicyon
Adjustable timeout for dormant post threads
parent
ef72b93984
commit
886e4f2beb
14
daemon.py
14
daemon.py
|
@ -12980,12 +12980,13 @@ class EpicyonServer(ThreadingHTTPServer):
|
|||
return HTTPServer.handle_error(self, request, client_address)
|
||||
|
||||
|
||||
def runPostsQueue(baseDir: str, sendThreads: [], debug: bool) -> None:
|
||||
def runPostsQueue(baseDir: str, sendThreads: [], debug: bool,
|
||||
timeoutMins: int) -> None:
|
||||
"""Manages the threads used to send posts
|
||||
"""
|
||||
while True:
|
||||
time.sleep(1)
|
||||
removeDormantThreads(baseDir, sendThreads, debug)
|
||||
removeDormantThreads(baseDir, sendThreads, debug, timeoutMins)
|
||||
|
||||
|
||||
def runSharesExpire(versionNumber: str, baseDir: str) -> None:
|
||||
|
@ -13048,7 +13049,8 @@ def loadTokens(baseDir: str, tokensDict: {}, tokensLookup: {}) -> None:
|
|||
break
|
||||
|
||||
|
||||
def runDaemon(dormantMonths: int,
|
||||
def runDaemon(sendThreadsTimeoutMins: int,
|
||||
dormantMonths: int,
|
||||
maxNewswirePosts: int,
|
||||
allowLocalNetworkAccess: bool,
|
||||
maxFeedItemSizeKb: int,
|
||||
|
@ -13343,10 +13345,14 @@ def runDaemon(dormantMonths: int,
|
|||
httpd.maxPostsInBox), daemon=True)
|
||||
httpd.thrCache.start()
|
||||
|
||||
# number of mins after which sending posts or updates will expire
|
||||
httpd.sendThreadsTimeoutMins = sendThreadsTimeoutMins
|
||||
|
||||
print('Creating posts queue')
|
||||
httpd.thrPostsQueue = \
|
||||
threadWithTrace(target=runPostsQueue,
|
||||
args=(baseDir, httpd.sendThreads, debug), daemon=True)
|
||||
args=(baseDir, httpd.sendThreads, debug,
|
||||
httpd.sendThreadsTimeoutMins), daemon=True)
|
||||
if not unitTest:
|
||||
httpd.thrPostsWatchdog = \
|
||||
threadWithTrace(target=runPostsWatchdog,
|
||||
|
|
13
epicyon.py
13
epicyon.py
|
@ -122,6 +122,11 @@ parser.add_argument('--dormantMonths',
|
|||
default=3,
|
||||
help='How many months does a followed account need to ' +
|
||||
'be unseen for before being considered dormant')
|
||||
parser.add_argument('--sendThreadsTimeoutMins',
|
||||
dest='sendThreadsTimeoutMins', type=int,
|
||||
default=30,
|
||||
help='How many minutes before a thread to send out ' +
|
||||
'posts expires')
|
||||
parser.add_argument('--maxNewswirePosts',
|
||||
dest='maxNewswirePosts', type=int,
|
||||
default=20,
|
||||
|
@ -2035,6 +2040,11 @@ dormantMonths = \
|
|||
if dormantMonths is not None:
|
||||
args.dormantMonths = int(dormantMonths)
|
||||
|
||||
sendThreadsTimeoutMins = \
|
||||
getConfigParam(baseDir, 'sendThreadsTimeoutMins')
|
||||
if sendThreadsTimeoutMins is not None:
|
||||
args.sendThreadsTimeoutMins = int(sendThreadsTimeoutMins)
|
||||
|
||||
allowNewsFollowers = \
|
||||
getConfigParam(baseDir, 'allowNewsFollowers')
|
||||
if allowNewsFollowers is not None:
|
||||
|
@ -2083,7 +2093,8 @@ if setTheme(baseDir, themeName, domain, args.allowLocalNetworkAccess):
|
|||
print('Theme set to ' + themeName)
|
||||
|
||||
if __name__ == "__main__":
|
||||
runDaemon(args.dormantMonths,
|
||||
runDaemon(args.sendThreadsTimeoutMins,
|
||||
args.dormantMonths,
|
||||
args.maxNewswirePosts,
|
||||
args.allowLocalNetworkAccess,
|
||||
args.maxFeedItemSizeKb,
|
||||
|
|
12
tests.py
12
tests.py
|
@ -296,8 +296,10 @@ def createServerAlice(path: str, domain: str, port: int,
|
|||
allowLocalNetworkAccess = True
|
||||
maxNewswirePosts = 20
|
||||
dormantMonths = 3
|
||||
sendThreadsTimeoutMins = 30
|
||||
print('Server running: Alice')
|
||||
runDaemon(dormantMonths, maxNewswirePosts,
|
||||
runDaemon(sendThreadsTimeoutMins,
|
||||
dormantMonths, maxNewswirePosts,
|
||||
allowLocalNetworkAccess,
|
||||
2048, False, True, False, False, True, 10, False,
|
||||
0, 100, 1024, 5, False,
|
||||
|
@ -366,8 +368,10 @@ def createServerBob(path: str, domain: str, port: int,
|
|||
allowLocalNetworkAccess = True
|
||||
maxNewswirePosts = 20
|
||||
dormantMonths = 3
|
||||
sendThreadsTimeoutMins = 30
|
||||
print('Server running: Bob')
|
||||
runDaemon(dormantMonths, maxNewswirePosts,
|
||||
runDaemon(sendThreadsTimeoutMins,
|
||||
dormantMonths, maxNewswirePosts,
|
||||
allowLocalNetworkAccess,
|
||||
2048, False, True, False, False, True, 10, False,
|
||||
0, 100, 1024, 5, False, 0,
|
||||
|
@ -410,8 +414,10 @@ def createServerEve(path: str, domain: str, port: int, federationList: [],
|
|||
allowLocalNetworkAccess = True
|
||||
maxNewswirePosts = 20
|
||||
dormantMonths = 3
|
||||
sendThreadsTimeoutMins = 30
|
||||
print('Server running: Eve')
|
||||
runDaemon(dormantMonths, maxNewswirePosts,
|
||||
runDaemon(sendThreadsTimeoutMins,
|
||||
dormantMonths, maxNewswirePosts,
|
||||
allowLocalNetworkAccess,
|
||||
2048, False, True, False, False, True, 10, False,
|
||||
0, 100, 1024, 5, False, 0,
|
||||
|
|
|
@ -69,12 +69,14 @@ class threadWithTrace(threading.Thread):
|
|||
daemon=True)
|
||||
|
||||
|
||||
def removeDormantThreads(baseDir: str, threadsList: [], debug: bool) -> None:
|
||||
def removeDormantThreads(baseDir: str, threadsList: [], debug: bool,
|
||||
timeoutMins=30) -> None:
|
||||
"""Removes threads whose execution has completed
|
||||
"""
|
||||
if len(threadsList) == 0:
|
||||
return
|
||||
|
||||
timeoutSecs = int(timeoutMins * 60)
|
||||
dormantThreads = []
|
||||
currTime = datetime.datetime.utcnow()
|
||||
changed = False
|
||||
|
@ -92,13 +94,13 @@ def removeDormantThreads(baseDir: str, threadsList: [], debug: bool) -> None:
|
|||
'thread is not alive ten seconds after start')
|
||||
removeThread = True
|
||||
# timeout for started threads
|
||||
if (currTime - th.startTime).total_seconds() > 600:
|
||||
if (currTime - th.startTime).total_seconds() > timeoutSecs:
|
||||
if debug:
|
||||
print('DEBUG: started thread timed out')
|
||||
removeThread = True
|
||||
else:
|
||||
# timeout for threads which havn't been started
|
||||
if (currTime - th.startTime).total_seconds() > 600:
|
||||
if (currTime - th.startTime).total_seconds() > timeoutSecs:
|
||||
if debug:
|
||||
print('DEBUG: unstarted thread timed out')
|
||||
removeThread = True
|
||||
|
|
Loading…
Reference in New Issue