scanner: Add a CheckSchedulerTask
This task breaks a library's tracks into chunks and schedules a CheckTask for each chunk. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
8946df3ce4
commit
19278af3b8
|
@ -76,3 +76,19 @@ class CheckTask(Task):
|
|||
need_commit = True
|
||||
if need_commit:
|
||||
db.commit()
|
||||
|
||||
|
||||
class CheckSchedulerTask(Task):
|
||||
def __init__(self, library):
|
||||
Task.__init__(self)
|
||||
self.library = library
|
||||
|
||||
def track_chunks(self):
|
||||
tracks = self.library.tracks()
|
||||
while len(tracks) > 0:
|
||||
res = tracks[:50]
|
||||
tracks = tracks[50:]
|
||||
yield res
|
||||
|
||||
def run_task(self):
|
||||
return [ CheckTask(tracks) for tracks in self.track_chunks() ]
|
||||
|
|
|
@ -130,3 +130,33 @@ class TestScannerCheckTask(unittest.TestCase):
|
|||
self.assertIsNone(db.track.Table.get(2))
|
||||
self.assertIsNone(db.track.Table.get(3))
|
||||
self.assertEqual(db.track.Table.get(4), track)
|
||||
|
||||
|
||||
class TestScannerCheckSchedulerTask(unittest.TestCase):
|
||||
def setUp(self):
|
||||
db.reset()
|
||||
|
||||
def test_scanner_check_scheduler_task(self):
|
||||
lib = db.library.Table.find(test_tracks)
|
||||
track = db.make_fake_track(1, 1, "Test Album Track", str(test_track01), str(test_tracks))
|
||||
|
||||
lib2 = db.library.Table.find("/a/b/c")
|
||||
for i in range(75):
|
||||
db.make_fake_track(i, i, f"Test Track {i}",f"/a/b/c/{i}.ogg", lib="/a/b/c")
|
||||
|
||||
cst = task.CheckSchedulerTask(lib2)
|
||||
self.assertIsInstance(cst, task.Task)
|
||||
self.assertEqual(cst.library, lib2)
|
||||
|
||||
tasks = cst.run_task()
|
||||
self.assertEqual(len(tasks), 2)
|
||||
self.assertIsInstance(tasks[0], task.CheckTask)
|
||||
self.assertIsInstance(tasks[1], task.CheckTask)
|
||||
self.assertEqual(len(tasks[0].tracks), 50)
|
||||
self.assertEqual(len(tasks[1].tracks), 25)
|
||||
tasks[0].run_task()
|
||||
tasks[1].run_task()
|
||||
|
||||
self.assertEqual(db.track.Table.get(1), track)
|
||||
for i in range(1, 76):
|
||||
self.assertIsNone(db.track.Table.get(1+i))
|
||||
|
|
Loading…
Reference in New Issue