forked from indymedia/epicyon
Log post results
parent
11046d2165
commit
4b28e67a0d
28
posts.py
28
posts.py
|
@ -27,7 +27,10 @@ except ImportError:
|
||||||
|
|
||||||
# Contains threads for posts being sent
|
# Contains threads for posts being sent
|
||||||
sendThreads = []
|
sendThreads = []
|
||||||
|
|
||||||
|
# stores the results from recent post sending attempts
|
||||||
|
postLog = []
|
||||||
|
|
||||||
def permitted(url: str,federationList) -> bool:
|
def permitted(url: str,federationList) -> bool:
|
||||||
"""Is a url from one of the permitted domains?
|
"""Is a url from one of the permitted domains?
|
||||||
"""
|
"""
|
||||||
|
@ -299,10 +302,25 @@ def createPublicPost(username: str, domain: str, https: bool, content: str, foll
|
||||||
return createPostBase(username, domain, 'https://www.w3.org/ns/activitystreams#Public', prefix+'://'+domain+'/users/'+username+'/followers', https, content, followersOnly, saveToFile, inReplyTo, inReplyToAtomUri, subject)
|
return createPostBase(username, domain, 'https://www.w3.org/ns/activitystreams#Public', prefix+'://'+domain+'/users/'+username+'/followers', https, content, followersOnly, saveToFile, inReplyTo, inReplyToAtomUri, subject)
|
||||||
|
|
||||||
def threadSendPost(session,postJsonObject,federationList,inboxUrl: str,signatureHeader) -> None:
|
def threadSendPost(session,postJsonObject,federationList,inboxUrl: str,signatureHeader) -> None:
|
||||||
|
"""Sends a post with exponential backoff
|
||||||
|
"""
|
||||||
tries=0
|
tries=0
|
||||||
backoffTime=600
|
backoffTime=60
|
||||||
for attempt in range(12):
|
for attempt in range(20):
|
||||||
if postJson(session,postJsonObject,federationList,inboxUrl,signatureHeader):
|
postResult = postJson(session,postJsonObject,federationList,inboxUrl,signatureHeader):
|
||||||
|
if postResult:
|
||||||
|
postLog.append(postJsonObject['published']+' '+postResult+'\n')
|
||||||
|
# keep the length of the log finite
|
||||||
|
# Don't accumulate massive files on systems with limited resources
|
||||||
|
while len(postLog)>64:
|
||||||
|
postlog.pop(0)
|
||||||
|
# save the log file
|
||||||
|
baseDir=os.getcwd()
|
||||||
|
filename=baseDir+'/post.log'
|
||||||
|
with open(filename, "w") as logFile:
|
||||||
|
for line in postLog:
|
||||||
|
print(line, file=logFile)
|
||||||
|
# our work here is done
|
||||||
break
|
break
|
||||||
time.sleep(backoffTime)
|
time.sleep(backoffTime)
|
||||||
backoffTime *= 2
|
backoffTime *= 2
|
||||||
|
@ -342,7 +360,7 @@ def sendPost(session,username: str, domain: str, toUsername: str, toDomain: str,
|
||||||
if len(sendThreads)>10:
|
if len(sendThreads)>10:
|
||||||
thr=sendThreads[0]
|
thr=sendThreads[0]
|
||||||
thr.stop()
|
thr.stop()
|
||||||
sendThreads.remove(thr)
|
sendThreads.pop(0)
|
||||||
thr = threading.Thread(target=threadSendPost,args=(session,postJsonObject,federationList,inboxUrl,signatureHeader),daemon=True)
|
thr = threading.Thread(target=threadSendPost,args=(session,postJsonObject,federationList,inboxUrl,signatureHeader),daemon=True)
|
||||||
sendThreads.append(thr)
|
sendThreads.append(thr)
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
Loading…
Reference in New Issue