/usr/lib/python2.7/dist-packages/cylc/taskdef.py is in python-cylc 7.6.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | #!/usr/bin/env python
# THIS FILE IS PART OF THE CYLC SUITE ENGINE.
# Copyright (C) 2008-2017 NIWA
#
# 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 <http://www.gnu.org/licenses/>.
"""Task definition."""
from collections import deque
from cylc.cycling.loader import (
get_point_relative, get_interval, is_offset_absolute)
from cylc.task_id import TaskID
class TaskDefError(Exception):
"""Exception raise for errors in TaskDef initialization."""
def __init__(self, msg):
Exception.__init__(self, msg)
self.msg = msg
def __str__(self):
return "ERROR: %s" % self.msg
class TaskDef(object):
"""Task definition."""
# Memory optimization - constrain possible attributes to this list.
__slots__ = [
"MAX_LEN_ELAPSED_TIMES", "run_mode", "rtconfig", "start_point",
"spawn_ahead", "sequences", "implicit_sequences",
"used_in_offset_trigger", "max_future_prereq_offset",
"intercycle_offsets", "sequential", "is_coldstart",
"suite_polling_cfg", "clocktrigger_offset", "expiration_offset",
"namespace_hierarchy", "dependencies", "outputs", "param_var",
"external_triggers", "name", "elapsed_times"]
# Store the elapsed times for a maximum of 10 cycles
MAX_LEN_ELAPSED_TIMES = 10
def __init__(self, name, rtcfg, run_mode, start_point, spawn_ahead):
if not TaskID.is_valid_name(name):
raise TaskDefError("Illegal task name: %s" % name)
self.run_mode = run_mode
self.rtconfig = rtcfg
self.start_point = start_point
self.spawn_ahead = spawn_ahead
self.sequences = []
self.implicit_sequences = [] # Implicit sequences are deprecated.
self.used_in_offset_trigger = False
# some defaults
self.max_future_prereq_offset = None
self.intercycle_offsets = set([])
self.sequential = False
self.suite_polling_cfg = {}
self.clocktrigger_offset = None
self.expiration_offset = None
self.namespace_hierarchy = []
self.dependencies = {}
self.outputs = []
self.param_var = {}
self.external_triggers = []
self.name = name
self.elapsed_times = deque(maxlen=self.MAX_LEN_ELAPSED_TIMES)
def add_dependency(self, dependency, sequence):
"""Add a dependency to a named sequence.
Args:
dependency (cylc.task_trigger.Dependency): The dependency to add.
sequence (cylc.cycling.SequenceBase): The sequence for which this
dependency applies.
"""
if sequence not in self.dependencies:
self.dependencies[sequence] = []
self.dependencies[sequence].append(dependency)
def add_sequence(self, sequence, is_implicit=False):
"""Add a sequence."""
if sequence not in self.sequences:
self.sequences.append(sequence)
if is_implicit:
self.implicit_sequences.append(sequence)
def describe(self):
"""Return title and description of the current task."""
info = {}
for item in 'title', 'description':
info[item] = self.rtconfig['meta'][item]
return info
def check_for_explicit_cycling(self):
"""Check for explicitly somewhere.
Must be called after all graph sequences added.
"""
if len(self.sequences) == 0 and self.used_in_offset_trigger:
raise TaskDefError(
"No cycling sequences defined for %s" % self.name)
@classmethod
def get_cleanup_cutoff_point(cls, my_point, offset_sequence_tuples):
"""Extract the max dependent cycle point for this point."""
if not offset_sequence_tuples:
# This task does not have dependent tasks at other cycles.
return my_point
cutoff_points = []
for offset_string, sequence in offset_sequence_tuples:
if offset_string is None:
# This indicates a dependency that lasts for the whole run.
return None
if sequence is None:
# This indicates a simple offset interval such as [-PT6H].
cutoff_points.append(
my_point - get_interval(offset_string))
continue
if is_offset_absolute(offset_string):
stop_point = sequence.get_stop_point()
if stop_point:
# Stop point of the sequence is a good cutoff point for an
# absolute "offset"
cutoff_points.append(stop_point)
continue
else:
# The dependency lasts for the whole run.
return None
# This is a complicated offset like [02T00-P1W].
dependent_point = sequence.get_start_point()
my_cutoff_point = None
while dependent_point is not None:
# TODO: Is it realistically possible to hang in this loop?
target_point = (
get_point_relative(offset_string, dependent_point))
if target_point > my_point:
# Assume monotonic (target_point can never jump back).
break
if target_point == my_point:
# We have found a dependent_point for my_point.
my_cutoff_point = dependent_point
dependent_point = sequence.get_next_point_on_sequence(
dependent_point)
if my_cutoff_point:
# Choose the largest of the dependent points.
cutoff_points.append(my_cutoff_point)
if cutoff_points:
max_cutoff_point = max(cutoff_points)
if max_cutoff_point < my_point:
# This is caused by future triggers - default to my_point.
return my_point
return max_cutoff_point
# There aren't any dependent tasks in other cycles for my_point.
return my_point
|