def run_turbolift(): """This is the run section of the application Turbolift.""" if len(sys.argv) <= 1: arguments.get_help() raise SystemExit('Give me something to do and I will do it') else: args = arguments.get_args() log = logger.LogSetup( debug_logging=args.get('debug', False), log_dir=args.get('log_location', '/var/log'), log_name=args.get('log_file') ).default_logger(enable_stream=args.get('log_streaming')) log.debug('set arguments [ %s ]', json.dumps(args, indent=2)) import turbolift.utils.basic_utils as basic args = basic.dict_pop_none(dictionary=args) load_constants(args=args) try: from turbolift import worker worker.start_work() except KeyboardInterrupt: turbo.emergency_kill(reclaim=True) finally: if args.get('quiet') is not True: print('All Done!') log.info('Job Finished.')
def operation(retry, conn=None, obj=None, cleanup=None): """This is an operation wrapper, which wraps an operation in try except. If clean up is used, a clean up operation will be run should an exception happen. :param retry: :param conn: :param obj: :param cleanup: :return: """ try: yield retry except turbo.NoSource as exp: report.reporter( msg=('No Source. Message: %s\nADDITIONAL DATA: %s\nTB: %s' % (traceback.format_exc(), exp, obj)), lvl='error' ) retry() except turbo.SystemProblem as exp: report.reporter( msg='System Problems Found %s\nADDITIONAL DATA: %s' % (exp, obj), lvl='error' ) retry() except KeyboardInterrupt: if cleanup is not None: cleanup() turbo.emergency_kill(reclaim=True) except IOError as exp: report.reporter( msg=('IO ERROR: %s. ADDITIONAL DATA: %s' '\nMESSAGE %s will retry.' '\nSTACKTRACE: %s' % (exp, obj, info.__appname__, traceback.format_exc())), lvl='error' ) retry() except Exception: report.reporter( msg=('Failed Operation. ADDITIONAL DATA: %s\n%s will retry\nTB: %s' % (obj, info.__appname__, traceback.format_exc())), lvl='error' ) retry() finally: if cleanup is not None: cleanup() if conn is not None: conn.close()
def operation(retry, conn=None, obj=None, cleanup=None): """This is an operation wrapper, which wraps an operation in try except. If clean up is used, a clean up operation will be run should an exception happen. :param retry: :param conn: :param obj: :param cleanup: :return: """ try: yield retry except turbo.NoSource as exp: report.reporter( msg=('No Source. Message: %s\nADDITIONAL DATA: %s\nTB: %s' % (traceback.format_exc(), exp, obj)), lvl='error') retry() except turbo.SystemProblem as exp: report.reporter(msg='System Problems Found %s\nADDITIONAL DATA: %s' % (exp, obj), lvl='error') retry() except KeyboardInterrupt: if cleanup is not None: cleanup() turbo.emergency_kill(reclaim=True) except IOError as exp: report.reporter( msg=('IO ERROR: %s. ADDITIONAL DATA: %s' '\nMESSAGE %s will retry.' '\nSTACKTRACE: %s' % (exp, obj, info.__appname__, traceback.format_exc())), lvl='error') retry() except Exception: report.reporter(msg=( 'Failed Operation. ADDITIONAL DATA: %s\n%s will retry\nTB: %s' % (obj, info.__appname__, traceback.format_exc())), lvl='error') retry() finally: if cleanup is not None: cleanup() if conn is not None: conn.close()
def run_turbolift(): """This is the run section of the application Turbolift.""" if len(sys.argv) <= 1: arguments.get_help() raise SystemExit('Give me something to do and I will do it') else: args = arguments.get_args() log = logger.load_in(log_level=args.get('log_level', 'info'), log_location=args.get('log_location', '/var/log')) log.debug('set arguments %s', args) load_constants(log_method=log, args=args) try: from turbolift import worker worker.start_work() except KeyboardInterrupt: turbo.emergency_kill(reclaim=True) finally: print('All Done!')
def start_work(): """Begin Work.""" def get_method(method, name): """Import what is required to run the System.""" to_import = '%s.%s' % (method.__name__, name) return __import__(to_import, fromlist="None") def get_actions(module, name): """Get all available actions from an imported method. :param module: :param name: :return method attributes: """ return getattr(module, name) # Low imports for load in module. import pkgutil # Low imports for load in module. import turbolift as turbo from turbolift.authentication import authentication as auth from turbolift import methods as met try: for mod, name, package in pkgutil.iter_modules(met.__path__): if ARGS.get(name) is not None: titled_name = name.title().replace('_', '') method = get_method(method=met, name=name) actions = get_actions(module=method, name=titled_name) actions(auth=auth.authenticate()).start() break else: raise turbo.SystemProblem('No Method set for processing') except KeyboardInterrupt: turbo.emergency_kill(reclaim=True)
def doerator(work_q, kwargs): """Do Jobs until done. :param work_q: :param job: """ job = kwargs.pop('cf_job') while True: # Get the file that we want to work with wfile = get_from_q(queue=work_q) # If Work is None return None if wfile is None: break try: # Do the job that was provided kwargs['u_file'] = wfile job(**kwargs) except EOFError: turbo.emergency_kill() except KeyboardInterrupt: turbo.emergency_kill(reclaim=True)