# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
"""Wrangle task proxies to manage the workflow."""
from collections import Counter
from contextlib import suppress
import json
import logging
from textwrap import indent
from typing import (
TYPE_CHECKING,
Dict,
Iterable,
List,
NamedTuple,
Optional,
Set,
Tuple,
Type,
Union,
)
from cylc.flow import LOG
from cylc.flow.cycling.loader import (
get_point,
standardise_point_string,
)
from cylc.flow.exceptions import (
PlatformLookupError,
PointParsingError,
WorkflowConfigError,
)
import cylc.flow.flags
from cylc.flow.flow_mgr import (
FLOW_NONE,
repr_flow_nums,
)
from cylc.flow.id import (
TaskTokens,
Tokens,
quick_relative_id,
)
from cylc.flow.id_match import id_match
from cylc.flow.platforms import get_platform
from cylc.flow.prerequisite import PrereqTuple
from cylc.flow.run_modes import RunMode
from cylc.flow.run_modes.skip import process_outputs as get_skip_mode_outputs
from cylc.flow.task_action_timer import (
TaskActionTimer,
TimerFlags,
)
from cylc.flow.task_events_mgr import (
CustomTaskEventHandlerContext,
EventKey,
TaskEventMailContext,
TaskJobLogsRetrieveContext,
)
from cylc.flow.task_id import TaskID
from cylc.flow.task_outputs import (
TASK_OUTPUT_EXPIRED,
TASK_OUTPUT_FAILED,
TASK_OUTPUT_SUBMIT_FAILED,
TASK_OUTPUT_SUCCEEDED,
)
from cylc.flow.task_proxy import TaskProxy
from cylc.flow.task_queues.independent import IndepQueueManager
from cylc.flow.task_state import (
TASK_STATUS_EXPIRED,
TASK_STATUS_FAILED,
TASK_STATUS_PREPARING,
TASK_STATUS_RUNNING,
TASK_STATUS_SUBMITTED,
TASK_STATUS_SUCCEEDED,
TASK_STATUS_WAITING,
TASK_STATUSES_ACTIVE,
TASK_STATUSES_FINAL,
status_geq,
)
from cylc.flow.task_trigger import TaskTrigger
from cylc.flow.util import deserialise_set
from cylc.flow.workflow_status import StopMode
from cylc.flow.scripts.set import XTRIGGER_PREREQ_PREFIX
if TYPE_CHECKING:
from cylc.flow.config import WorkflowConfig
from cylc.flow.cycling import (
IntervalBase,
PointBase,
)
from cylc.flow.data_store_mgr import DataStoreMgr
from cylc.flow.flow_mgr import (
FlowMgr,
FlowNums,
)
from cylc.flow.prerequisite import SatisfiedState
from cylc.flow.task_events_mgr import TaskEventsManager
from cylc.flow.taskdef import TaskDef
from cylc.flow.workflow_db_mgr import WorkflowDatabaseManager
from cylc.flow.xtrigger_mgr import XtriggerManager
Pool = Dict['PointBase', Dict[str, TaskProxy]]
def _get_xtrig_prereqs(
prereqs: 'Iterable[str]'
) -> 'Dict[str, bool]':
"""Extract xtriggers from user prerequisite input.
Weed out any task prerequisites.
Command validation has handled output suffixes and defaults.
Args:
prereqs: prerequisites and xtriggers in string form:
/: