bartender.web.api.job.views#

Attributes#

Functions#

retrieve_jobs(→ list[bartender.db.models.job_model.Job])

Retrieve all jobs of user from the database.

retrieve_job(→ bartender.db.models.job_model.Job)

Retrieve specific job from the database.

get_job_dir(]) → pathlib.Path)

Get directory where input and output files of a job reside.

get_dir_of_completed_job(], job_dir, ...)

Get directory of a completed job.

retrieve_job_file(→ fastapi.responses.FileResponse)

Retrieve file from a completed job.

get_destination(→ bartender.destinations.Destination)

Get the destination of a job.

get_completed_logs(→ Tuple[str, str])

Get the standard output and error of a completed job.

retrieve_job_stdout(→ str)

Retrieve the jobs standard output.

retrieve_job_stderr(→ str)

Retrieve the jobs standard error.

retrieve_job_directories(...)

List directory contents of a job.

retrieve_job_directories_from_path(...)

List directory contents of a job.

_remove_archive(→ None)

Remove archive after file response.

retrieve_job_directory_as_archive(, exclude_dirs, filename)

Download contents of job directory as archive.

retrieve_job_subdirectory_as_archive(, exclude_dirs, ...)

Download job output as archive.

_resolve_path(→ pathlib.Path)

_parse_subdirectory(→ pathlib.Path)

get_interactive_app(...)

Get interactive app configuration.

run_interactive_app(...)

Run interactive app on a completed job.

rename_job_name(]) → None)

Rename the name of a job.

delete_job(], user, job_dir, Depends], destination, ...)

Delete a job.

Module Contents#

bartender.web.api.job.views.router#
async bartender.web.api.job.views.retrieve_jobs(job_dao: bartender.db.dao.job_dao.CurrentJobDAO, user: bartender.web.users.CurrentUser, context: bartender.context.CurrentContext, file_staging_queue: bartender.filesystems.queue.CurrentFileOutStagingQueue, limit: int = 10, offset: int = 0) list[bartender.db.models.job_model.Job]#

Retrieve all jobs of user from the database.

Parameters:
  • limit (int) – limit of jobs.

  • offset (int) – offset of jobs.

  • job_dao (bartender.db.dao.job_dao.CurrentJobDAO) – JobDAO object.

  • user (bartender.web.users.CurrentUser) – Current active user.

  • context (bartender.context.CurrentContext) – Context with destinations.

  • file_staging_queue (bartender.filesystems.queue.CurrentFileOutStagingQueue) – When scheduler reports job is complete. The output files need to be copied back. Use queue to perform download outside request/response handling.

Returns:

stream of jobs.

Return type:

list[bartender.db.models.job_model.Job]

async bartender.web.api.job.views.retrieve_job(jobid: int, job_dao: bartender.db.dao.job_dao.CurrentJobDAO, user: bartender.web.users.CurrentUser, context: bartender.context.CurrentContext, file_staging_queue: bartender.filesystems.queue.CurrentFileOutStagingQueue) bartender.db.models.job_model.Job#

Retrieve specific job from the database.

Parameters:
  • jobid (int) – identifier of job instance.

  • job_dao (bartender.db.dao.job_dao.CurrentJobDAO) – JobDAO object.

  • user (bartender.web.users.CurrentUser) – Current active user.

  • context (bartender.context.CurrentContext) – Context with destinations.

  • file_staging_queue (bartender.filesystems.queue.CurrentFileOutStagingQueue) – When scheduler reports job is complete. The output files need to be copied back. Use queue to perform download outside request/response handling.

Raises:

HTTPException – When job is not found or user is not allowed to see job.

Returns:

job models.

Return type:

bartender.db.models.job_model.Job

bartender.web.api.job.views.get_job_dir(jobid: int, job_root_dir: Annotated[pathlib.Path, Depends(get_job_root_dir)]) pathlib.Path#

Get directory where input and output files of a job reside.

Parameters:
  • jobid (int) – The job identifier.

  • job_root_dir (Annotated[pathlib.Path, Depends(get_job_root_dir)]) – Directory in which all jobs are stored.

Returns:

Directory of job.

Return type:

pathlib.Path

bartender.web.api.job.views.get_dir_of_completed_job(job: Annotated[bartender.db.models.job_model.Job, Depends(retrieve_job)], job_dir: Annotated[pathlib.Path, Depends(get_job_dir)]) pathlib.Path#

Get directory of a completed job.

Parameters:
Raises:

HTTPException – When job is not completed.

Returns:

Directory of a completed job.

Return type:

pathlib.Path

bartender.web.api.job.views.CurrentCompletedJobDir#
bartender.web.api.job.views.retrieve_job_file(path: str, job_dir: CurrentCompletedJobDir) fastapi.responses.FileResponse#

Retrieve file from a completed job.

Parameters:
  • path (str) – Path to file that job has produced.

  • job_dir (CurrentCompletedJobDir) – Directory with job output files.

Raises:

HTTPException – When file is not found or is not a file or is outside job directory.

Returns:

The file contents.

Return type:

fastapi.responses.FileResponse

bartender.web.api.job.views.CurrentJob#
bartender.web.api.job.views.get_destination(job: CurrentJob, context: bartender.context.CurrentContext) bartender.destinations.Destination#

Get the destination of a job.

Parameters:
  • job (CurrentJob) – The job.

  • context (bartender.context.CurrentContext) – Context with destinations.

Raises:

ValueError – When job has no destination.

Returns:

The destination of the job.

Return type:

bartender.destinations.Destination

bartender.web.api.job.views.CurrentDestination#
async bartender.web.api.job.views.get_completed_logs(job_dir: CurrentCompletedJobDir, job: CurrentJob, destination: CurrentDestination) Tuple[str, str]#

Get the standard output and error of a completed job.

Parameters:
  • job_dir (CurrentCompletedJobDir) – Directory with job output files.

  • job (CurrentJob) – The job.

  • destination (CurrentDestination) – The destination of the job.

Raises:
  • ValueError – When job has no destination.

  • HTTPException – When a log file is not found.

Returns:

The standard output and error.

Return type:

Tuple[str, str]

bartender.web.api.job.views.CurrentLogs#
async bartender.web.api.job.views.retrieve_job_stdout(logs: CurrentLogs) str#

Retrieve the jobs standard output.

Parameters:

logs (CurrentLogs) – The standard output and error of a completed job.

Returns:

Content of standard output.

Return type:

str

bartender.web.api.job.views.retrieve_job_stderr(logs: CurrentLogs) str#

Retrieve the jobs standard error.

Parameters:

logs (CurrentLogs) – The standard output and error of a completed job.

Returns:

Content of standard error.

Return type:

str

async bartender.web.api.job.views.retrieve_job_directories(job_dir: CurrentCompletedJobDir, max_depth: pydantic.PositiveInt = 1) bartender.walk_dir.DirectoryItem#

List directory contents of a job.

Parameters:
  • max_depth (pydantic.PositiveInt) – Number of directories to traverse into.

  • job_dir (CurrentCompletedJobDir) – The job directory.

Returns:

Listing of files and directories.

Return type:

DirectoryItem

async bartender.web.api.job.views.retrieve_job_directories_from_path(path: str, job_dir: CurrentCompletedJobDir, max_depth: pydantic.PositiveInt = 1) bartender.walk_dir.DirectoryItem#

List directory contents of a job.

Parameters:
  • path (str) – Sub directory inside job directory to start from.

  • max_depth (pydantic.PositiveInt) – Number of directories to traverse into.

  • job_dir (CurrentCompletedJobDir) – The job directory.

Returns:

Listing of files and directories.

Return type:

DirectoryItem

bartender.web.api.job.views._remove_archive(filename: str) None#

Remove archive after file response.

Parameters:

filename (str) – path to the file that should be removed.

Return type:

None

async bartender.web.api.job.views.retrieve_job_directory_as_archive(job_dir: CurrentCompletedJobDir, background_tasks: fastapi.BackgroundTasks, archive_format: bartender.web.api.job.archive.ArchiveFormat = '.zip', exclude: list[str] | None = Query(default=None), exclude_dirs: list[str] | None = Query(default=None), filename: str | None = Query(default=None)) fastapi.responses.FileResponse#

Download contents of job directory as archive.

Parameters:
  • job_dir (CurrentCompletedJobDir) – The job directory.

  • background_tasks (fastapi.BackgroundTasks) – FastAPI mechanism for post-processing tasks

  • archive_format (bartender.web.api.job.archive.ArchiveFormat) – Format to use for archive. Supported formats are ‘.zip’, ‘.tar’, ‘.tar.xz’, ‘.tar.gz’, ‘.tar.bz2’

  • exclude (Optional[list[str]]) – list of filename patterns that should be excluded from archive.

  • exclude_dirs (Optional[list[str]]) – list of directory patterns that should be excluded from archive.

  • filename (Optional[str]) – Name of the archive file to be returned. If not provided, uses id of the job.

Returns:

Archive containing the content of job_dir

Return type:

FileResponse

async bartender.web.api.job.views.retrieve_job_subdirectory_as_archive(path: str, job_dir: CurrentCompletedJobDir, background_tasks: fastapi.BackgroundTasks, archive_format: bartender.web.api.job.archive.ArchiveFormat = '.zip', exclude: list[str] | None = Query(default=None), exclude_dirs: list[str] | None = Query(default=None), filename: str | None = Query(default=None)) fastapi.responses.FileResponse#

Download job output as archive.

Parameters:
  • path (str) – Sub directory inside job directory to start from.

  • job_dir (CurrentCompletedJobDir) – The job directory.

  • background_tasks (fastapi.BackgroundTasks) – FastAPI mechanism for post-processing tasks

  • archive_format (bartender.web.api.job.archive.ArchiveFormat) – Format to use for archive. Supported formats are ‘.zip’, ‘.tar’, ‘.tar.xz’, ‘.tar.gz’, ‘.tar.bz2’

  • exclude (Optional[list[str]]) – list of filename patterns that should be excluded from archive.

  • exclude_dirs (Optional[list[str]]) – list of directory patterns that should be excluded from archive.

  • filename (Optional[str]) – Name of the archive file to be returned. If not provided, uses id of the job.

Returns:

Archive containing the output of job_dir

Return type:

FileResponse

bartender.web.api.job.views._resolve_path(path: str, job_dir: pathlib.Path) pathlib.Path#
Parameters:
Return type:

pathlib.Path

bartender.web.api.job.views._parse_subdirectory(path: str, job_dir: pathlib.Path) pathlib.Path#
Parameters:
Return type:

pathlib.Path

bartender.web.api.job.views.get_interactive_app(application: str, config: bartender.config.CurrentConfig) bartender.config.InteractiveApplicationConfiguration#

Get interactive app configuration.

Parameters:
  • application (str) – The interactive application.

  • config (bartender.config.CurrentConfig) – The bartender configuration.

Returns:

The interactive application configuration.

Return type:

bartender.config.InteractiveApplicationConfiguration

bartender.web.api.job.views.CurrentInteractiveAppConf#
async bartender.web.api.job.views.run_interactive_app(request: fastapi.Request, job_dir: CurrentCompletedJobDir, job: CurrentJob, application: CurrentInteractiveAppConf) bartender.web.api.job.interactive_apps.InteractiveAppResult#

Run interactive app on a completed job.

Parameters:
  • request (fastapi.Request) – The request.

  • job_dir (CurrentCompletedJobDir) – The job directory.

  • job (CurrentJob) – The job.

  • application (CurrentInteractiveAppConf) – The interactive application.

Returns:

The result of running the interactive application.

Raises:

HTTPException – When job was not run with the required application or the payload is invalid or the load on the machine is too high.

Return type:

bartender.web.api.job.interactive_apps.InteractiveAppResult

async bartender.web.api.job.views.rename_job_name(jobid: int, job_dao: bartender.db.dao.job_dao.CurrentJobDAO, user: bartender.web.users.CurrentUser, name: Annotated[str, Body(max_length=MAX_LENGTH_NAME, min_length=1)]) None#

Rename the name of a job.

Parameters:
  • jobid (int) – The job identifier.

  • job_dao (bartender.db.dao.job_dao.CurrentJobDAO) – The job DAO.

  • user (bartender.web.users.CurrentUser) – The current user.

  • name (Annotated[str, Body(max_length=MAX_LENGTH_NAME, min_length=1)]) – The new name of the job.

Raises:

HTTPException – When job is not found. Or when user is not owner of job.

Return type:

None

async bartender.web.api.job.views.delete_job(jobid: int, job_dao: bartender.db.dao.job_dao.CurrentJobDAO, job: Annotated[bartender.db.models.job_model.Job, Depends(retrieve_job)], user: bartender.web.users.CurrentUser, job_dir: Annotated[pathlib.Path, Depends(get_job_dir)], destination: CurrentDestination, job_root_dir: Annotated[pathlib.Path, Depends(get_job_root_dir)]) None#

Delete a job.

Deletes job from database and filesystem.

When job is queued or running it will be canceled and removed from the filesystem where the job is located.

Parameters:
  • jobid (int) – The job identifier.

  • job_dao (bartender.db.dao.job_dao.CurrentJobDAO) – The job DAO.

  • job (Annotated[bartender.db.models.job_model.Job, Depends(retrieve_job)]) – The job.

  • user (bartender.web.users.CurrentUser) – The current user.

  • job_dir (Annotated[pathlib.Path, Depends(get_job_dir)]) – The job directory.

  • destination (CurrentDestination) – The destination of the job.

  • job_root_dir (Annotated[pathlib.Path, Depends(get_job_root_dir)]) – The root directory of all jobs.

Raises:

HTTPException – When job is not found. Or when user is not owner of job. Or when job is in state that cannot be deleted.

Return type:

None