code: def job_model_to_job_submission(job_model: JobModel) -> JobSubmission:
      job_provisioning_data = None
      if job_model.job_provisioning_data is not None:
          job_provisioning_data = JobProvisioningData.parse_raw(
              job_model.job_provisioning_data
          )
          # TODO remove after transitioning to computed fields
          job_provisioning_data.instance_type.resources.description = (
              job_provisioning_data.instance_type.resources.pretty_format()
          )
      finished_at = None
      if job_model.status.is_finished():
          finished_at = job_model.last_processed_at.replace(
              tzinfo=timezone.utc
          )
      return JobSubmission(
          id=job_model.id,
          submission_num=job_model.submission_num,
          submitted_at=job_model.submitted_at.replace(
              tzinfo=timezone.utc
          ),
          finished_at=finished_at,
          status=job_model.status,
          error_code=job_model.error_code,
          job_provisioning_data=job_provisioning_data,
      )
  
imports: import asyncio
  import datetime
  import socket
  from datetime import timezone
  from typing import Dict, List, Optional
  from sqlalchemy import update
  from sqlalchemy.ext.asyncio import AsyncSession
  from dstack._internal.core.errors import SSHError
  from dstack._internal.core.models.configurations import ConfigurationType
  from dstack._internal.core.models.runs import Job, JobErrorCode, JobProvisioningData, JobSpec, JobStatus, JobSubmission, RunSpec
  from dstack._internal.core.services.ssh import tunnel
  from dstack._internal.server.models import JobModel, ProjectModel
  from dstack._internal.server.services.backends import get_project_backend_by_type
  from dstack._internal.server.services.jobs.configurators.base import JobConfigurator
  from dstack._internal.server.services.jobs.configurators.dev import DevEnvironmentJobConfigurator
  from dstack._internal.server.services.jobs.configurators.service import ServiceJobConfigurator
  from dstack._internal.server.services.jobs.configurators.task import TaskJobConfigurator
  from dstack._internal.server.services.logging import job_log
  from dstack._internal.server.services.runner import client
  from dstack._internal.server.utils.common import run_async
  from dstack._internal.utils.common import get_current_datetime
  from dstack._internal.utils.logging import get_logger
label_desc: Use image node_id 3 for calling a global function with example usage: job_model_to_job_submission(job_model) and returns: JobSubmission