arg_parser.add_argument('-s', '--sleeptime', type=int, default=10, help='time to sleep before checking for new files') arg_parser.add_argument('-f', '--logfile', help='path to log file') arg_parser.add_argument('-l', '--loglevel', default='info', help='log level (default: info)') arg_parser.add_argument('-q', '--quiet', action='store_true', default=False, help='disable console logging') args = arg_parser.parse_args() nimsutil.configure_log(args.logfile, not args.quiet, args.loglevel) nimsgears.model.init_model(sqlalchemy.create_engine(args.db_uri)) sorter = Sorter(args.stage_path, args.preserve_path, args.nims_path, args.sleeptime) def term_handler(signum, stack): sorter.halt() log.info('Receieved SIGTERM - shutting down...') signal.signal(signal.SIGTERM, term_handler) sorter.run() log.warning('Process halted')
def __init__(self): super(ArgumentParser, self).__init__() self.add_argument('reap_path', help='path to reaping stage') self.add_argument('sort_path', help='path to sorting stage') self.add_argument('data_path', help='path to data source') self.add_argument('-p', '--patid', help='glob for patient IDs to reap (default: "*")') self.add_argument('-d', '--discard', default='discard', help='space-separated list of Patient IDs to discard') self.add_argument('-s', '--sleeptime', type=int, default=30, help='time to sleep before checking for new data') self.add_argument('-f', '--logfile', help='path to log file') self.add_argument('-l', '--loglevel', default='info', help='log level (default: info)') self.add_argument('-q', '--quiet', action='store_true', default=False, help='disable console logging') if __name__ == '__main__': args = ArgumentParser().parse_args() reaper_id = args.data_path.strip('/').replace('/', '_') nimsutil.configure_log(args.logfile, not args.quiet, args.loglevel) datetime_file = os.path.join(os.path.dirname(__file__), '.%s.datetime' % reaper_id) reaper = PFileReaper(reaper_id, args.patid, args.discard.split(), args.data_path, args.reap_path, args.sort_path, datetime_file, args.sleeptime) def term_handler(signum, stack): reaper.halt() log.info('Received SIGTERM - shutting down...') signal.signal(signal.SIGTERM, term_handler) reaper.run() log.warning('Process halted')