def create_worker_app(): """Create worker app.""" # load settings settings = Settings() settings.load_settings(config_file=constants.CONFIG_FILE) settings.set_client(constants.CLIENT_NAME, constants.CLIENT_VERSION) if is_worker_enabled(): task_queue = settings.get_setting("task_queue") worker_app = Celery( 'tasks', backend=task_queue["backend"], broker=task_queue["broker_url"] ) # configure worker worker_app.conf.update( CELERY_TASK_SERIALIZER='json', CELERY_ACCEPT_CONTENT=['json'] ) if worker_app is None: logger.error("Error connection to task queue") else: logger.info( "Connected to task queue : %s", task_queue["broker_url"] ) else: worker_app = Celery() logger.warning( "Task queue is not defined," " check README.md to configure task queue" ) return worker_app
class Root(object): """Root handler.""" def __init__(self): """ Initialise class. Load config file and set loglevel, define error page handler """ self.settings = Settings() self.settings.load_settings(config_file=constants.CONFIG_FILE) self.settings.set_client(constants.CLIENT_NAME, constants.CLIENT_VERSION) self.file_index = os.path.join(STATIC_DIR, "index.html") cherrypy.config.update({'error_page.404': self.error_page_404}) # get logger self.logger = logger @cherrypy.expose def index(self): """Index page.""" if check_file(self.file_index): return open(self.file_index) else: raise cherrypy.HTTPError(404, "File not found") def error_page_404(self, status, message, traceback, version): """Error Page (404).""" self.logger.error( "Cherrypy %s : Error loading page (%s) : %s\nTraceback : %s", version, status, message, traceback) return "This page doesn't exist, please check usage on " \ "the {} website.".format(SERVICE_WEBSITE_LINK)
def generate_trend(argv): """Generate trends from analysed buildtime data.""" settings = Settings() # load settings from config file, env_var and cli parameters if settings.load_settings(argv) is None: return # load Travis CI environment variables env_var.load_all(settings) # run trend_keen() always, # if $KEEN_PROJECT_ID variable is set (checked later), it will be executed if settings.get_setting("mode_native") is True: trend_native() if settings.get_setting("mode_keen") is True: trend_keen()
def get_read_key(argv): """Generate a read key for the project and print that key.""" settings = Settings() # load settings from config file, env_var and cli parameters args = settings.load_settings(argv) # exit script if processing cli parameters failed (result = None) if args is None: return # get project name from argument # check if collection is empty if args: settings.set_project_name(args[0]) # generate a read key print(keenio.generate_read_key(settings.get_project_name()))
def retrieve_and_store_data(argv): """ Load timing and build data, process and store it. Retrieve timing and build data from Travis CI log, parse it and store the result in Keen.io. Parameters: - argv : command line parameters """ settings = Settings() settings.set_client(CLIENT_NAME, CLIENT_VERSION) # load settings from config file, env_var and cli parameters if settings.load_settings(argv, "config_service.yml") is None: return build = settings.get_setting('build') if build is None: print("Build number is not set, use --build=build_id") return travis_data = TravisData(settings.get_project_name(), build) # retrieve build data using Travis CI API print( "Retrieve build #{:s} data of {:s} from Travis CI".format( build, settings.get_project_name() ) ) travis_data.get_build_data() # process all build jobs travis_data.process_build_jobs() if not keenio.is_writable(): print("Keen IO write key not set, no data was sent") return # send build job data to Keen.io for build_job in travis_data.build_jobs: print("Send build job #{:s} data to Keen.io".format(build_job)) keenio.send_build_data_service(travis_data.build_jobs[build_job])