def test_is_compilable(self): assert LifeCycle.is_unschedulable(None) is False for status in V1Statuses.allowable_values: if status in LifeCycle.COMPILABLE_VALUES: assert LifeCycle.is_compilable(status) is True else: assert LifeCycle.is_compilable(status) is False
def runs_prepare(run_id: int, run: Optional[BaseRun], eager: bool = False) -> bool: run = get_run(run_id=run_id, run=run) if not run: return False if not LifeCycle.is_compilable(run.status): _logger.info( "Run `%s` cannot transition from `%s` to `%s`.", run_id, run.status, V1Statuses.COMPILED, ) return False try: compiled_at = now() _, compiled_operation = resolver.resolve(run=run, compiled_at=compiled_at, eager=eager) except PolyaxonCompilerError as e: condition = V1StatusCondition.get_condition( type=V1Statuses.FAILED, status="True", reason="SchedulerPrepare", message=f"Failed to compile.\n{e}", ) new_run_status(run=run, condition=condition) return False except Exception as e: condition = V1StatusCondition.get_condition( type=V1Statuses.FAILED, status="True", reason="SchedulerPrepare", message=f"Compiler received an internal error.\n{e}", ) new_run_status(run=run, condition=condition) return False condition = V1StatusCondition.get_condition( type=V1Statuses.COMPILED, status="True", reason="SchedulerPrepare", message="Run is compiled", last_update_time=compiled_at, ) new_run_status(run=run, condition=condition) if run.pending: return False if eager: runs_start(run_id=run.id, run=run) return False return True
def runs_prepare(run_id: int, run: Optional[BaseRun], eager: bool = False): run = get_run(run_id=run_id, run=run) if not run: return if not LifeCycle.is_compilable(run.status): _logger.info( "Run `%s` cannot transition from `%s` to `%s`.", run_id, run.status, V1Statuses.COMPILED, ) return None try: compiled_at = now() _, compiled_operation = resolver.resolve(run=run, compiled_at=compiled_at) except PolyaxonCompilerError as e: condition = V1StatusCondition.get_condition( type=V1Statuses.FAILED, status="True", reason="PolyaxonRunFailed", message=f"Run compilation error: {e}", ) new_run_status(run=run, condition=condition) return None condition = V1StatusCondition.get_condition( type=V1Statuses.COMPILED, status="True", reason="PolyaxonRunCompiler", message="Run is compiled", last_update_time=compiled_at, ) new_run_status(run=run, condition=condition) if eager: runs_start(run_id=run.id, run=run) return