code: def _update_execution_state_in_mlmd(
      mlmd_handle: metadata.Metadata,
      node_uid: task_lib.NodeUid,
      execution_id: int,
      new_state: proto.Execution.State,
      error_code: int,
      error_msg: str,
      execution_result: Optional[
          execution_result_pb2.ExecutionResult
      ] = None,
  ) -> None:
      """Updates the execution state and sets execution_result if provided."""
      with mlmd_state.mlmd_execution_atomic_op(
          mlmd_handle,
          execution_id,
          on_commit=event_observer.make_notify_execution_state_change_fn(
              node_uid
          ),
      ) as execution:
          execution.last_known_state = new_state
          data_types_utils.set_metadata_value(
              execution.custom_properties[
                  constants.EXECUTION_ERROR_CODE_KEY
              ],
              error_code,
          )
          if error_msg:
              data_types_utils.set_metadata_value(
                  execution.custom_properties[
                      constants.EXECUTION_ERROR_MSG_KEY
                  ],
                  error_msg,
              )
          if execution_result:
              execution_lib.set_execution_result(
                  execution_result, execution
              )
  
imports: from __future__ import annotations
  from typing import Optional
  from absl import logging
  from tfx.dsl.io import fileio
  from tfx.orchestration import data_types_utils
  from tfx.orchestration import metadata
  from tfx.orchestration.experimental.core import component_generated_alert_pb2
  from tfx.orchestration.experimental.core import constants
  from tfx.orchestration.experimental.core import event_observer
  from tfx.orchestration.experimental.core import garbage_collection
  from tfx.orchestration.experimental.core import mlmd_state
  from tfx.orchestration.experimental.core import task
  from tfx.orchestration.experimental.core import task_scheduler
  from tfx.orchestration.portable import data_types
  from tfx.orchestration.portable import execution_publish_utils
  from tfx.orchestration.portable.mlmd import execution_lib
  from tfx.proto.orchestration import execution_result_pb2
  from tfx.utils import status
  from tfx.utils import typing_utils
  from ml_metadata import proto
label_desc: Use image node_id 3 for calling a global function with example usage: _update_execution_state_in_mlmd(mlmd_handle, node_uid, execution_id, new_state, error_code, error_msg, execution_result) without return types