code: def _process_running(
      run_model: RunModel,
      job_model: JobModel,
      *,
      ports: Dict[int, int],
  ) -> bool:
      """
      Possible next states:
      - JobStatus.FAILED if runner is not available
      - Any status received from runner
  
      Returns:
          is successful
      """
      runner_client = client.RunnerClient(
          port=ports[client.REMOTE_RUNNER_PORT]
      )
      timestamp = 0
      if job_model.runner_timestamp is not None:
          timestamp = job_model.runner_timestamp
      resp = runner_client.pull(
          timestamp
      )  # raises error if runner is down, causes retry
      job_model.runner_timestamp = resp.last_updated
      logs_services.write_logs(
          project=run_model.project,
          run_name=run_model.run_name,
          job_submission_id=job_model.id,
          runner_logs=resp.runner_logs,
          job_logs=resp.job_logs,
      )
      if len(resp.job_states) > 0:
          last_job_state = resp.job_states[-1]
          job_model.status = last_job_state.state
          if job_model.status == JobStatus.DONE:
              delay_job_instance_termination(job_model)
          logger.info(
              *job_log("now is %s", job_model, job_model.status.value)
          )
      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 4 for calling a global function with example usage: _process_running(run_model, job_model) and returns: True