code: def most_recent_job(
      job_type: str, session: Session = NEW_SESSION
  ) -> Job | JobPydantic | None:
      """
      Return the most recent job of this type, if any, based on last heartbeat received.
  
      Jobs in "running" state take precedence over others to make sure alive
      job is returned if it is available.
  
      :param job_type: job type to query for to get the most recent job for
      :param session: Database session
      """
      return session.scalar(
          select(Job)
          .where(Job.job_type == job_type)
          .order_by(
              # Put "running" jobs at the front.
              case({JobState.RUNNING: 0}, value=Job.state, else_=1),
              Job.latest_heartbeat.desc(),
          )
          .limit(1)
      )
  
imports: from __future__ import annotations
  from functools import cached_property
  from time import sleep
  from typing import TYPE_CHECKING, Callable, NoReturn
  from sqlalchemy import Column, Index, Integer, String, case, select
  from sqlalchemy.exc import OperationalError
  from sqlalchemy.orm import backref, foreign, relationship
  from sqlalchemy.orm.session import make_transient
  from airflow.api_internal.internal_api_call import internal_api_call
  from airflow.configuration import conf
  from airflow.exceptions import AirflowException
  from airflow.executors.executor_loader import ExecutorLoader
  from airflow.listeners.listener import get_listener_manager
  from airflow.models.base import ID_LEN, Base
  from airflow.serialization.pydantic.job import JobPydantic
  from airflow.stats import Stats
  from airflow.utils import timezone
  from airflow.utils.helpers import convert_camel_to_snake
  from airflow.utils.log.logging_mixin import LoggingMixin
  from airflow.utils.net import get_hostname
  from airflow.utils.platform import getuser
  from airflow.utils.session import NEW_SESSION, provide_session
  from airflow.utils.sqlalchemy import UtcDateTime
  from airflow.utils.state import JobState
label_desc: Use image node_id 2 for calling a global function with example usage: most_recent_job(job_type, session) and returns: session