code: def _process_pulling_with_shim(
      run: Run,
      job_model: JobModel,
      job: Job,
      code: bytes,
      secrets: Dict[str, str],
      repo_credentials: Optional[RemoteRepoCreds],
      *,
      ports: Dict[int, int],
  ) -> bool:
      """
      Possible next states:
      - JobStatus.RUNNING if runner is available
      - JobStatus.FAILED if shim is not available
  
      Returns:
          is successful
      """
      shim_client = client.ShimClient(
          port=ports[client.REMOTE_SHIM_PORT]
      )
      shim_client.pull()  # raises error if shim is down, causes retry
  
      runner_client = client.RunnerClient(
          port=ports[client.REMOTE_RUNNER_PORT]
      )
      resp = runner_client.healthcheck()
      if resp is None:
          return True  # runner is not available yet, but shim is alive (pulling)
  
      _submit_job_to_runner(
          runner_client=runner_client,
          run=run,
          job_model=job_model,
          job=job,
          code=code,
          secrets=secrets,
          repo_credentials=repo_credentials,
      )
      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 3 for calling a global function with example usage: _process_pulling_with_shim(run, job_model, job, code, secrets, repo_credentials) and returns: True, True