Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supply URLs to suite and task event handlers. #2276

Merged
merged 4 commits into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/src/cylc-user-guide/suiterc.tex
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ \subsection{[cylc]}
\begin{myitemize}
\item \%(event)s: event name (see below)
\item \%(suite)s: suite name
\item \%(suite_url)s: suite URL
\item \%(message)s: event message, if any
\end{myitemize}

Expand Down Expand Up @@ -1546,6 +1547,8 @@ \subsection{[runtime]}
\item \%(suite)s: suite name
\item \%(point)s: cycle point
\item \%(name)s: task name
\item \%(suite_url)s: suite url
\item \%(task_url)s: task url
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be URL (ALL CAPS), to be consistent with line 304 above.

\item \%(submit\_num)s: submit number
\item \%(id)s: task ID (i.e. \%(name)s.\%(point)s)
\item \%(message)s: event message, if any
Expand Down
3 changes: 3 additions & 0 deletions lib/cylc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from parsec.OrderedDict import OrderedDictWithDefaults
from parsec.util import replicate
from cylc.suite_logging import OUT, ERR
from cylc.task_proxy import TaskProxy


RE_SUITE_NAME_VAR = re.compile('\${?CYLC_SUITE_(REG_)?NAME}?')
Expand Down Expand Up @@ -757,6 +758,8 @@ def __init__(self, suite, fpath, template_vars=None,
'(graph the suite to see back-edges).')

self.mem_log("config.py: end init config")
TaskProxy.suite_name = self.suite
TaskProxy.suite_url = self.cfg['URL']

def _expand_name_list(self, orig_names):
"""Expand any parameters in lists of names."""
Expand Down
1 change: 1 addition & 0 deletions lib/cylc/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,7 @@ def _run_event_custom_handlers(self, event, message):
'event': quote(event),
'suite': quote(self.suite),
'message': quote(message),
'suite_url': quote(self.config.cfg['URL'])
}
if cmd == handler:
# Nothing substituted, assume classic interface
Expand Down
24 changes: 14 additions & 10 deletions lib/cylc/task_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class TaskProxy(object):
"is_manual_submit", "summary", "local_job_file_path",
"retries_configured", "try_timers",
"event_handler_try_timers", "db_inserts_map",
"db_updates_map", "suite_name", "task_host", "task_owner",
"db_updates_map", "task_host", "task_owner",
"job_vacated", "poll_timers", "event_hooks",
"delayed_start_str", "delayed_start", "expire_time_str",
"expire_time", "state"]
Expand Down Expand Up @@ -231,6 +231,10 @@ class TaskProxy(object):

stop_sim_mode_job_submission = False

# Updated during config parsing:
suite_name = None
suite_url = None

def __init__(
self, tdef, start_point, status=TASK_STATUS_WAITING,
hold_swap=None, has_spawned=False, stop_point=None,
Expand Down Expand Up @@ -316,9 +320,6 @@ def __init__(
self.TABLE_TASK_STATES: [],
}

# TODO - should take suite name from config!
self.suite_name = os.environ['CYLC_SUITE_NAME']
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to be an instance variable, and this was an insane way of getting the suite name.


# In case task owner and host are needed by db_events_insert()
# for pre-submission events, set their initial values as if
# local (we can't know the correct host prior to this because
Expand Down Expand Up @@ -789,17 +790,20 @@ def setup_custom_event_handlers(self, event, message, only_list=None):
continue
cmd = handler % {
"event": quote(event),
"suite": quote(self.suite_name),
"suite": quote(self.__class__.suite_name),
"point": quote(str(self.point)),
"name": quote(self.tdef.name),
"submit_num": self.submit_num,
"id": quote(self.identity),
"task_url": quote(self.tdef.rtconfig['URL']),
"suite_url": quote(self.__class__.suite_url),
"message": quote(message),
}
if cmd == handler:
# Nothing substituted, assume classic interface
cmd = "%s '%s' '%s' '%s' '%s'" % (
handler, event, self.suite_name, self.identity, message)
handler, event, self.__class__.suite_name,
self.identity, message)
self.log(DEBUG, "Queueing %s handler: %s" % (event, cmd))
self.event_handler_try_timers[(key1, self.submit_num)] = (
TaskActionTimer(
Expand Down Expand Up @@ -1121,7 +1125,7 @@ def _prep_submit_impl(self, overrides=None):

if self.tdef.run_mode != 'simulation':
RemoteJobHostManager.get_inst().init_suite_run_dir(
self.suite_name, self.task_host, self.task_owner)
self.__class__.suite_name, self.task_host, self.task_owner)
self.db_updates_map[self.TABLE_TASK_JOBS].append({
"user_at_host": user_at_host,
"batch_sys_name": self.summary['batch_sys_name'],
Expand Down Expand Up @@ -1158,7 +1162,7 @@ def _prep_submit_impl(self, overrides=None):
'remote_suite_d': rtconfig['remote']['suite definition directory'],
'shell': rtconfig['job']['shell'],
'submit_num': self.submit_num,
'suite_name': self.suite_name,
'suite_name': self.__class__.suite_name,
'task_id': self.identity,
'try_num': self.try_timers[self.KEY_EXECUTE].num + 1,
'work_d': rtconfig['work sub-directory'],
Expand Down Expand Up @@ -1522,10 +1526,10 @@ def get_job_log_path(self, head_mode=None, submit_num=None, tail=None):
args.append(submit_num)
if head_mode == self.HEAD_MODE_LOCAL:
args.insert(0, GLOBAL_CFG.get_derived_host_item(
self.suite_name, "suite job log directory"))
self.__class__.suite_name, "suite job log directory"))
elif head_mode == self.HEAD_MODE_REMOTE:
args.insert(0, GLOBAL_CFG.get_derived_host_item(
self.suite_name, 'suite job log directory',
self.__class__.suite_name, 'suite job log directory',
self.task_host, self.task_owner))
if tail:
args.append(tail)
Expand Down
12 changes: 7 additions & 5 deletions tests/events/08-task-event-handler-retry.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ OPT_SET=
if [[ "${TEST_NAME_BASE}" == *-globalcfg ]]; then
create_test_globalrc "" "
[task events]
handlers=hello-event-handler '%(name)s' '%(event)s'
handlers = hello-event-handler %(name)s %(event)s %(suite_url)s %(task_url)s %(message)s %(point)s %(submit_num)s %(id)s
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well test all possible args.

handler events=succeeded, failed
handler retry delays=PT0S, 2*PT1S"
OPT_SET='-s GLOBALCFG=True'
Expand All @@ -33,15 +33,17 @@ run_ok "${TEST_NAME_BASE}-validate" cylc validate ${OPT_SET} "${SUITE_NAME}"
suite_run_ok "${TEST_NAME_BASE}-run" \
cylc run --reference-test --debug ${OPT_SET} "${SUITE_NAME}"

SUITE_URL=http://my-suites.com/${SUITE_NAME}.html
TASK_URL=http://my-suites.com/${SUITE_NAME}/t1.html
LOG="${SUITE_RUN_DIR}/log/job/1/t1/NN/job-activity.log"
sed "/(('event-handler-00', 'succeeded'), 1)/!d; s/^.* \[/[/" "${LOG}" \
>'edited-job-activity.log'
cmp_ok 'edited-job-activity.log' <<'__LOG__'
[(('event-handler-00', 'succeeded'), 1) cmd] hello-event-handler 't1' 'succeeded'
cmp_ok 'edited-job-activity.log' <<__LOG__
[(('event-handler-00', 'succeeded'), 1) cmd] hello-event-handler t1 succeeded ${SUITE_URL} ${TASK_URL} 'job succeeded' 1 1 t1.1
[(('event-handler-00', 'succeeded'), 1) ret_code] 1
[(('event-handler-00', 'succeeded'), 1) cmd] hello-event-handler 't1' 'succeeded'
[(('event-handler-00', 'succeeded'), 1) cmd] hello-event-handler t1 succeeded ${SUITE_URL} ${TASK_URL} 'job succeeded' 1 1 t1.1
[(('event-handler-00', 'succeeded'), 1) ret_code] 1
[(('event-handler-00', 'succeeded'), 1) cmd] hello-event-handler 't1' 'succeeded'
[(('event-handler-00', 'succeeded'), 1) cmd] hello-event-handler t1 succeeded ${SUITE_URL} ${TASK_URL} 'job succeeded' 1 1 t1.1
[(('event-handler-00', 'succeeded'), 1) ret_code] 0
[(('event-handler-00', 'succeeded'), 1) out] hello
__LOG__
Expand Down
4 changes: 3 additions & 1 deletion tests/events/08-task-event-handler-retry/suite.rc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!jinja2

title=Task Event Handler Retry
URL = http://my-suites.com/${CYLC_SUITE_NAME}.html

[cylc]
[[reference test]]
Expand All @@ -12,14 +13,15 @@ title=Task Event Handler Retry

[runtime]
[[t1]]
URL = http://my-suites.com/${CYLC_SUITE_NAME}/${CYLC_TASK_NAME}.html
script=true
{% if HOST is defined %}
[[[remote]]]
host = {{HOST}}
{% endif %}
{% if GLOBALCFG is not defined %}
[[[events]]]
handlers=hello-event-handler '%(name)s' '%(event)s'
handlers = hello-event-handler %(name)s %(event)s %(suite_url)s %(task_url)s %(message)s %(point)s %(submit_num)s %(id)s
handler events=succeeded, failed
handler retry delays=PT0S, 2*PT1S
{% endif %}{# not GLOBALCFG is not defined #}
Expand Down
4 changes: 2 additions & 2 deletions tests/events/20-suite-event-handlers.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if [[ "${TEST_NAME_BASE}" == *-globalcfg ]]; then
create_test_globalrc "" "
[cylc]
[[events]]
handlers = echo 'Your %(suite)s suite has a %(event)s event.'
handlers = echo 'Your %(suite)s suite has a %(event)s event and URL %(suite_url)s.'
handler events = startup"
OPT_SET='-s GLOBALCFG=True'
fi
Expand All @@ -36,7 +36,7 @@ suite_run_ok "${TEST_NAME_BASE}-run" \

LOG_FILE="$(cylc get-global-config --print-run-dir)/${SUITE_NAME}/log/suite/log"
grep_ok "\\[('suite-event-handler-00', 'startup') ret_code\\] 0" "${LOG_FILE}"
grep_ok "\\[('suite-event-handler-00', 'startup') out\\] Your ${SUITE_NAME} suite has a startup event." "${LOG_FILE}"
grep_ok "\\[('suite-event-handler-00', 'startup') out\\] Your ${SUITE_NAME} suite has a startup event and URL http://mysuites.com/${SUITE_NAME}.html." "${LOG_FILE}"

purge_suite "${SUITE_NAME}"
exit
3 changes: 2 additions & 1 deletion tests/events/20-suite-event-handlers/suite.rc
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!jinja2

title=Suite Event Mail
URL = http://mysuites.com/${CYLC_SUITE_NAME}.html

[cylc]
[[events]]
{% if GLOBALCFG is not defined %}
handlers = echo 'Your %(suite)s suite has a %(event)s event.'
handlers = echo 'Your %(suite)s suite has a %(event)s event and URL %(suite_url)s.'
handler events = startup
{% endif %}{# not GLOBALCFG is not defined #}
[[reference test]]
Expand Down