move looping call to check announcement status to SQLiteStorage

This commit is contained in:
Jack Robison 2018-08-02 14:32:08 -04:00
parent a3de065c93
commit 314400a1bd
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 11 additions and 12 deletions

View file

@ -1,8 +1,7 @@
import logging import logging
import os import os
from sqlite3 import IntegrityError from sqlite3 import IntegrityError
from twisted.internet import threads, defer, task from twisted.internet import threads, defer
from lbrynet import conf
from lbrynet.blob.blob_file import BlobFile from lbrynet.blob.blob_file import BlobFile
from lbrynet.blob.creator import BlobFileCreator from lbrynet.blob.creator import BlobFileCreator
@ -26,23 +25,14 @@ class DiskBlobManager(object):
self.blobs = {} self.blobs = {}
self.blob_hashes_to_delete = {} # {blob_hash: being_deleted (True/False)} self.blob_hashes_to_delete = {} # {blob_hash: being_deleted (True/False)}
self.check_should_announce_lc = None
# TODO: move this looping call to SQLiteStorage
if 'reflector' not in conf.settings['components_to_skip']:
self.check_should_announce_lc = task.LoopingCall(self.storage.verify_will_announce_all_head_and_sd_blobs)
@defer.inlineCallbacks @defer.inlineCallbacks
def setup(self): def setup(self):
if self.check_should_announce_lc and not self.check_should_announce_lc.running:
self.check_should_announce_lc.start(600)
if self._node_datastore is not None: if self._node_datastore is not None:
raw_blob_hashes = yield self.storage.get_all_finished_blobs() raw_blob_hashes = yield self.storage.get_all_finished_blobs()
self._node_datastore.completed_blobs.update(raw_blob_hashes) self._node_datastore.completed_blobs.update(raw_blob_hashes)
defer.returnValue(True) defer.returnValue(True)
def stop(self): def stop(self):
if self.check_should_announce_lc and self.check_should_announce_lc.running:
self.check_should_announce_lc.stop()
return defer.succeed(True) return defer.succeed(True)
def get_blob(self, blob_hash, length=None): def get_blob(self, blob_hash, length=None):

View file

@ -181,10 +181,17 @@ class SQLiteStorage(object):
# when it loads each file # when it loads each file
self.content_claim_callbacks = {} # {<stream_hash>: <callable returning a deferred>} self.content_claim_callbacks = {} # {<stream_hash>: <callable returning a deferred>}
if 'reflector' not in conf.settings['components_to_skip']:
self.check_should_announce_lc = task.LoopingCall(self.verify_will_announce_all_head_and_sd_blobs)
@defer.inlineCallbacks
def setup(self): def setup(self):
def _create_tables(transaction): def _create_tables(transaction):
transaction.executescript(self.CREATE_TABLES_QUERY) transaction.executescript(self.CREATE_TABLES_QUERY)
return self.db.runInteraction(_create_tables) yield self.db.runInteraction(_create_tables)
if self.check_should_announce_lc and not self.check_should_announce_lc.running:
self.check_should_announce_lc.start(600)
defer.returnValue(None)
@defer.inlineCallbacks @defer.inlineCallbacks
def run_and_return_one_or_none(self, query, *args): def run_and_return_one_or_none(self, query, *args):
@ -203,6 +210,8 @@ class SQLiteStorage(object):
defer.returnValue([]) defer.returnValue([])
def stop(self): def stop(self):
if self.check_should_announce_lc and self.check_should_announce_lc.running:
self.check_should_announce_lc.stop()
self.db.close() self.db.close()
return defer.succeed(True) return defer.succeed(True)