Archive daily

master
Bob Mottram 2019-08-20 12:51:29 +01:00
parent 8703f86c05
commit 8551e1e3a7
3 changed files with 21 additions and 10 deletions

View File

@ -66,14 +66,6 @@ def expirePersonCache(personCache: {}):
del personCache[personUrl] del personCache[personUrl]
print(str(len(removals))+' actors were expired from the cache') print(str(len(removals))+' actors were expired from the cache')
def expireCache(baseDir: str,personCache: {}):
"""Cache expiry thread
"""
while True:
# once per day
time.sleep(60*60*24)
expirePersonCache(basedir,personCache)
def storeWebfingerInCache(handle: str,wf,cachedWebfingers: {}) -> None: def storeWebfingerInCache(handle: str,wf,cachedWebfingers: {}) -> None:
"""Store a webfinger endpoint in the cache """Store a webfinger endpoint in the cache
""" """

View File

@ -43,6 +43,7 @@ from posts import createFollowersOnlyPost
from posts import createDirectMessagePost from posts import createDirectMessagePost
from posts import populateRepliesJson from posts import populateRepliesJson
from posts import addToField from posts import addToField
from posts import expireCache
from inbox import inboxPermittedMessage from inbox import inboxPermittedMessage
from inbox import inboxMessageHasParams from inbox import inboxMessageHasParams
from inbox import runInboxQueue from inbox import runInboxQueue
@ -109,7 +110,6 @@ from announce import createAnnounce
from announce import outboxAnnounce from announce import outboxAnnounce
from content import addHtmlTags from content import addHtmlTags
from media import removeMetaData from media import removeMetaData
from cache import expireCache
import os import os
import sys import sys
@ -2892,6 +2892,7 @@ def runDaemon(projectVersion, \
# max POST size of 10M # max POST size of 10M
httpd.projectVersion=projectVersion httpd.projectVersion=projectVersion
httpd.maxPostLength=1024*1024*10 httpd.maxPostLength=1024*1024*10
httpd.maxPostsInBox=256
httpd.domain=domain httpd.domain=domain
httpd.port=port httpd.port=port
httpd.domainFull=domain httpd.domainFull=domain
@ -2949,10 +2950,18 @@ def runDaemon(projectVersion, \
print('Creating actors cache') print('Creating actors cache')
os.mkdir(baseDir+'/cache/actors') os.mkdir(baseDir+'/cache/actors')
archiveDir=baseDir+'/archive'
if not os.path.isdir(archiveDir):
print('Creating archive')
os.mkdir(archiveDir)
print('Creating cache expiry thread') print('Creating cache expiry thread')
httpd.thrCache= \ httpd.thrCache= \
threadWithTrace(target=expireCache, \ threadWithTrace(target=expireCache, \
args=(baseDir,httpd.personCache),daemon=True) args=(baseDir,httpd.personCache, \
httpd.httpPrefix, \
archiveDir, \
httpdmaxPostsInBox),daemon=True)
httpd.thrCache.start() httpd.thrCache.start()
print('Creating inbox queue') print('Creating inbox queue')

View File

@ -21,6 +21,7 @@ from collections import OrderedDict
from threads import threadWithTrace from threads import threadWithTrace
from cache import storePersonInCache from cache import storePersonInCache
from cache import getPersonFromCache from cache import getPersonFromCache
from cache import expirePersonCache
from pprint import pprint from pprint import pprint
from random import randint from random import randint
from session import createSession from session import createSession
@ -1706,6 +1707,15 @@ def createBoxBase(baseDir: str,boxname: str, \
return boxHeader return boxHeader
return boxItems return boxItems
def expireCache(baseDir: str,personCache: {},httpPrefix: str,archiveDir: str,maxPostsInBox=256):
"""Thread used to expire actors from the cache and archive old posts
"""
while True:
# once per day
time.sleep(60*60*24)
expirePersonCache(basedir,personCache)
archivePosts(baseDir,httpPrefix,archiveDir,maxPostsInBox)
def archivePosts(baseDir: str,httpPrefix: str,archiveDir: str,maxPostsInBox=256) -> None: def archivePosts(baseDir: str,httpPrefix: str,archiveDir: str,maxPostsInBox=256) -> None:
"""Archives posts for all accounts """Archives posts for all accounts
""" """