Debian Codegraph @

cylc/flow/scripts/pause.py

raw
1 #!/usr/bin/env python3
2
3 # THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
4 # Copyright (C) NIWA & British Crown (Met Office) & Contributors.
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 """cylc pause [OPTIONS] ARGS
20
21 Suspend automatic job submission.
22
23 Manual triggering can still run tasks immediately, even if the workflow is
24 paused.
25
26 Examples:
27 # pause my_workflow
28 $ cylc pause my_workflow
29
30 # resume my_workflow
31 $ cylc play my_workflow
32
33 (Not to be confused with `cylc hold` which suspends submission of individual
34 tasks within a workflow).
35 """
36
37 from functools import partial
38 from typing import TYPE_CHECKING
39 import sys
40
41 from cylc.flow.option_parsers import (
42 WORKFLOW_ID_MULTI_ARG_DOC,
43 CylcOptionParser as COP,
44 )
45 from cylc.flow.network.client import WorkflowRuntimeClient
46 from cylc.flow.network.multi import call_multi
47 from cylc.flow.terminal import cli_function
48
49 if TYPE_CHECKING:
50 from optparse import Values
51
52
53 MUTATION = '''
54 mutation (
55 $wFlows: [WorkflowID]!
56 ) {
57 pause (
58 workflows: $wFlows
59 ) {
60 result
61 }
62 }
63 '''
64
65
66 def get_option_parser() -> COP:
67 parser = COP(
68 __doc__,
69 comms=True,
70 multitask=False,
71 multiworkflow=True,
72 argdoc=[WORKFLOW_ID_MULTI_ARG_DOC],
73 )
74 return parser
75
76
77 async def run(options: 'Values', workflow_id: str):
78 pclient = WorkflowRuntimeClient(workflow_id, timeout=options.comms_timeout)
79
80 mutation_kwargs = {
81 'request_string': MUTATION,
82 'variables': {
83 'wFlows': [workflow_id],
84 }
85 }
86
87 return await pclient.async_request('graphql', mutation_kwargs)
88
89
90 @cli_function(get_option_parser)
91 def main(parser: COP, options: 'Values', *ids) -> None:
92 rets = call_multi(
93 partial(run, options),
94 *ids,
95 constraint='workflows',
96 )
97 sys.exit(all(rets.values()) is False)