meerschaum 2.3.0.dev1__py3-none-any.whl → 2.3.0rc1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- meerschaum/__init__.py +5 -2
- meerschaum/__main__.py +0 -5
- meerschaum/_internal/arguments/_parse_arguments.py +10 -3
- meerschaum/_internal/arguments/_parser.py +6 -2
- meerschaum/_internal/entry.py +36 -6
- meerschaum/_internal/shell/Shell.py +32 -20
- meerschaum/actions/__init__.py +8 -6
- meerschaum/actions/attach.py +31 -13
- meerschaum/actions/copy.py +68 -41
- meerschaum/actions/delete.py +64 -21
- meerschaum/actions/edit.py +3 -3
- meerschaum/actions/install.py +40 -32
- meerschaum/actions/pause.py +44 -27
- meerschaum/actions/restart.py +107 -0
- meerschaum/actions/show.py +8 -8
- meerschaum/actions/start.py +26 -41
- meerschaum/actions/stop.py +11 -4
- meerschaum/api/_events.py +10 -3
- meerschaum/api/dash/jobs.py +69 -70
- meerschaum/api/routes/_actions.py +8 -3
- meerschaum/api/routes/_jobs.py +86 -37
- meerschaum/config/_default.py +1 -1
- meerschaum/config/_paths.py +5 -0
- meerschaum/config/_shell.py +1 -1
- meerschaum/config/_version.py +1 -1
- meerschaum/config/static/__init__.py +6 -1
- meerschaum/connectors/Connector.py +13 -7
- meerschaum/connectors/__init__.py +21 -5
- meerschaum/connectors/api/APIConnector.py +3 -0
- meerschaum/connectors/api/_jobs.py +108 -11
- meerschaum/connectors/parse.py +10 -13
- meerschaum/core/Pipe/_bootstrap.py +16 -8
- meerschaum/jobs/_Executor.py +69 -0
- meerschaum/{utils/jobs → jobs}/_Job.py +206 -40
- meerschaum/jobs/_LocalExecutor.py +88 -0
- meerschaum/jobs/_SystemdExecutor.py +608 -0
- meerschaum/jobs/__init__.py +365 -0
- meerschaum/plugins/__init__.py +6 -6
- meerschaum/utils/daemon/Daemon.py +7 -0
- meerschaum/utils/daemon/RotatingFile.py +5 -2
- meerschaum/utils/daemon/StdinFile.py +12 -2
- meerschaum/utils/daemon/__init__.py +2 -0
- meerschaum/utils/formatting/_jobs.py +52 -16
- meerschaum/utils/misc.py +23 -5
- meerschaum/utils/packages/_packages.py +7 -4
- meerschaum/utils/process.py +9 -9
- meerschaum/utils/venv/__init__.py +2 -2
- {meerschaum-2.3.0.dev1.dist-info → meerschaum-2.3.0rc1.dist-info}/METADATA +14 -17
- {meerschaum-2.3.0.dev1.dist-info → meerschaum-2.3.0rc1.dist-info}/RECORD +55 -51
- meerschaum/utils/jobs/__init__.py +0 -245
- {meerschaum-2.3.0.dev1.dist-info → meerschaum-2.3.0rc1.dist-info}/LICENSE +0 -0
- {meerschaum-2.3.0.dev1.dist-info → meerschaum-2.3.0rc1.dist-info}/NOTICE +0 -0
- {meerschaum-2.3.0.dev1.dist-info → meerschaum-2.3.0rc1.dist-info}/WHEEL +0 -0
- {meerschaum-2.3.0.dev1.dist-info → meerschaum-2.3.0rc1.dist-info}/entry_points.txt +0 -0
- {meerschaum-2.3.0.dev1.dist-info → meerschaum-2.3.0rc1.dist-info}/top_level.txt +0 -0
- {meerschaum-2.3.0.dev1.dist-info → meerschaum-2.3.0rc1.dist-info}/zip-safe +0 -0
meerschaum/actions/delete.py
CHANGED
@@ -10,9 +10,9 @@ from __future__ import annotations
|
|
10
10
|
from meerschaum.utils.typing import Any, SuccessTuple, Union, Optional, List
|
11
11
|
|
12
12
|
def delete(
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
action: Optional[List[str]] = None,
|
14
|
+
**kw: Any
|
15
|
+
) -> SuccessTuple:
|
16
16
|
"""
|
17
17
|
Delete an element.
|
18
18
|
|
@@ -35,23 +35,21 @@ def delete(
|
|
35
35
|
|
36
36
|
|
37
37
|
def _complete_delete(
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
action: Optional[List[str]] = None,
|
39
|
+
**kw: Any
|
40
|
+
) -> List[str]:
|
41
41
|
"""
|
42
42
|
Override the default Meerschaum `complete_` function.
|
43
|
-
|
44
43
|
"""
|
45
|
-
from meerschaum.actions.start import _complete_start_jobs
|
46
44
|
from meerschaum.actions.edit import _complete_edit_config
|
47
45
|
if action is None:
|
48
46
|
action = []
|
49
47
|
options = {
|
50
48
|
'connector': _complete_delete_connectors,
|
51
49
|
'connectors': _complete_delete_connectors,
|
52
|
-
'config'
|
53
|
-
'job'
|
54
|
-
'jobs'
|
50
|
+
'config': _complete_edit_config,
|
51
|
+
'job': _complete_delete_jobs,
|
52
|
+
'jobs': _complete_delete_jobs,
|
55
53
|
}
|
56
54
|
|
57
55
|
if (
|
@@ -390,22 +388,22 @@ def _complete_delete_connectors(
|
|
390
388
|
|
391
389
|
|
392
390
|
def _delete_jobs(
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
391
|
+
action: Optional[List[str]] = None,
|
392
|
+
executor_keys: Optional[str] = None,
|
393
|
+
noask: bool = False,
|
394
|
+
nopretty: bool = False,
|
395
|
+
force: bool = False,
|
396
|
+
yes: bool = False,
|
397
|
+
debug: bool = False,
|
398
|
+
**kw
|
399
|
+
) -> SuccessTuple:
|
402
400
|
"""
|
403
401
|
Remove a job's log files and delete the job's ID.
|
404
402
|
|
405
403
|
If the job is running, ask to kill the job first.
|
406
404
|
|
407
405
|
"""
|
408
|
-
from meerschaum.
|
406
|
+
from meerschaum.jobs import (
|
409
407
|
Job,
|
410
408
|
get_running_jobs,
|
411
409
|
get_stopped_jobs,
|
@@ -496,6 +494,51 @@ def _delete_jobs(
|
|
496
494
|
)
|
497
495
|
|
498
496
|
|
497
|
+
def _complete_delete_jobs(
|
498
|
+
action: Optional[List[str]] = None,
|
499
|
+
executor_keys: Optional[str] = None,
|
500
|
+
line: str = '',
|
501
|
+
_get_job_method: Optional[str, List[str]] = None,
|
502
|
+
**kw
|
503
|
+
) -> List[str]:
|
504
|
+
from meerschaum._internal.shell.Shell import shell_attrs
|
505
|
+
from meerschaum.jobs import (
|
506
|
+
get_jobs,
|
507
|
+
get_filtered_jobs,
|
508
|
+
get_restart_jobs,
|
509
|
+
get_stopped_jobs,
|
510
|
+
get_paused_jobs,
|
511
|
+
get_running_jobs,
|
512
|
+
)
|
513
|
+
from meerschaum.utils.misc import remove_ansi
|
514
|
+
|
515
|
+
executor_keys = executor_keys or remove_ansi(shell_attrs.get('executor_keys', 'local'))
|
516
|
+
|
517
|
+
jobs = get_jobs(executor_keys)
|
518
|
+
if _get_job_method:
|
519
|
+
method_keys = [_get_job_method] if isinstance(_get_job_method, str) else _get_job_method
|
520
|
+
method_jobs = {}
|
521
|
+
for method_key in method_keys:
|
522
|
+
method_func = locals()[f'get_{method_key}_jobs']
|
523
|
+
method_jobs.update(method_func(jobs=jobs))
|
524
|
+
jobs = method_jobs
|
525
|
+
|
526
|
+
if not action:
|
527
|
+
return list(jobs)
|
528
|
+
|
529
|
+
possibilities = []
|
530
|
+
_line_end = line.split(' ')[-1]
|
531
|
+
for name in jobs:
|
532
|
+
if name in action:
|
533
|
+
continue
|
534
|
+
if _line_end == '':
|
535
|
+
possibilities.append(name)
|
536
|
+
continue
|
537
|
+
if name.startswith(action[-1]):
|
538
|
+
possibilities.append(name)
|
539
|
+
return possibilities
|
540
|
+
|
541
|
+
|
499
542
|
def _delete_venvs(
|
500
543
|
action: Optional[List[str]] = None,
|
501
544
|
yes: bool = False,
|
meerschaum/actions/edit.py
CHANGED
@@ -11,9 +11,9 @@ import meerschaum as mrsm
|
|
11
11
|
from meerschaum.utils.typing import List, Any, SuccessTuple, Optional, Dict
|
12
12
|
|
13
13
|
def edit(
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
action: Optional[List[str]] = None,
|
15
|
+
**kw: Any
|
16
|
+
) -> SuccessTuple:
|
17
17
|
"""
|
18
18
|
Edit an existing element.
|
19
19
|
"""
|
meerschaum/actions/install.py
CHANGED
@@ -10,9 +10,9 @@ from __future__ import annotations
|
|
10
10
|
from meerschaum.utils.typing import List, Any, SuccessTuple, Optional, Union
|
11
11
|
|
12
12
|
def install(
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
action: Optional[List[str]] = None,
|
14
|
+
**kw: Any
|
15
|
+
) -> SuccessTuple:
|
16
16
|
"""
|
17
17
|
Install Meerschaum plugins or Python packages.
|
18
18
|
"""
|
@@ -26,9 +26,9 @@ def install(
|
|
26
26
|
|
27
27
|
|
28
28
|
def _complete_install(
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
action: Optional[List[str]] = None,
|
30
|
+
**kw: Any
|
31
|
+
) -> List[str]:
|
32
32
|
"""
|
33
33
|
Override the default Meerschaum `complete_` function.
|
34
34
|
"""
|
@@ -52,13 +52,13 @@ def _complete_install(
|
|
52
52
|
|
53
53
|
|
54
54
|
def _install_plugins(
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
55
|
+
action: Optional[List[str]] = None,
|
56
|
+
repository: Optional[str] = None,
|
57
|
+
skip_deps: bool = False,
|
58
|
+
force: bool = False,
|
59
|
+
debug: bool = False,
|
60
|
+
**kw: Any
|
61
|
+
) -> SuccessTuple:
|
62
62
|
"""
|
63
63
|
Install a plugin.
|
64
64
|
|
@@ -103,10 +103,10 @@ def _install_plugins(
|
|
103
103
|
|
104
104
|
|
105
105
|
def _complete_install_plugins(
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
106
|
+
action: Optional[List[str]] = None,
|
107
|
+
repository: Optional[str] = None,
|
108
|
+
**kw: Any
|
109
|
+
) -> List[str]:
|
110
110
|
"""
|
111
111
|
Search for plugins to autocomplete command line text.
|
112
112
|
NOTE: Disabled for the time being so we don't interrupt the user typing.
|
@@ -143,12 +143,12 @@ class NoVenv:
|
|
143
143
|
pass
|
144
144
|
|
145
145
|
def _install_packages(
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
146
|
+
action: Optional[List[str]] = None,
|
147
|
+
sub_args: Optional[List[str]] = None,
|
148
|
+
venv: Union[str, NoVenv] = NoVenv,
|
149
|
+
debug: bool = False,
|
150
|
+
**kw: Any
|
151
|
+
) -> SuccessTuple:
|
152
152
|
"""
|
153
153
|
Install PyPI packages into the Meerschaum virtual environment.
|
154
154
|
|
@@ -179,19 +179,17 @@ def _install_packages(
|
|
179
179
|
)
|
180
180
|
|
181
181
|
|
182
|
-
def _complete_install_packages(
|
183
|
-
**kw : Any
|
184
|
-
) -> List[str]:
|
182
|
+
def _complete_install_packages(**kw : Any) -> List[str]:
|
185
183
|
return []
|
186
184
|
|
187
185
|
|
188
186
|
def _install_required(
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
187
|
+
action: Optional[List[str]] = None,
|
188
|
+
repository: Optional[str] = None,
|
189
|
+
force: bool = False,
|
190
|
+
debug: bool = False,
|
191
|
+
**kw
|
192
|
+
) -> SuccessTuple:
|
195
193
|
"""
|
196
194
|
Install the required packages for Meerschaum plugins.
|
197
195
|
Each plugin's packages will be installed into its virtual environment.
|
@@ -237,6 +235,16 @@ def _complete_install_required(*args, **kw) -> List[str]:
|
|
237
235
|
return _complete_uninstall_plugins(*args, **kw)
|
238
236
|
|
239
237
|
|
238
|
+
def _install_systemd(
|
239
|
+
action: Optional[List[str]] = None,
|
240
|
+
**kwargs: Any
|
241
|
+
) -> SuccessTuple:
|
242
|
+
"""
|
243
|
+
Install the Meerschaum job monitor as a systemd service.
|
244
|
+
"""
|
245
|
+
import sys
|
246
|
+
|
247
|
+
|
240
248
|
### NOTE: This must be the final statement of the module.
|
241
249
|
### Any subactions added below these lines will not
|
242
250
|
### be added to the `help` docstring.
|
meerschaum/actions/pause.py
CHANGED
@@ -27,13 +27,20 @@ def _complete_pause(
|
|
27
27
|
"""
|
28
28
|
Override the default Meerschaum `complete_` function.
|
29
29
|
"""
|
30
|
-
from meerschaum.actions.
|
30
|
+
from meerschaum.actions.delete import _complete_delete_jobs
|
31
|
+
from functools import partial
|
32
|
+
|
31
33
|
if action is None:
|
32
34
|
action = []
|
33
35
|
|
36
|
+
_complete_pause_jobs = partial(
|
37
|
+
_complete_delete_jobs,
|
38
|
+
_get_job_method='running',
|
39
|
+
)
|
40
|
+
|
34
41
|
options = {
|
35
|
-
'job'
|
36
|
-
'jobs'
|
42
|
+
'job': _complete_pause_jobs,
|
43
|
+
'jobs': _complete_pause_jobs,
|
37
44
|
}
|
38
45
|
|
39
46
|
if (
|
@@ -49,43 +56,53 @@ def _complete_pause(
|
|
49
56
|
|
50
57
|
|
51
58
|
def _pause_jobs(
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
+
action: Optional[List[str]] = None,
|
60
|
+
executor_keys: Optional[str] = None,
|
61
|
+
noask: bool = False,
|
62
|
+
force: bool = False,
|
63
|
+
yes: bool = False,
|
64
|
+
nopretty: bool = False,
|
65
|
+
debug: bool = False,
|
66
|
+
**kw
|
67
|
+
) -> SuccessTuple:
|
59
68
|
"""
|
60
|
-
Pause running jobs
|
61
|
-
|
62
|
-
To see running jobs, run `show jobs`.
|
69
|
+
Pause (suspend) running jobs.
|
63
70
|
"""
|
64
71
|
from meerschaum.utils.formatting._jobs import pprint_jobs
|
65
72
|
from meerschaum.utils.daemon import (
|
66
73
|
get_filtered_daemons, get_running_daemons, get_stopped_daemons, get_paused_daemons,
|
67
74
|
)
|
75
|
+
from meerschaum.jobs import (
|
76
|
+
get_filtered_jobs,
|
77
|
+
get_running_jobs,
|
78
|
+
get_stopped_jobs,
|
79
|
+
get_paused_jobs,
|
80
|
+
)
|
68
81
|
from meerschaum.utils.warnings import warn
|
69
82
|
from meerschaum.utils.prompt import yes_no
|
70
83
|
from meerschaum.utils.misc import items_str
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
84
|
+
|
85
|
+
jobs = get_filtered_jobs(executor_keys, action, debug=debug, warn=(not nopretty))
|
86
|
+
running_jobs = get_running_jobs(executor_keys, jobs, debug=debug)
|
87
|
+
paused_jobs = get_paused_jobs(executor_keys, jobs, debug=debug)
|
88
|
+
stopped_jobs = get_stopped_jobs(executor_keys, jobs, debug=debug)
|
89
|
+
|
90
|
+
if action and stopped_jobs and not nopretty:
|
76
91
|
warn(
|
77
|
-
f"Skipping stopped job" + ("s" if len(
|
78
|
-
|
79
|
-
|
92
|
+
f"Skipping stopped job" + ("s" if len(stopped_jobs) > 1 else '')
|
93
|
+
+ " '"
|
94
|
+
+ ("', '".join(stopped_jobs.keys()))
|
95
|
+
+ "'.",
|
96
|
+
stack=False,
|
80
97
|
)
|
81
98
|
|
82
|
-
|
83
|
-
if not
|
99
|
+
jobs_to_pause = {**running_jobs, **paused_jobs}
|
100
|
+
if not jobs_to_pause:
|
84
101
|
return False, "No running jobs to pause. You can start jobs with `-d` or `start jobs`."
|
85
102
|
|
86
103
|
if not action:
|
87
104
|
if not force:
|
88
|
-
pprint_jobs(
|
105
|
+
pprint_jobs(running_jobs)
|
89
106
|
if not yes_no(
|
90
107
|
"Pause all running jobs?",
|
91
108
|
noask=noask, yes=yes, default='n'
|
@@ -93,9 +110,9 @@ def _pause_jobs(
|
|
93
110
|
return False, "No jobs were paused."
|
94
111
|
|
95
112
|
successes, fails = [], []
|
96
|
-
for
|
97
|
-
pause_success, pause_msg =
|
98
|
-
(successes if pause_success else fails).append(
|
113
|
+
for name, job in jobs_to_pause.items():
|
114
|
+
pause_success, pause_msg = job.pause()
|
115
|
+
(successes if pause_success else fails).append(name)
|
99
116
|
|
100
117
|
msg = (
|
101
118
|
(
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#! /usr/bin/env python3
|
2
|
+
# vim:fenc=utf-8
|
3
|
+
|
4
|
+
"""
|
5
|
+
Restart stopped jobs which have not been manually stopped.
|
6
|
+
"""
|
7
|
+
|
8
|
+
from meerschaum.utils.typing import SuccessTuple, Optional, List, Any
|
9
|
+
|
10
|
+
def restart(
|
11
|
+
action: Optional[List[str]] = None,
|
12
|
+
executor_keys: Optional[str] = None,
|
13
|
+
**kwargs: Any
|
14
|
+
) -> SuccessTuple:
|
15
|
+
"""
|
16
|
+
Restart stopped jobs which have not been manually stopped.
|
17
|
+
"""
|
18
|
+
from meerschaum.actions import choose_subaction
|
19
|
+
attach_options = {
|
20
|
+
'jobs': _restart_jobs,
|
21
|
+
}
|
22
|
+
return choose_subaction(action, attach_options, executor_keys=executor_keys, **kwargs)
|
23
|
+
|
24
|
+
|
25
|
+
def _complete_restart(
|
26
|
+
action: Optional[List[str]] = None,
|
27
|
+
**kw: Any
|
28
|
+
) -> List[str]:
|
29
|
+
"""
|
30
|
+
Override the default Meerschaum `complete_` function.
|
31
|
+
"""
|
32
|
+
from functools import partial
|
33
|
+
from meerschaum.actions.delete import _complete_delete_jobs
|
34
|
+
|
35
|
+
if action is None:
|
36
|
+
action = []
|
37
|
+
|
38
|
+
_complete_restart_jobs = partial(
|
39
|
+
_complete_delete_jobs,
|
40
|
+
_get_job_method='restart',
|
41
|
+
)
|
42
|
+
|
43
|
+
options = {
|
44
|
+
'job': _complete_restart_jobs,
|
45
|
+
'jobs': _complete_restart_jobs,
|
46
|
+
}
|
47
|
+
|
48
|
+
if (
|
49
|
+
len(action) > 0 and action[0] in options
|
50
|
+
and kw.get('line', '').split(' ')[-1] != action[0]
|
51
|
+
):
|
52
|
+
sub = action[0]
|
53
|
+
del action[0]
|
54
|
+
return options[sub](action=action, **kw)
|
55
|
+
|
56
|
+
from meerschaum._internal.shell import default_action_completer
|
57
|
+
return default_action_completer(action=(['restart'] + action), **kw)
|
58
|
+
|
59
|
+
|
60
|
+
def _restart_jobs(
|
61
|
+
action: Optional[List[str]] = None,
|
62
|
+
executor_keys: Optional[str] = None,
|
63
|
+
loop: bool = False,
|
64
|
+
min_seconds: Optional[float] = 1.0,
|
65
|
+
debug: bool = False,
|
66
|
+
**kwargs: Any
|
67
|
+
) -> SuccessTuple:
|
68
|
+
"""
|
69
|
+
Restart stopped jobs which have not been manually stopped.
|
70
|
+
"""
|
71
|
+
import time
|
72
|
+
from meerschaum.jobs import (
|
73
|
+
get_restart_jobs,
|
74
|
+
get_filtered_jobs,
|
75
|
+
check_restart_jobs,
|
76
|
+
)
|
77
|
+
from meerschaum.utils.misc import items_str
|
78
|
+
from meerschaum.utils.warnings import info
|
79
|
+
action = action or []
|
80
|
+
|
81
|
+
while True:
|
82
|
+
jobs = get_filtered_jobs(executor_keys, action, include_hidden=True, debug=debug)
|
83
|
+
restart_jobs = get_restart_jobs(executor_keys, jobs, debug=debug) if not action else jobs
|
84
|
+
if not restart_jobs and not loop:
|
85
|
+
return True, "No jobs need to be restarted."
|
86
|
+
|
87
|
+
info(
|
88
|
+
"Checking job"
|
89
|
+
+ ('s' if len(restart_jobs) != 1 else '')
|
90
|
+
+ ' '
|
91
|
+
+ items_str(list(restart_jobs.keys()))
|
92
|
+
+ '...'
|
93
|
+
)
|
94
|
+
|
95
|
+
check_success, check_msg = check_restart_jobs(
|
96
|
+
executor_keys,
|
97
|
+
restart_jobs,
|
98
|
+
debug=debug,
|
99
|
+
)
|
100
|
+
if not loop:
|
101
|
+
break
|
102
|
+
|
103
|
+
if min_seconds is not None and min_seconds != 0.0:
|
104
|
+
info(f"Sleeping for {min_seconds} seconds...")
|
105
|
+
time.sleep(min_seconds)
|
106
|
+
|
107
|
+
return check_success, check_msg
|
meerschaum/actions/show.py
CHANGED
@@ -54,7 +54,7 @@ def _complete_show(
|
|
54
54
|
"""
|
55
55
|
Override the default Meerschaum `complete_` function.
|
56
56
|
"""
|
57
|
-
from meerschaum.actions.
|
57
|
+
from meerschaum.actions.delete import _complete_delete_jobs
|
58
58
|
|
59
59
|
if action is None:
|
60
60
|
action = []
|
@@ -65,10 +65,10 @@ def _complete_show(
|
|
65
65
|
'config' : _complete_show_config,
|
66
66
|
'package' : _complete_show_packages,
|
67
67
|
'packages' : _complete_show_packages,
|
68
|
-
'job' :
|
69
|
-
'jobs' :
|
70
|
-
'log' :
|
71
|
-
'logs' :
|
68
|
+
'job' : _complete_delete_jobs,
|
69
|
+
'jobs' : _complete_delete_jobs,
|
70
|
+
'log' : _complete_delete_jobs,
|
71
|
+
'logs' : _complete_delete_jobs,
|
72
72
|
}
|
73
73
|
|
74
74
|
if (
|
@@ -560,7 +560,7 @@ def _show_jobs(
|
|
560
560
|
"""
|
561
561
|
Show the currently running and stopped jobs.
|
562
562
|
"""
|
563
|
-
from meerschaum.
|
563
|
+
from meerschaum.jobs import get_filtered_jobs
|
564
564
|
from meerschaum.utils.formatting._jobs import pprint_jobs
|
565
565
|
|
566
566
|
jobs = get_filtered_jobs(executor_keys, action, debug=debug)
|
@@ -575,7 +575,7 @@ def _show_jobs(
|
|
575
575
|
" - start api -d\n" +
|
576
576
|
" - start job sync pipes --loop"
|
577
577
|
)
|
578
|
-
return
|
578
|
+
return True, "No jobs to show."
|
579
579
|
|
580
580
|
pprint_jobs(jobs, nopretty=nopretty)
|
581
581
|
return True, "Success"
|
@@ -602,7 +602,7 @@ def _show_logs(
|
|
602
602
|
from functools import partial
|
603
603
|
from datetime import datetime, timezone
|
604
604
|
from meerschaum.utils.packages import attempt_import, import_rich
|
605
|
-
from meerschaum.
|
605
|
+
from meerschaum.jobs import get_filtered_jobs, Job
|
606
606
|
from meerschaum.utils.warnings import warn, info
|
607
607
|
from meerschaum.utils.formatting import get_console, ANSI, UNICODE
|
608
608
|
from meerschaum.utils.misc import tail
|
meerschaum/actions/start.py
CHANGED
@@ -10,9 +10,9 @@ from __future__ import annotations
|
|
10
10
|
from meerschaum.utils.typing import SuccessTuple, Optional, List, Any
|
11
11
|
|
12
12
|
def start(
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
action: Optional[List[str]] = None,
|
14
|
+
**kw: Any,
|
15
|
+
) -> SuccessTuple:
|
16
16
|
"""
|
17
17
|
Start subsystems (API server, background job, etc.).
|
18
18
|
"""
|
@@ -28,16 +28,23 @@ def start(
|
|
28
28
|
|
29
29
|
|
30
30
|
def _complete_start(
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
action: Optional[List[str]] = None,
|
32
|
+
**kw: Any
|
33
|
+
) -> List[str]:
|
34
34
|
"""
|
35
35
|
Override the default Meerschaum `complete_` function.
|
36
36
|
"""
|
37
|
+
from meerschaum.actions.delete import _complete_delete_jobs
|
38
|
+
from functools import partial
|
37
39
|
|
38
40
|
if action is None:
|
39
41
|
action = []
|
40
42
|
|
43
|
+
_complete_start_jobs = partial(
|
44
|
+
_complete_delete_jobs,
|
45
|
+
_get_job_method=['stopped', 'paused'],
|
46
|
+
)
|
47
|
+
|
41
48
|
options = {
|
42
49
|
'job': _complete_start_jobs,
|
43
50
|
'jobs': _complete_start_jobs,
|
@@ -76,13 +83,13 @@ def _start_api(action: Optional[List[str]] = None, **kw):
|
|
76
83
|
return actions['api'](action=['start'], **kw)
|
77
84
|
|
78
85
|
def _start_jobs(
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
+
action: Optional[List[str]] = None,
|
87
|
+
name: Optional[str] = None,
|
88
|
+
sysargs: Optional[List[str]] = None,
|
89
|
+
executor_keys: Optional[str] = None,
|
90
|
+
debug: bool = False,
|
91
|
+
**kw
|
92
|
+
) -> SuccessTuple:
|
86
93
|
"""
|
87
94
|
Run a Meerschaum action as a background job.
|
88
95
|
|
@@ -115,7 +122,7 @@ def _start_jobs(
|
|
115
122
|
import textwrap
|
116
123
|
from meerschaum.utils.warnings import warn, info
|
117
124
|
from meerschaum.utils.daemon._names import get_new_daemon_name
|
118
|
-
from meerschaum.
|
125
|
+
from meerschaum.jobs import (
|
119
126
|
Job,
|
120
127
|
get_jobs,
|
121
128
|
get_filtered_jobs,
|
@@ -123,6 +130,7 @@ def _start_jobs(
|
|
123
130
|
get_running_jobs,
|
124
131
|
get_paused_jobs,
|
125
132
|
get_restart_jobs,
|
133
|
+
_install_healthcheck_job,
|
126
134
|
)
|
127
135
|
from meerschaum._internal.arguments._parse_arguments import parse_arguments
|
128
136
|
from meerschaum.actions import actions
|
@@ -133,7 +141,7 @@ def _start_jobs(
|
|
133
141
|
from meerschaum.utils.misc import items_str
|
134
142
|
|
135
143
|
names = []
|
136
|
-
jobs = get_filtered_jobs(executor_keys, debug=debug)
|
144
|
+
jobs = get_filtered_jobs(executor_keys, action, debug=debug)
|
137
145
|
|
138
146
|
new_job = len(list(action)) > 0
|
139
147
|
_potential_jobs = {'known': [], 'unknown': []}
|
@@ -166,7 +174,7 @@ def _start_jobs(
|
|
166
174
|
+ items_str(_potential_jobs['unknown'])
|
167
175
|
+ " will be ignored."
|
168
176
|
),
|
169
|
-
stack
|
177
|
+
stack=False
|
170
178
|
)
|
171
179
|
|
172
180
|
### Determine the `names` list.
|
@@ -232,7 +240,7 @@ def _start_jobs(
|
|
232
240
|
stop_success_tuple = actions['stop'](
|
233
241
|
action=['jobs'] + [_name for _name in _filtered_running_jobs],
|
234
242
|
force=True,
|
235
|
-
|
243
|
+
executor_keys=executor_keys,
|
236
244
|
debug=debug,
|
237
245
|
)
|
238
246
|
if not stop_success_tuple[0]:
|
@@ -294,33 +302,10 @@ def _start_jobs(
|
|
294
302
|
+ ("Failed to start job" + ("s" if len(_failures) != 1 else '')
|
295
303
|
+ f" {items_str(_failures)}." if _failures else '')
|
296
304
|
)
|
305
|
+
_install_healthcheck_job()
|
297
306
|
return len(_failures) == 0, msg
|
298
307
|
|
299
308
|
|
300
|
-
def _complete_start_jobs(
|
301
|
-
action: Optional[List[str]] = None,
|
302
|
-
executor_keys: Optional[str] = None,
|
303
|
-
line: str = '',
|
304
|
-
**kw
|
305
|
-
) -> List[str]:
|
306
|
-
from meerschaum.utils.jobs import get_filtered_jobs
|
307
|
-
jobs = get_filtered_jobs(executor_keys, action)
|
308
|
-
if not action:
|
309
|
-
return list(jobs)
|
310
|
-
|
311
|
-
possibilities = []
|
312
|
-
_line_end = line.split(' ')[-1]
|
313
|
-
for name in jobs:
|
314
|
-
if name in action:
|
315
|
-
continue
|
316
|
-
if _line_end == '':
|
317
|
-
possibilities.append(name)
|
318
|
-
continue
|
319
|
-
if name.startswith(action[-1]):
|
320
|
-
possibilities.append(name)
|
321
|
-
return possibilities
|
322
|
-
|
323
|
-
|
324
309
|
def _start_gui(
|
325
310
|
action: Optional[List[str]] = None,
|
326
311
|
mrsm_instance: Optional[str] = None,
|