server.web.repositories.task_template_repository ================================================ .. py:module:: server.web.repositories.task_template_repository Attributes ---------- .. autoapisummary:: server.web.repositories.task_template_repository.logger Classes ------- .. autoapisummary:: server.web.repositories.task_template_repository.ResourceUsageStatistics server.web.repositories.task_template_repository.TaskTemplateRepository Module Contents --------------- .. py:data:: logger .. py:class:: ResourceUsageStatistics Clean data class for resource usage statistics. .. py:attribute:: num_tasks :type: Optional[int] :value: None .. py:attribute:: min_mem :type: Optional[int] :value: None .. py:attribute:: max_mem :type: Optional[int] :value: None .. py:attribute:: mean_mem :type: Optional[float] :value: None .. py:attribute:: min_runtime :type: Optional[int] :value: None .. py:attribute:: max_runtime :type: Optional[int] :value: None .. py:attribute:: mean_runtime :type: Optional[float] :value: None .. py:attribute:: median_mem :type: Optional[float] :value: None .. py:attribute:: median_runtime :type: Optional[float] :value: None .. py:attribute:: ci_mem :type: Optional[List[Union[float, None]]] :value: None .. py:attribute:: ci_runtime :type: Optional[List[Union[float, None]]] :value: None .. py:attribute:: viz_data :type: Optional[List[jobmon.server.web.schemas.task_template.TaskResourceVizItem]] :value: None .. py:class:: TaskTemplateRepository(session: sqlalchemy.orm.Session) Initialize the TaskTemplateRepository with a database session. .. py:attribute:: session .. py:method:: get_task_resource_details(task_template_version_id: int, workflows: Optional[List[int]], node_args: Optional[Dict[str, List[Any]]], limit: Optional[int] = 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. .. py:method:: calculate_resource_statistics(task_details: List[jobmon.server.web.schemas.task_template.TaskResourceDetailItem], confidence_interval: Optional[str] = None, task_template_version_id: Optional[int] = None) -> ResourceUsageStatistics Calculate statistics from task details using scipy.stats. .. py:method:: count_task_resource_details(task_template_version_id: int, workflows: Optional[List[int]], node_args: Optional[Dict[str, List[Any]]]) -> 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. .. py:method:: get_task_resource_aggregates(task_template_version_id: int, workflows: Optional[List[int]], node_args: Optional[Dict[str, List[Any]]] = 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. .. py:method:: get_task_template_details(workflow_id: int, task_template_id: int, task_template_version_id: Optional[int] = None) -> Optional[jobmon.server.web.schemas.task_template.TaskTemplateDetailsResponse] Get task template details. .. py:method:: get_task_template_versions(task_id: Optional[int] = None, workflow_id: Optional[int] = None) -> Optional[jobmon.server.web.schemas.task_template.TaskTemplateVersionResponse] Get task template version IDs and names for a task or workflow. :param task_id: Optional task ID to get task template version for :param 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. .. py:method:: 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. :param task_template_version_ids: List of task template version IDs :returns: RequestedCoresResponse with core information for each task template version .. py:method:: get_most_popular_queue(task_template_version_ids: List[int]) -> jobmon.server.web.schemas.task_template.MostPopularQueueResponse Get the most popular queue for task template versions. :param task_template_version_ids: List of task template version IDs :returns: MostPopularQueueResponse with queue information for each task template version .. py:method:: 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. :param workflow_id: ID of the workflow :param dialect: Database dialect for optimization hints :returns: Dictionary mapping task template ID to WorkflowTaskTemplateStatusItem .. py:method:: get_fatal_error_breakdown_for_tt(workflow_id: int, task_template_version_id: int, workflow_run_id: Optional[int] = 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. .. py:method:: get_tt_error_log_viz(workflow_id: int, task_template_id: int, task_instance_id: Optional[int] = 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: Optional[int] = None, task_template_version_id: Optional[int] = None) -> jobmon.server.web.schemas.task_template.ErrorLogResponse Get error logs for a task template ID for GUI visualization. :param workflow_id: ID of the workflow :param task_template_id: ID of the task template :param task_instance_id: Optional specific task instance ID :param page: Page number for pagination :param page_size: Number of items per page :param recent_errors_only: Whether to show only recent errors :param cluster_errors: Whether to cluster similar errors :returns: ErrorLogResponse with paginated error log data