def restart(context, max_gaussian, restart, email, case, extras, disable, start_from, config_path): """Restart MIP with modifications to the config file.""" if not case and not config_path: log.error("you must provide either case of config path") context.abort() if case: most_recent = api.case(case).first() config_path = most_recent.config_path if max_gaussian: new_values = restart_api.update_maxgaussian(config_path) else: extras = dict(extras) new_values = restart_api.update_config(config_path, start_step=start_from, disable_branches=disable, **extras) log.info("update config: {}".format(config_path)) restart_api.write_config(config_path, new_values) if restart: email = email or environ_email() or new_values.get('email') kwargs = dict(executable=context.obj['mip_exe'], email=email) process = start_mip(config=config_path, **kwargs) process.wait() if process.returncode != 0: log.error("error starting analysis, check the output") context.abort() if case: new_entry = build_pending(most_recent.case_id, most_recent.root_dir) commit_analysis(context.obj['manager'], new_entry)
def commit_analysis(manager, new_entry, email=None): """Store new analysis in the database.""" # look up previous runs for the same case old_runs = api.case(case_id=new_entry.case_id) latest_run = old_runs.first() if latest_run is None or not same_entry(latest_run, new_entry): if new_entry.status == 'completed': # set failed runs to not be visible in dashboard for old_run in old_runs: old_runs.is_visible = False manager.commit() # save the new entry to the database if latest_run and latest_run.status in ('running', 'pending'): # replace old temporary entries log.debug("deleting existing entry: %s", new_entry.case_id) latest_run.delete() manager.commit() if email: new_entry.user = api.user(email) manager.add_commit(new_entry) log.info("added new entry: {entry.case_id} - {entry.status}" .format(entry=new_entry))