def run(): """ Run a job """ global last_usage_time global backend_handler global jobs message = flask.request.get_json(force=True, silent=True) if message and not isinstance(message, dict): return error() last_usage_time = time.time() standalone_config = message['config']['standalone'] backend_handler.auto_dismantle = standalone_config['auto_dismantle'] backend_handler.soft_dismantle_timeout = standalone_config[ 'soft_dismantle_timeout'] backend_handler.hard_dismantle_timeout = standalone_config[ 'hard_dismantle_timeout'] act_id = str(uuid.uuid4()).replace('-', '')[:12] runtime = message['job_description']['runtime_name'] executor_id = message['executor_id'] job_id = message['job_id'] jobs['{}_{}'.format(executor_id.replace('/', '-'), job_id)] = 'running' localhost_handler = LocalhostHandler({'runtime': runtime}) localhost_handler.run_job(message) response = flask.jsonify({'activationId': act_id}) response.status_code = 202 return response
def run(): """ Run a job """ global last_usage_time global jobs message = flask.request.get_json(force=True, silent=True) if message and not isinstance(message, dict): return error() last_usage_time = time.time() act_id = str(uuid.uuid4()).replace('-', '')[:12] runtime = message['job_description']['runtime_name'] logger.info("Running job in {}".format(runtime)) executor_id = message['job_description']['executor_id'] job_id = message['job_description']['job_id'] jobs['{}_{}'.format(executor_id.replace('/', '-'), job_id)] = 'running' localhost_handler = LocalhostHandler({'runtime': runtime}) localhost_handler.run_job(message) response = flask.jsonify({'activationId': act_id}) response.status_code = 202 return response
def run(): """ Run a job """ global BUDGET_KEEPER job_payload = flask.request.get_json(force=True, silent=True) if job_payload and not isinstance(job_payload, dict): return error('The action did not receive a dictionary as an argument.') try: runtime = job_payload['runtime_name'] verify_runtime_name(runtime) except Exception as e: return error(str(e)) BUDGET_KEEPER.last_usage_time = time.time() BUDGET_KEEPER.update_config(job_payload['config']['standalone']) BUDGET_KEEPER.jobs[job_payload['job_key']] = 'running' pull_runtime = STANDALONE_CONFIG.get('pull_runtime', False) localhost_handler = LocalhostHandler({ 'runtime': runtime, 'pull_runtime': pull_runtime }) localhost_handler.run_job(job_payload) act_id = str(uuid.uuid4()).replace('-', '')[:12] response = flask.jsonify({'activationId': act_id}) response.status_code = 202 return response
def run(): """ Run a job locally, in consume mode """ global BUDGET_KEEPER global WORK_QUEUES global JOB_PROCESSES job_payload = flask.request.get_json(force=True, silent=True) if job_payload and not isinstance(job_payload, dict): return error('The action did not receive a dictionary as an argument.') try: runtime = job_payload['runtime_name'] verify_runtime_name(runtime) except Exception as e: return error(str(e)) job_key = job_payload['job_key'] logger.info('Received job {}'.format(job_key)) BUDGET_KEEPER.last_usage_time = time.time() BUDGET_KEEPER.update_config(job_payload['config']['standalone']) BUDGET_KEEPER.jobs[job_key] = 'running' exec_mode = job_payload['config']['standalone'].get('exec_mode', 'consume') if exec_mode == 'consume': # Consume mode runs the job locally pull_runtime = STANDALONE_CONFIG.get('pull_runtime', False) localhost_handler = LocalhostHandler({ 'runtime': runtime, 'pull_runtime': pull_runtime }) localhost_handler.run_job(job_payload) elif exec_mode == 'create': # Create mode runs the job in worker VMs work_queue = MP_MANAGER.Queue() WORK_QUEUES[job_key] = work_queue jp = mp.Process(target=run_job_process, args=(job_payload, work_queue)) jp.daemon = True jp.start() JOB_PROCESSES[job_key] = jp act_id = str(uuid.uuid4()).replace('-', '')[:12] response = flask.jsonify({'activationId': act_id}) response.status_code = 202 return response
def run(): """ Run a job """ global last_usage_time global backend_handler global jobs message = flask.request.get_json(force=True, silent=True) if message and not isinstance(message, dict): return error('The action did not receive a dictionary as an argument.') try: runtime = message['job_description']['runtime_name'] verify_runtime_name(runtime) except Exception as e: return error(str(e)) last_usage_time = time.time() standalone_config = message['config']['standalone'] backend_handler.auto_dismantle = standalone_config['auto_dismantle'] backend_handler.soft_dismantle_timeout = standalone_config[ 'soft_dismantle_timeout'] backend_handler.hard_dismantle_timeout = standalone_config[ 'hard_dismantle_timeout'] act_id = str(uuid.uuid4()).replace('-', '')[:12] executor_id = message['executor_id'] job_id = message['job_id'] job_key = create_job_key(executor_id, job_id) jobs[job_key] = 'running' localhost_handler = LocalhostHandler({'runtime': runtime}) localhost_handler.run_job(message) response = flask.jsonify({'activationId': act_id}) response.status_code = 202 return response
def run_worker(master_ip, job_key): """ Run a job """ global BUDGET_KEEPER while True: url = 'http://{}:{}/get-task/{}'.format(master_ip, STANDALONE_SERVICE_PORT, job_key) logger.info('Getting task from {}'.format(url)) resp = requests.get(url) if resp.status_code != 200: logger.info('All tasks completed'.format(url)) return job_payload = resp.json() logger.info(job_payload) logger.info('Got tasks {}'.format(', '.join(job_payload['call_ids']))) try: runtime = job_payload['runtime_name'] verify_runtime_name(runtime) except Exception: return BUDGET_KEEPER.last_usage_time = time.time() BUDGET_KEEPER.update_config(job_payload['config']['standalone']) BUDGET_KEEPER.jobs[job_payload['job_key']] = 'running' pull_runtime = STANDALONE_CONFIG.get('pull_runtime', False) localhost_handler = LocalhostHandler({ 'runtime': runtime, 'pull_runtime': pull_runtime }) localhost_handler.run_job(job_payload) wait_job_completed(job_key)