Formatted class_singleCleaner and simplified the code a bit more
This commit is contained in:
parent
6b1801b5e9
commit
6681fc4ae8
|
@ -25,11 +25,11 @@ import time
|
||||||
|
|
||||||
import queues
|
import queues
|
||||||
import state
|
import state
|
||||||
import tr
|
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
from helper_sql import sqlExecute, sqlQuery
|
from helper_sql import sqlExecute, sqlQuery
|
||||||
from inventory import Inventory
|
from inventory import Inventory
|
||||||
from network import BMConnectionPool, knownnodes, StoppableThread
|
from network import BMConnectionPool, knownnodes, StoppableThread
|
||||||
|
from tr import _translate
|
||||||
|
|
||||||
|
|
||||||
#: Equals 4 weeks. You could make this longer if you want
|
#: Equals 4 weeks. You could make this longer if you want
|
||||||
|
@ -63,11 +63,8 @@ class singleCleaner(StoppableThread):
|
||||||
# from the config file.
|
# from the config file.
|
||||||
state.maximumLengthOfTimeToBotherResendingMessages = float('inf')
|
state.maximumLengthOfTimeToBotherResendingMessages = float('inf')
|
||||||
|
|
||||||
# initial wait
|
|
||||||
if state.shutdown == 0:
|
|
||||||
self.stop.wait(singleCleaner.cycleLength)
|
|
||||||
|
|
||||||
while state.shutdown == 0:
|
while state.shutdown == 0:
|
||||||
|
self.stop.wait(self.cycleLength)
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateStatusBar',
|
'updateStatusBar',
|
||||||
'Doing housekeeping (Flushing inventory in memory to disk...)'
|
'Doing housekeeping (Flushing inventory in memory to disk...)'
|
||||||
|
@ -81,15 +78,16 @@ class singleCleaner(StoppableThread):
|
||||||
# FIXME redundant?
|
# FIXME redundant?
|
||||||
if state.thisapp.daemon or not state.enableGUI:
|
if state.thisapp.daemon or not state.enableGUI:
|
||||||
queues.UISignalQueue.queue.clear()
|
queues.UISignalQueue.queue.clear()
|
||||||
if timeWeLastClearedInventoryAndPubkeysTables < \
|
|
||||||
int(time.time()) - 7380:
|
tick = int(time.time())
|
||||||
timeWeLastClearedInventoryAndPubkeysTables = int(time.time())
|
if timeWeLastClearedInventoryAndPubkeysTables < tick - 7380:
|
||||||
|
timeWeLastClearedInventoryAndPubkeysTables = tick
|
||||||
Inventory().clean()
|
Inventory().clean()
|
||||||
queues.workerQueue.put(('sendOnionPeerObj', ''))
|
queues.workerQueue.put(('sendOnionPeerObj', ''))
|
||||||
# pubkeys
|
# pubkeys
|
||||||
sqlExecute(
|
sqlExecute(
|
||||||
"DELETE FROM pubkeys WHERE time<? AND usedpersonally='no'",
|
"DELETE FROM pubkeys WHERE time<? AND usedpersonally='no'",
|
||||||
int(time.time()) - lengthOfTimeToHoldOnToAllPubkeys)
|
tick - lengthOfTimeToHoldOnToAllPubkeys)
|
||||||
|
|
||||||
# Let us resend getpubkey objects if we have not yet heard
|
# Let us resend getpubkey objects if we have not yet heard
|
||||||
# a pubkey, and also msg objects if we have not yet heard
|
# a pubkey, and also msg objects if we have not yet heard
|
||||||
|
@ -98,19 +96,10 @@ class singleCleaner(StoppableThread):
|
||||||
"SELECT toaddress, ackdata, status FROM sent"
|
"SELECT toaddress, ackdata, status FROM sent"
|
||||||
" WHERE ((status='awaitingpubkey' OR status='msgsent')"
|
" WHERE ((status='awaitingpubkey' OR status='msgsent')"
|
||||||
" AND folder='sent' AND sleeptill<? AND senttime>?)",
|
" AND folder='sent' AND sleeptill<? AND senttime>?)",
|
||||||
int(time.time()), int(time.time())
|
tick,
|
||||||
- state.maximumLengthOfTimeToBotherResendingMessages
|
tick - state.maximumLengthOfTimeToBotherResendingMessages
|
||||||
)
|
)
|
||||||
for row in queryreturn:
|
for toAddress, ackData, status in queryreturn:
|
||||||
if len(row) < 2:
|
|
||||||
self.logger.error(
|
|
||||||
'Something went wrong in the singleCleaner thread:'
|
|
||||||
' a query did not return the requested fields. %r',
|
|
||||||
row
|
|
||||||
)
|
|
||||||
self.stop.wait(3)
|
|
||||||
break
|
|
||||||
toAddress, ackData, status = row
|
|
||||||
if status == 'awaitingpubkey':
|
if status == 'awaitingpubkey':
|
||||||
self.resendPubkeyRequest(toAddress)
|
self.resendPubkeyRequest(toAddress)
|
||||||
elif status == 'msgsent':
|
elif status == 'msgsent':
|
||||||
|
@ -121,7 +110,6 @@ class singleCleaner(StoppableThread):
|
||||||
# while writing it to disk
|
# while writing it to disk
|
||||||
knownnodes.cleanupKnownNodes()
|
knownnodes.cleanupKnownNodes()
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
# pylint: disable=protected-access
|
|
||||||
if "Errno 28" in str(err):
|
if "Errno 28" in str(err):
|
||||||
self.logger.fatal(
|
self.logger.fatal(
|
||||||
'(while writing knownnodes to disk)'
|
'(while writing knownnodes to disk)'
|
||||||
|
@ -129,8 +117,8 @@ class singleCleaner(StoppableThread):
|
||||||
)
|
)
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'alert',
|
'alert',
|
||||||
(tr._translate("MainWindow", "Disk full"),
|
(_translate("MainWindow", "Disk full"),
|
||||||
tr._translate(
|
_translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
'Alert: Your disk or data storage volume'
|
'Alert: Your disk or data storage volume'
|
||||||
' is full. Bitmessage will now exit.'),
|
' is full. Bitmessage will now exit.'),
|
||||||
|
@ -138,7 +126,7 @@ class singleCleaner(StoppableThread):
|
||||||
))
|
))
|
||||||
# FIXME redundant?
|
# FIXME redundant?
|
||||||
if state.thisapp.daemon or not state.enableGUI:
|
if state.thisapp.daemon or not state.enableGUI:
|
||||||
os._exit(1)
|
os._exit(1) # pylint: disable=protected-access
|
||||||
|
|
||||||
# inv/object tracking
|
# inv/object tracking
|
||||||
for connection in BMConnectionPool().connections():
|
for connection in BMConnectionPool().connections():
|
||||||
|
@ -156,9 +144,6 @@ class singleCleaner(StoppableThread):
|
||||||
|
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
if state.shutdown == 0:
|
|
||||||
self.stop.wait(singleCleaner.cycleLength)
|
|
||||||
|
|
||||||
def resendPubkeyRequest(self, address):
|
def resendPubkeyRequest(self, address):
|
||||||
"""Resend pubkey request for address"""
|
"""Resend pubkey request for address"""
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
|
@ -179,8 +164,8 @@ class singleCleaner(StoppableThread):
|
||||||
'Doing work necessary to again attempt to request a public key...'
|
'Doing work necessary to again attempt to request a public key...'
|
||||||
))
|
))
|
||||||
sqlExecute(
|
sqlExecute(
|
||||||
'''UPDATE sent SET status='msgqueued' WHERE toaddress=? AND folder='sent' ''',
|
"UPDATE sent SET status = 'msgqueued'"
|
||||||
address)
|
" WHERE toaddress = ? AND folder = 'sent'", address)
|
||||||
queues.workerQueue.put(('sendmessage', ''))
|
queues.workerQueue.put(('sendmessage', ''))
|
||||||
|
|
||||||
def resendMsg(self, ackdata):
|
def resendMsg(self, ackdata):
|
||||||
|
@ -190,8 +175,8 @@ class singleCleaner(StoppableThread):
|
||||||
' to our msg. Sending again.'
|
' to our msg. Sending again.'
|
||||||
)
|
)
|
||||||
sqlExecute(
|
sqlExecute(
|
||||||
'''UPDATE sent SET status='msgqueued' WHERE ackdata=? AND folder='sent' ''',
|
"UPDATE sent SET status = 'msgqueued'"
|
||||||
ackdata)
|
" WHERE ackdata = ? AND folder = 'sent'", ackdata)
|
||||||
queues.workerQueue.put(('sendmessage', ''))
|
queues.workerQueue.put(('sendmessage', ''))
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
'updateStatusBar',
|
'updateStatusBar',
|
||||||
|
|
Reference in New Issue
Block a user