class_docstr: A ``LightningPlugin`` is a single-file Python class that can be executed within a cloudspace to perform
  actions.
class_docstr_tok: ["A","``","LightningPlugin","``","is","a","single-file","Python","class","that","can","be","executed","within","a","cloudspace","to","perform","actions","."]
docstr: Run a job in the cloudspace associated with this plugin.
  
  Args:
      name: The name of the job.
      app_entrypoint: The path of the file containing the app to run.
      env_vars: Additional env vars to set when running the app.
  
  Returns:
      The spec of the created LightningappInstance.
docstr_tok: ["Run","a","job","in","the","cloudspace","associated","with","this","plugin",".","Args",":","name",":","The","name","of","the","job",".","app_entrypoint",":","The","path","of","the","file","containing","the","app","to","run",".","env_vars",":","Additional","env","vars","to","set","when","running","the","app",".","Returns",":","The","spec","of","the","created","LightningappInstance","."]
code: def run_job(
      self,
      name: str,
      app_entrypoint: str,
      env_vars: Dict[str, str] = {},
  ) -> Externalv1LightningappInstance:
      """Run a job in the cloudspace associated with this plugin.
  
      Args:
          name: The name of the job.
          app_entrypoint: The path of the file containing the app to run.
          env_vars: Additional env vars to set when running the app.
  
      Returns:
          The spec of the created LightningappInstance.
  
      """
      from lightning.app.runners.backends.cloud import CloudBackend
      from lightning.app.runners.cloud import CloudRuntime
  
      logger.info(
          f"Processing job run request. name: {name}, app_entrypoint: {app_entrypoint}, env_vars: {env_vars}"
      )
  
      # Dispatch the job
      _set_flow_context()
  
      entrypoint_file = Path(app_entrypoint)
  
      app = CloudRuntime.load_app_from_file(
          str(entrypoint_file.resolve().absolute()), env_vars=env_vars
      )
  
      app.stage = AppStage.BLOCKING
  
      runtime = CloudRuntime(
          app=app,
          entrypoint=entrypoint_file,
          start_server=True,
          env_vars=env_vars,
          secrets={},
          run_app_comment_commands=True,
          backend=CloudBackend(
              entrypoint_file, client_max_tries=_PLUGIN_MAX_CLIENT_TRIES
          ),
      )
      # Used to indicate Lightning has been dispatched
      os.environ["LIGHTNING_DISPATCHED"] = "1"
  
      return runtime.cloudspace_dispatch(
          project_id=self.project_id,
          cloudspace_id=self.cloudspace_id,
          name=name,
          cluster_id=self.cluster_id,
          source_app=self.source_app,
      )
  
imports: import os
  import shutil
  import tarfile
  import tempfile
  from pathlib import Path
  from typing import Any, Dict
  from urllib.parse import urlparse
  import requests
  import uvicorn
  from fastapi import FastAPI, HTTPException, status
  from fastapi.middleware.cors import CORSMiddleware
  from lightning_cloud.openapi import Externalv1LightningappInstance
  from pydantic import BaseModel
  from lightning.app.utilities.app_helpers import Logger
  from lightning.app.utilities.component import _set_flow_context
  from lightning.app.utilities.enum import AppStage
  from lightning.app.utilities.load_app import _load_plugin_from_file
label_desc: Use image node_id 3 for calling the LightningPlugin obj's underlying member method code with example usage: obj.run_job(name, app_entrypoint, env_vars) and returns: runtime