5 from dirtrigger import DirTrigger
6 from migrator import Migrator
10 def __init__(self, idx, trigger, migrator, cleanup):
12 self.trigger = trigger
13 self.migrator = migrator
14 self.cleanup = cleanup
16 def __init__(self, idx, cfg):
20 for src_dir_cfg in cfg['src_dirs']:
22 Bunch.TriggeredSource(
24 DirTrigger(src_dir_cfg['path'], src_dir_cfg['cool_time'],
25 src_dir_cfg['max_time']),
26 Migrator(src_dir_cfg['path'], cfg['dst_dir']['path']),
27 src_dir_cfg['cleanup']
31 logging.info("Created bunch #%d with %d sources.", self._idx, len(self._sources))
34 logging.info("Starting bunch #%d...", self._idx)
36 self._worker_thread = threading.Thread(target=self._worker)
37 self._worker_thread.start()
40 logging.info("Stopping bunch #%d...", self._idx)
42 self._worker_thread.join()
43 logging.info("Stopped bunch #%d.", self._idx)
46 return self._worker_thread.is_alive()
49 for src in self._sources:
53 for src in self._sources:
55 if src.trigger.is_triggering():
56 logging.info("Got trigger for source #%d.%d.", self._idx, src.idx)
59 src.migrator.migrate(src.cleanup)
61 src.migrator.cleanup()
62 logging.info("Migration took %.1fs for source #%d.%d.",
63 time.time() - before, self._idx, src.idx)
64 except Exception as e:
65 logging.error("Error migrating source #%d.%d: %s",
66 self._idx, src.idx, str(e))
69 for src in self._sources: