code: def _process_provisioning_with_shim(
      job_model: JobModel,
      secrets: Dict[str, str],
      registry_auth: Optional[RegistryAuth],
      *,
      ports: Dict[int, int],
  ) -> bool:
      """
      Possible next states:
      - JobStatus.PULLING if shim is available
      - JobStatus.FAILED if timeout is exceeded
  
      Returns:
          is successful
      """
      shim_client = client.ShimClient(
          port=ports[client.REMOTE_SHIM_PORT]
      )
      resp = shim_client.healthcheck()
      if resp is None:
          logger.debug(*job_log("shim is not available yet", job_model))
          return False  # shim is not available yet
      if registry_auth is not None:
          logger.debug(
              *job_log("authenticating to the registry...", job_model)
          )
          interpolate = VariablesInterpolator(
              {"secrets": secrets}
          ).interpolate
          shim_client.registry_auth(
              username=interpolate(registry_auth.username),
              password=interpolate(registry_auth.password),
          )
      job_model.status = JobStatus.PULLING
      logger.info(*job_log("now is pulling", job_model))
      return True
  
imports: from datetime import timedelta
  from typing import Dict, Optional
  from uuid import UUID
  import requests
  from sqlalchemy import select
  from sqlalchemy.ext.asyncio import AsyncSession
  from sqlalchemy.orm import joinedload
  from dstack._internal.core.errors import GatewayError
  from dstack._internal.core.models.backends.base import BackendType
  from dstack._internal.core.models.configurations import RegistryAuth
  from dstack._internal.core.models.repos import RemoteRepoCreds
  from dstack._internal.core.models.runs import Job, JobErrorCode, JobProvisioningData, JobStatus, Run
  from dstack._internal.server.db import get_session_ctx
  from dstack._internal.server.models import GatewayModel, JobModel, ProjectModel, RepoModel, RunModel
  from dstack._internal.server.services import logs
  from dstack._internal.server.services.gateways.ssh import gateway_tunnel_client
  from dstack._internal.server.services.jobs import RUNNING_PROCESSING_JOBS_IDS, RUNNING_PROCESSING_JOBS_LOCK, delay_job_instance_termination, job_model_to_job_submission
  from dstack._internal.server.services.logging import job_log
  from dstack._internal.server.services.repos import get_code_model, repo_model_to_repo_head
  from dstack._internal.server.services.runner import client
  from dstack._internal.server.services.runner.ssh import runner_ssh_tunnel
  from dstack._internal.server.services.runs import create_job_model_for_new_submission, run_model_to_run
  from dstack._internal.server.services.storage import get_default_storage
  from dstack._internal.server.utils.common import run_async
  from dstack._internal.utils import common
  from dstack._internal.utils.interpolator import VariablesInterpolator
  from dstack._internal.utils.logging import get_logger
label_desc: Use image node_id 2 for calling a global function with example usage: _process_provisioning_with_shim(job_model, secrets, registry_auth) and returns: True, False