server.web.repositories.task_template_repository

Attributes

logger

Classes

ResourceUsageStatistics

Clean data class for resource usage statistics.

TaskTemplateRepository

Initialize the TaskTemplateRepository with a database session.

Module Contents

server.web.repositories.task_template_repository.logger
class server.web.repositories.task_template_repository.ResourceUsageStatistics

Clean data class for resource usage statistics.

num_tasks: int | None = None
min_mem: int | None = None
max_mem: int | None = None
mean_mem: float | None = None
min_runtime: int | None = None
max_runtime: int | None = None
mean_runtime: float | None = None
median_mem: float | None = None
median_runtime: float | None = None
ci_mem: List[float | None] | None = None
ci_runtime: List[float | None] | None = None
viz_data: List[jobmon.server.web.schemas.task_template.TaskResourceVizItem] | None = None
class server.web.repositories.task_template_repository.TaskTemplateRepository(session: sqlalchemy.orm.Session)

Initialize the TaskTemplateRepository with a database session.

session
get_task_resource_details(task_template_version_id: int, workflows: List[int] | None, node_args: Dict[str, List[Any]] | None, limit: int | None = None, offset: int = 0) List[jobmon.server.web.schemas.task_template.TaskResourceDetailItem]

Fetch and filter task resource details with optimized single-query approach.

Uses LEFT JOINs on TaskInstance and TaskResources so that every task appears in the result set regardless of instance state: - Tasks with terminal instances → full resource data - Tasks with running/launched instances → instance row, null resources - Tasks with no instances yet (registered) → single row, null instance fields Status falls back to Task.status when no instance exists.

Pagination: when limit is provided, rows are ordered by (Task.id, TaskInstance.id) for deterministic paging and the supplied offset / limit are applied.

calculate_resource_statistics(task_details: List[jobmon.server.web.schemas.task_template.TaskResourceDetailItem], confidence_interval: str | None = None, task_template_version_id: int | None = None) ResourceUsageStatistics

Calculate statistics from task details using scipy.stats.

count_task_resource_details(task_template_version_id: int, workflows: List[int] | None, node_args: Dict[str, List[Any]] | None) int

Count rows that get_task_resource_details would return.

Used by the paginated endpoint to report total_count without materializing the full detail payload. Uses LEFT OUTER JOIN on task_instance to match the paged detail query shape: tasks with no instances yet (registered-but-not-launched) appear as a single row in the paged output, so they must be counted here too or total_count understates the true row count and the frontend stops paginating early.

get_task_resource_aggregates(task_template_version_id: int, workflows: List[int] | None, node_args: Dict[str, List[Any]] | None = None, latest_only: bool = True) jobmon.server.web.schemas.task_template.TaskTemplateResourceAggregatesResponse

Compute compact aggregates for a task template.

Aggregation runs entirely in MySQL: a single main query returns one row of stats + efficiency totals + outlier count, and a second query groups by task_resources_id for cluster breakdown. Avoids the previous 78K-row ship-to-Python pattern which was bottlenecked on row serialization (~10s for pixel).

Median / p95 for wallclock and maxrss are not computed server-side — percentiles don’t compose across GROUP BYs and running separate ORDER BY LIMIT OFFSET scans per column erodes the win. The frontend computes these client-side from the streaming viz rows instead, falling back to undefined on the initial paint.

When latest_only is True (the UI default), only the latest TaskInstance per Task is included, so the numbers match the latest-only scatter / table view.

get_task_template_details(workflow_id: int, task_template_id: int, task_template_version_id: int | None = None) jobmon.server.web.schemas.task_template.TaskTemplateDetailsResponse | None

Get task template details.

get_task_template_versions(task_id: int | None = None, workflow_id: int | None = None) jobmon.server.web.schemas.task_template.TaskTemplateVersionResponse | None

Get task template version IDs and names for a task or workflow.

Parameters:
  • task_id – Optional task ID to get task template version for

  • workflow_id – Optional workflow ID to get all task template versions for

Returns:

TaskTemplateVersionResponse with list of task template versions, or None if no data found.

Note

If both task_id and workflow_id are provided, task_id takes precedence.

get_requested_cores(task_template_version_ids: List[int]) jobmon.server.web.schemas.task_template.RequestedCoresResponse

Get the min, max, and avg of requested cores for task template versions.

Parameters:

task_template_version_ids – List of task template version IDs

Returns:

RequestedCoresResponse with core information for each task template version

Get the most popular queue for task template versions.

Parameters:

task_template_version_ids – List of task template version IDs

Returns:

MostPopularQueueResponse with queue information for each task template version

get_workflow_tt_status_viz(workflow_id: int, dialect: str = 'sqlite') Dict[int, jobmon.server.web.schemas.task_template.WorkflowTaskTemplateStatusItem]

Get the status of workflow task templates for GUI visualization.

Optimized version using single query with SQL aggregation instead of two separate queries and Python-level aggregation.

Parameters:
  • workflow_id – ID of the workflow

  • dialect – Database dialect for optimization hints

Returns:

Dictionary mapping task template ID to WorkflowTaskTemplateStatusItem

get_fatal_error_breakdown_for_tt(workflow_id: int, task_template_version_id: int, workflow_run_id: int | None = None) jobmon.server.web.schemas.task_template.FatalErrorBreakdownResponse

Classify fatal tasks for one template by last TI status.

Scoped to workflow + template for fast indexed lookup.

get_tt_error_log_viz(workflow_id: int, task_template_id: int, task_instance_id: int | None = None, page: int = 1, page_size: int = 10, recent_errors_only: bool = False, cluster_errors: bool = False, fatal_tasks_only: bool = False, workflow_run_id: int | None = None, task_template_version_id: int | None = None) jobmon.server.web.schemas.task_template.ErrorLogResponse

Get error logs for a task template ID for GUI visualization.

Parameters:
  • workflow_id – ID of the workflow

  • task_template_id – ID of the task template

  • task_instance_id – Optional specific task instance ID

  • page – Page number for pagination

  • page_size – Number of items per page

  • recent_errors_only – Whether to show only recent errors

  • cluster_errors – Whether to cluster similar errors

Returns:

ErrorLogResponse with paginated error log data