Skip to content

Commit f7a9bc0

Browse files
authored
Merge pull request cylc#2523 from oliver-sanders/suicide-trigger-fix
Fix behaviour with multiple suicide triggers.
2 parents 7c019bd + 813f171 commit f7a9bc0

File tree

6 files changed

+108
-1
lines changed

6 files changed

+108
-1
lines changed

lib/cylc/task_pool.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ def remove_suiciding_tasks(self):
963963
num_removed = 0
964964
for itask in self.get_tasks():
965965
if itask.state.suicide_prerequisites:
966-
if itask.state.suicide_prerequisites_are_all_satisfied():
966+
if itask.state.suicide_prerequisites_satisfied():
967967
if itask.state.status in [TASK_STATUS_READY,
968968
TASK_STATUS_SUBMITTED,
969969
TASK_STATUS_RUNNING]:

lib/cylc/task_state.py

+6
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ def prerequisites_are_not_all_satisfied(self):
219219
return (not self.prerequisites_are_all_satisfied() or
220220
not self.suicide_prerequisites_are_all_satisfied())
221221

222+
def suicide_prerequisites_satisfied(self):
223+
"""Return True if any suicide prerequisites are satisfied."""
224+
if self._suicide_is_satisfied is True:
225+
return True
226+
return any(preq.is_satisfied() for preq in self.suicide_prerequisites)
227+
222228
def suicide_prerequisites_are_all_satisfied(self):
223229
"""Return True if all suicide prerequisites are satisfied."""
224230
if self._suicide_is_satisfied is None:

lib/cylc/task_trigger.py

+21
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ def get_point(self, point):
8888
self.cycle_point_offset, point)
8989
return point
9090

91+
def __str__(self):
92+
if self.abs_cycle_point:
93+
return '%s[%s]:%s' % (self.task_name, self.abs_cycle_point,
94+
self.output)
95+
elif self.cycle_point_offset:
96+
return '%s[%s]:%s' % (self.task_name, self.cycle_point_offset,
97+
self.output)
98+
else:
99+
return '%s:%s' % (self.task_name, self.output)
100+
91101
@staticmethod
92102
def get_trigger_name(trigger_name):
93103
"""Standardise a trigger name.
@@ -182,6 +192,17 @@ def get_expression(self, point):
182192
"""
183193
return ''.join(self._stringify_list(self._exp, point))
184194

195+
def __str__(self):
196+
ret = []
197+
if self.suicide:
198+
ret.append('!')
199+
for item in self._exp:
200+
if isinstance(item, list):
201+
ret.append(str(item))
202+
else:
203+
ret.append('( %s )' % str(item))
204+
return ' '.join(ret)
205+
185206
@classmethod
186207
def _stringify_list(cls, nested_expr, point):
187208
"""Stringify a nested list of TaskTrigger objects."""

tests/triggering/17-suicide-multi.t

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
# THIS FILE IS PART OF THE CYLC SUITE ENGINE.
3+
# Copyright (C) 2008-2017 NIWA
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
#-------------------------------------------------------------------------------
18+
# Test suicide triggering
19+
# (this is currently just a copy of the tutorial suicide example, but I
20+
# anticipate making it more fiendish at some point).
21+
. $(dirname $0)/test_header
22+
#-------------------------------------------------------------------------------
23+
set_test_number 2
24+
#-------------------------------------------------------------------------------
25+
install_suite $TEST_NAME_BASE suicide-multi
26+
#-------------------------------------------------------------------------------
27+
TEST_NAME=$TEST_NAME_BASE-validate
28+
run_ok $TEST_NAME cylc validate $SUITE_NAME
29+
#-------------------------------------------------------------------------------
30+
TEST_NAME=$TEST_NAME_BASE-run
31+
suite_run_ok $TEST_NAME cylc run --reference-test --debug --no-detach $SUITE_NAME
32+
#-------------------------------------------------------------------------------
33+
purge_suite $SUITE_NAME
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2017-12-27T14:42:10Z INFO - Initial point: 1
2+
2017-12-27T14:42:10Z INFO - Final point: 3
3+
2017-12-27T14:42:10Z INFO - [showdown.1] -triggered off []
4+
2017-12-27T14:42:13Z INFO - [ugly.1] -triggered off ['showdown.1']
5+
2017-12-27T14:42:16Z INFO - [fin.1] -triggered off ['ugly.1']
6+
2017-12-27T14:42:19Z INFO - [showdown.2] -triggered off ['fin.1']
7+
2017-12-27T14:42:22Z INFO - [bad.2] -triggered off ['showdown.2']
8+
2017-12-27T14:42:25Z INFO - [fin.2] -triggered off ['bad.2']
9+
2017-12-27T14:42:28Z INFO - [showdown.3] -triggered off ['fin.2']
10+
2017-12-27T14:42:32Z INFO - [good.3] -triggered off ['showdown.3']
11+
2017-12-27T14:42:35Z INFO - [fin.3] -triggered off ['good.3']
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[cylc]
2+
[[events]]
3+
timeout = PT1M
4+
5+
[scheduling]
6+
cycling mode = integer
7+
initial cycle point = 1
8+
final cycle point = 3
9+
[[dependencies]]
10+
[[[P1]]]
11+
graph = """
12+
fin[-P1] => showdown
13+
14+
showdown:good => good & ! bad & ! ugly
15+
showdown:bad => bad & ! good & ! ugly
16+
showdown:ugly => ugly & ! good & ! bad
17+
18+
good | bad | ugly => fin
19+
"""
20+
[runtime]
21+
[[root]]
22+
script = true
23+
[[showdown]]
24+
script = """
25+
if ! (( ${CYLC_TASK_CYCLE_POINT} % 3 )); then
26+
cylc message 'The-Good'
27+
elif ! (( ( ${CYLC_TASK_CYCLE_POINT} + 1 ) % 3 )); then
28+
cylc message 'The-Bad'
29+
else
30+
cylc message 'The-Ugly'
31+
fi
32+
"""
33+
[[[outputs]]]
34+
good = 'The-Good'
35+
bad = 'The-Bad'
36+
ugly = 'The-Ugly'

0 commit comments

Comments
 (0)