Commit 174d0868 authored by Gerion Entrup's avatar Gerion Entrup
Browse files

collector: add ability to not run as a thread

parent 77a7e6a1
......@@ -26,26 +26,35 @@ class Collector(threading.Thread):
Collects Tags and write them to the database.
def __init__(self, session_fac):
self._session = session_fac()
self.log = logging.getLogger('collector')
def __init__(self, session_fac, threaded=True):
if threaded:
self._session = session_fac()
self._logger = logging.getLogger('collector')
def get_unthreaded_instance(cls, session, logger):
instance = cls(None, threaded=False)
instance._session = session
instance._logger = logger
def run(self):
while True:
action, data = Paths.get()
if action == NEW:"Adding file {} to the database.".format(data.path))"Adding file {} to the database.".format(data.path))
self.fetch_recording(data.mbid, data.path)
elif action == DEFECT:"Repair broken entry with mbid {}".format(data))"Repair broken entry with mbid {}".format(data))
elif action == UPDATE:"Update outdated entry with mbid {}".format(data))"Update outdated entry with mbid {}".format(data))
self.log.error("Unknow action: {}".format(action))
self._logger.error("Unknow action: {}".format(action))
......@@ -150,7 +159,7 @@ class Collector(threading.Thread):
except musicbrainzngs.WebServiceError as exc:
self.log.error("Could not connect to Musicbrainz. Path: {} Request: {}".format(path, exc))
self._logger.error("Could not connect to Musicbrainz. Path: {} Request: {}".format(path, exc))
recording = None
return recording
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment