def run(self): """ main runner """ config = self.cm.get_section_items('main') url_list = config.get('url_list') url_list = ast.literal_eval(url_list) worker = lib.worker.Worker(url_list) worker.start()
def _run_test_worker_pool(runnable_test_cases, test_cases): # Generate Work List job_matrix = [] for job_index in range(int(math.ceil(len(runnable_test_cases) / test_pool))): worker_matrix = [] for worker_index in range(test_pool): if job_index * test_pool + worker_index < len(runnable_test_cases): worker_matrix.append( runnable_test_cases[(job_index * test_pool) + worker_index]) else: continue job_matrix.append(worker_matrix) # Cycle through job_matrix and run each job in a thread job_index = 1 for job in job_matrix: workers = list() for index in range(len(job)): worker = Process(target=_run_test_case, args=(job, index)) worker.start() workers.append(worker) keep_trying = True while keep_trying: logger.info('Currently Running Job %s of %s' % (str(job_index), str(len(job_matrix)))) time.sleep(worker_pause) keep_trying = False for index in range(len(job)): fp = open(job[index]['test_case_file']) test_case = json.load(fp) fp.close() test_name = test_case['template_name'] + '_' + test_case[ 'cloud'] + '_' + test_case['test_case'] if test_case['status'] == CASE_INPROGRESS: keep_trying = True logger.info('Test Case Running : %s with Status of : %s' % (test_name, test_case['status'])) logger.info( 'No more tests in progress, waiting for all worker threads to complete' ) for worker in workers: worker.join() job_index = job_index + 1 logger.info('Testing Complete') return _generate_test_status(test_cases)
def _run_test_queue(runnable_test_cases, test_cases): # Cycle through job_matrix and run each job in a thread job_index = 1 floor = 1 ceiling = test_pool if test_pool > len(runnable_test_cases): ceiling = len(runnable_test_cases) workers = list() for index in range(ceiling): worker = Process(target=_run_test_case, args=(runnable_test_cases, index)) worker.start() workers.append(worker) keep_trying = True test_indices = range(ceiling) while keep_trying: remove_indices = [] logger.info('Currently running tests %s-%s of %s' % (str(floor), str(ceiling), str(len(runnable_test_cases)))) time.sleep(worker_pause) keep_trying = False for index in test_indices: fp = open(runnable_test_cases[index]['test_case_file']) test_case = json.load(fp) fp.close() test_name = test_case['template_name'] + '_' + test_case[ 'cloud'] + '_' + test_case['test_case'] # If we're in progress, keep going. Otherwise, add the index to the list of indices to remove if test_case['status'] == CASE_INPROGRESS or test_case[ 'status'] == CASE_UNTESTED: keep_trying = True else: remove_indices.append(index) logger.info('Test Case Running : %s with Status of : %s' % (test_name, test_case['status'])) for remove_index in remove_indices: try: test_indices.remove(remove_index) if ceiling < len(runnable_test_cases): keep_trying = True worker = Process(target=_run_test_case, args=(runnable_test_cases, ceiling)) worker.start() workers.append(worker) test_indices.append(ceiling) ceiling = ceiling + 1 floor = floor + 1 elif floor < len(runnable_test_cases): floor = floor + 1 except ValueError: pass logger.info( 'No more tests in progress, waiting for all worker threads to complete' ) for worker in workers: worker.join() job_index = job_index + 1 logger.info('Testing Complete') return _generate_test_status(test_cases)
from flask import Flask,render_template,request,jsonify import lib import lib.worker import signal import sys import json from plugins import * lib.app = Flask(__name__) worker = lib.worker.Fetcher() worker.start() def properexit(signum,frame): worker.stop.set() worker.join() lib.app.logger.info("OS Exit") sys.exit() signal.signal(signal.SIGINT, properexit) @lib.app.route("/") @lib.app.route("/<name>") def main(name="home"): return render_template('index.html',name=name) @lib.app.route("/api",methods=['POST']) def api(): api_data = request.get_json(force=True) return_data = {"status":1} if "action" in api_data and "param" in api_data: if api_data["action"] == "fetch":