local: Re-add progress helper and log flushes.
Refactored the progress helper to be used in batching flushes in addition to logging.
This commit is contained in:
parent
63a8375429
commit
e880cb56b5
@ -110,12 +110,12 @@ class ScanCommand(commands.Command):
|
|||||||
logger.info('Found %d unknown tracks.', len(uris_to_update))
|
logger.info('Found %d unknown tracks.', len(uris_to_update))
|
||||||
logger.info('Scanning...')
|
logger.info('Scanning...')
|
||||||
|
|
||||||
scanner = scan.Scanner(scan_timeout)
|
uris_to_update = sorted(uris_to_update)[:args.limit]
|
||||||
count = 0
|
|
||||||
total = args.limit or len(uris_to_update)
|
|
||||||
start = time.time()
|
|
||||||
|
|
||||||
for uri in sorted(uris_to_update)[:args.limit]:
|
scanner = scan.Scanner(scan_timeout)
|
||||||
|
progress = _Progress(flush_threshold, len(uris_to_update))
|
||||||
|
|
||||||
|
for uri in uris_to_update:
|
||||||
try:
|
try:
|
||||||
data = scanner.scan(path.path_to_uri(uri_path_mapping[uri]))
|
data = scanner.scan(path.path_to_uri(uri_path_mapping[uri]))
|
||||||
track = scan.audio_data_to_track(data).copy(uri=uri)
|
track = scan.audio_data_to_track(data).copy(uri=uri)
|
||||||
@ -124,16 +124,30 @@ class ScanCommand(commands.Command):
|
|||||||
except exceptions.ScannerError as error:
|
except exceptions.ScannerError as error:
|
||||||
logger.warning('Failed %s: %s', uri, error)
|
logger.warning('Failed %s: %s', uri, error)
|
||||||
|
|
||||||
count += 1
|
if progress.increment():
|
||||||
if count % flush_threshold == 0 or count == total:
|
progress.log()
|
||||||
duration = time.time() - start
|
if library.flush():
|
||||||
remainder = duration / count * (total - count)
|
logger.debug('Progress flushed.')
|
||||||
logger.info('Scanned %d of %d files in %ds, ~%ds left.',
|
|
||||||
count, total, duration, remainder)
|
|
||||||
# TODO: log if flush succeeded
|
|
||||||
# TODO: don't flush when count == total
|
|
||||||
library.flush()
|
|
||||||
|
|
||||||
|
progress.log()
|
||||||
library.close()
|
library.close()
|
||||||
logger.info('Done scanning.')
|
logger.info('Done scanning.')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
class _Progress(object):
|
||||||
|
def __init__(self, batch_size, total):
|
||||||
|
self.count = 0
|
||||||
|
self.batch_size = batch_size
|
||||||
|
self.total = total
|
||||||
|
self.start = time.time()
|
||||||
|
|
||||||
|
def increment(self):
|
||||||
|
self.count += 1
|
||||||
|
return self.count % self.batch_size == 0
|
||||||
|
|
||||||
|
def log(self):
|
||||||
|
duration = time.time() - self.start
|
||||||
|
remainder = duration / self.count * (self.total - self.count)
|
||||||
|
logger.info('Scanned %d of %d files in %ds, ~%ds left.',
|
||||||
|
self.count, self.total, duration, remainder)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user