示例#1
0
    def execute_rpc(self, rpc: RemoteProcedureCall, timeout_s: float = 120):
        timeout_period_end = datetime.datetime.utcnow() + datetime.timedelta(
            seconds=timeout_s)
        spin_interval_ms = 10  # TODO: make intelligent choice

        submitted_rpc = self.models_database.submit_remote_procedure_call(
            rpc=rpc)
        old_status = submitted_rpc.request_status
        while datetime.datetime.now() < timeout_period_end:
            self.models_database.get_updated_request_status(submitted_rpc)
            if submitted_rpc.request_status != old_status:
                if submitted_rpc.request_status == 'complete':
                    #self.models_database.remove_rpc(submitted_rpc)
                    return json.loads(submitted_rpc.result,
                                      cls=HypergridJsonDecoder)
                if submitted_rpc.request_status == 'in progress':
                    continue
                if submitted_rpc.request_status == 'failed':
                    if submitted_rpc.result is not None:
                        exception = deserialize_from_bytes_string(rpc.result)
                        raise exception
                else:
                    raise RuntimeError(
                        f"Remote Procedure Call status: {submitted_rpc.request_status}."
                    )
            else:
                # nothing to do... chill for a bit
                time.sleep(spin_interval_ms / 1000.0)
        submitted_rpc.status = 'timed out'
        self.models_database.get_updated_request_status(submitted_rpc)
        raise TimeoutError("Remote Procedure Call timed out.")
示例#2
0
 def get_optimizer_convergence_state(self):
     optimizer_convergence_state_response = self._optimizer_stub.GetOptimizerConvergenceState(
         self.optimizer_handle)
     return deserialize_from_bytes_string(
         optimizer_convergence_state_response.
         SerializedOptimizerConvergenceState)