-
Notifications
You must be signed in to change notification settings - Fork 94
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
External trigger "plugin" functions. #2423
Changes from 12 commits
c62e952
7c879b7
e94dd87
6985909
69b9c74
1d0bb4c
4f5ed67
cc2e879
4e20ec9
1e12993
7fc05e4
f0f438b
a4e0fa4
c32357c
e6c1fbd
e00eedc
af12334
b35f458
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,9 +44,11 @@ import cylc.flags | |
from cylc.mp_pool import SuiteProcPool | ||
from cylc.option_parsers import CylcOptionParser as COP | ||
from cylc.suite_db_mgr import SuiteDatabaseManager | ||
from cylc.broadcast_mgr import BroadcastMgr | ||
from cylc.suite_srv_files_mgr import SuiteSrvFilesManager | ||
from cylc.task_id import TaskID | ||
from cylc.task_job_mgr import TaskJobManager | ||
from cylc.task_events_mgr import TaskEventsManager | ||
from cylc.task_proxy import TaskProxy | ||
from cylc.task_state import TASK_STATUS_SUBMIT_FAILED | ||
from cylc.templatevars import load_template_vars | ||
|
@@ -101,8 +103,11 @@ def main(): | |
|
||
# Initialise job submit environment | ||
glbl_cfg().create_cylc_run_tree(suite) | ||
task_job_mgr = TaskJobManager( | ||
suite, SuiteProcPool(), SuiteDatabaseManager(), suite_srv_mgr) | ||
pool = SuiteProcPool() | ||
db_mgr = SuiteDatabaseManager() | ||
b_mgr = BroadcastMgr(db_mgr) | ||
te_mgr = TaskEventsManager(suite, pool, db_mgr, b_mgr) | ||
task_job_mgr = TaskJobManager(suite, pool, db_mgr, suite_srv_mgr, te_mgr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this change still necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean exactly by "this change"? Oh, maybe just that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
task_job_mgr.task_remote_mgr.single_task_mode = True | ||
task_job_mgr.job_file_writer.set_suite_env({ | ||
'CYLC_UTC': str(config.cfg['cylc']['UTC mode']), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python2 | ||
|
||
# THIS FILE IS PART OF THE CYLC SUITE ENGINE. | ||
# Copyright (C) 2008-2018 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/>. | ||
""" | ||
INTERNAL USE (asynchronous xtrigger function execution). | ||
|
||
USAGE: cylc wrap-func <func-name> <'json-func-args'> <'json-func-kwargs'> | ||
|
||
Run "func-name(*func-args, **func-kwargs)" in the command process pool. | ||
|
||
The function must be defined in a module of the same name (func-name). | ||
|
||
The function's stdout is redirected to stderr, and visible in suite log in | ||
debug mode. Its return value is printed to stdout as a JSON string. | ||
""" | ||
|
||
# Function return value to stdout: for compat with the command process pool. | ||
|
||
import importlib | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused import? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you forgot to fetch my updates. This command has changed name to |
||
import json | ||
import sys | ||
from cylc.xtrigger_mgr import get_func | ||
|
||
|
||
def run_func(func_name, func_args, func_kwargs): | ||
func = get_func(func_name) | ||
# Redirect stdout to stderr. | ||
orig_stdout = sys.stdout | ||
sys.stdout = sys.stderr | ||
res = func(*func_args, **func_kwargs) | ||
# Restore stdout. | ||
sys.stdout = orig_stdout | ||
# Write function return value as JSON to stdout. | ||
sys.stdout.write(json.dumps(res)) | ||
|
||
|
||
if __name__ == "__main__": | ||
if sys.argv[1] in ['help', '--help']: | ||
print __doc__ | ||
sys.exit(0) | ||
func_name = sys.argv[1] | ||
func_args = json.loads(sys.argv[2]) | ||
func_kwargs = json.loads(sys.argv[3]) | ||
run_func(func_name, func_args, func_kwargs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be good to move the json-load => call function => json-dump logic to a location under There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could do (pref "for the future" as I haven't time to look at JSON-RPC right now) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've taken your advice on move into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More like
call-func
thanwrap-func
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, "call" suggests a normal function call, doesn't it? This wraps a function into a minimal executable program, to execute in the process pool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to
function-run
- less ambiguous, and no abbrev similarity to other commands (cylc warranty
was a problem withwrap-func
; andcylc run-func
is a no-go thanks tocylc run
).