fractal-server 2.15.0a3__py3-none-any.whl → 2.15.0a5__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.
- fractal_server/__init__.py +1 -1
- fractal_server/app/routes/admin/v2/task_group_lifecycle.py +0 -3
- fractal_server/app/routes/api/v2/_aux_functions_tasks.py +22 -0
- fractal_server/app/routes/api/v2/task_collection.py +5 -15
- fractal_server/app/routes/api/v2/task_collection_pixi.py +7 -24
- fractal_server/app/routes/api/v2/task_group.py +3 -0
- fractal_server/app/routes/api/v2/task_group_lifecycle.py +0 -3
- fractal_server/app/schemas/v2/__init__.py +0 -1
- fractal_server/app/schemas/v2/task_group.py +0 -9
- fractal_server/config.py +29 -1
- fractal_server/tasks/v2/local/_utils.py +1 -5
- fractal_server/tasks/v2/local/collect.py +5 -8
- fractal_server/tasks/v2/local/collect_pixi.py +29 -13
- fractal_server/tasks/v2/local/deactivate.py +5 -9
- fractal_server/tasks/v2/local/deactivate_pixi.py +4 -10
- fractal_server/tasks/v2/local/reactivate.py +5 -9
- fractal_server/tasks/v2/local/reactivate_pixi.py +29 -14
- fractal_server/tasks/v2/ssh/_utils.py +45 -4
- fractal_server/tasks/v2/ssh/collect.py +32 -37
- fractal_server/tasks/v2/ssh/collect_pixi.py +51 -45
- fractal_server/tasks/v2/ssh/deactivate.py +21 -28
- fractal_server/tasks/v2/ssh/deactivate_pixi.py +20 -28
- fractal_server/tasks/v2/ssh/reactivate.py +23 -29
- fractal_server/tasks/v2/ssh/reactivate_pixi.py +158 -38
- fractal_server/tasks/v2/templates/pixi_2_install.sh +12 -8
- fractal_server/tasks/v2/templates/pixi_3_post_install.sh +0 -4
- fractal_server/tasks/v2/utils_background.py +7 -0
- fractal_server/tasks/v2/utils_templates.py +14 -1
- {fractal_server-2.15.0a3.dist-info → fractal_server-2.15.0a5.dist-info}/METADATA +1 -1
- {fractal_server-2.15.0a3.dist-info → fractal_server-2.15.0a5.dist-info}/RECORD +33 -33
- {fractal_server-2.15.0a3.dist-info → fractal_server-2.15.0a5.dist-info}/LICENSE +0 -0
- {fractal_server-2.15.0a3.dist-info → fractal_server-2.15.0a5.dist-info}/WHEEL +0 -0
- {fractal_server-2.15.0a3.dist-info → fractal_server-2.15.0a5.dist-info}/entry_points.txt +0 -0
@@ -1,6 +1,10 @@
|
|
1
1
|
import os
|
2
2
|
from pathlib import Path
|
3
3
|
|
4
|
+
from sqlalchemy.ext.asyncio import AsyncSession
|
5
|
+
|
6
|
+
from ..utils_background import fail_and_cleanup
|
7
|
+
from fractal_server.app.models.v2 import TaskGroupActivityV2
|
4
8
|
from fractal_server.app.models.v2 import TaskGroupV2
|
5
9
|
from fractal_server.logger import get_logger
|
6
10
|
from fractal_server.ssh._fabric import FractalSSH
|
@@ -10,7 +14,7 @@ from fractal_server.tasks.v2.utils_templates import customize_template
|
|
10
14
|
def _customize_and_run_template(
|
11
15
|
*,
|
12
16
|
template_filename: str,
|
13
|
-
replacements:
|
17
|
+
replacements: set[tuple[str, str]],
|
14
18
|
script_dir_local: str,
|
15
19
|
prefix: str,
|
16
20
|
fractal_ssh: FractalSSH,
|
@@ -66,7 +70,10 @@ def _customize_and_run_template(
|
|
66
70
|
|
67
71
|
|
68
72
|
def _copy_wheel_file_ssh(
|
69
|
-
*,
|
73
|
+
*,
|
74
|
+
task_group: TaskGroupV2,
|
75
|
+
fractal_ssh: FractalSSH,
|
76
|
+
logger_name: str,
|
70
77
|
) -> str:
|
71
78
|
"""
|
72
79
|
Handle the situation where `task_group.archive_path` is not part of
|
@@ -81,7 +88,41 @@ def _copy_wheel_file_ssh(
|
|
81
88
|
Path(task_group.path) / Path(task_group.archive_path).name
|
82
89
|
).as_posix()
|
83
90
|
cmd = f"cp {source} {dest}"
|
84
|
-
logger.debug(f"[
|
91
|
+
logger.debug(f"[_copy_wheel_file_ssh] START {source=} {dest=}")
|
85
92
|
fractal_ssh.run_command(cmd=cmd)
|
86
|
-
logger.debug(f"[
|
93
|
+
logger.debug(f"[_copy_wheel_file_ssh] END {source=} {dest=}")
|
87
94
|
return dest
|
95
|
+
|
96
|
+
|
97
|
+
def check_ssh_or_fail_and_cleanup(
|
98
|
+
*,
|
99
|
+
fractal_ssh: FractalSSH,
|
100
|
+
task_group: TaskGroupV2,
|
101
|
+
task_group_activity: TaskGroupActivityV2,
|
102
|
+
logger_name: str,
|
103
|
+
log_file_path: Path,
|
104
|
+
db: AsyncSession,
|
105
|
+
) -> bool:
|
106
|
+
"""
|
107
|
+
Check SSH connection.
|
108
|
+
|
109
|
+
Returns:
|
110
|
+
Whether SSH connection is OK.
|
111
|
+
"""
|
112
|
+
try:
|
113
|
+
fractal_ssh.check_connection()
|
114
|
+
return True
|
115
|
+
except Exception as e:
|
116
|
+
logger = get_logger(logger_name=logger_name)
|
117
|
+
logger.error(
|
118
|
+
"Cannot establish SSH connection. " f"Original error: {str(e)}"
|
119
|
+
)
|
120
|
+
fail_and_cleanup(
|
121
|
+
task_group=task_group,
|
122
|
+
task_group_activity=task_group_activity,
|
123
|
+
logger_name=logger_name,
|
124
|
+
log_file_path=log_file_path,
|
125
|
+
exception=e,
|
126
|
+
db=db,
|
127
|
+
)
|
128
|
+
return False
|
@@ -2,11 +2,11 @@ import time
|
|
2
2
|
from pathlib import Path
|
3
3
|
from tempfile import TemporaryDirectory
|
4
4
|
|
5
|
-
from ....ssh._fabric import SingleUseFractalSSH
|
6
5
|
from ..utils_background import fail_and_cleanup
|
7
6
|
from ..utils_background import get_activity_and_task_group
|
8
7
|
from ..utils_background import prepare_tasks_metadata
|
9
8
|
from ..utils_database import create_db_tasks_and_update_task_group_sync
|
9
|
+
from ._utils import check_ssh_or_fail_and_cleanup
|
10
10
|
from fractal_server.app.db import get_sync_db
|
11
11
|
from fractal_server.app.schemas.v2 import FractalUploadedFile
|
12
12
|
from fractal_server.app.schemas.v2 import TaskGroupActivityActionV2
|
@@ -14,6 +14,7 @@ from fractal_server.app.schemas.v2 import TaskGroupActivityStatusV2
|
|
14
14
|
from fractal_server.app.schemas.v2.manifest import ManifestV2
|
15
15
|
from fractal_server.logger import reset_logger_handlers
|
16
16
|
from fractal_server.logger import set_logger
|
17
|
+
from fractal_server.ssh._fabric import SingleUseFractalSSH
|
17
18
|
from fractal_server.ssh._fabric import SSHConfig
|
18
19
|
from fractal_server.tasks.v2.ssh._utils import _customize_and_run_template
|
19
20
|
from fractal_server.tasks.v2.utils_background import add_commit_refresh
|
@@ -68,43 +69,39 @@ def collect_ssh(
|
|
68
69
|
logger_name=LOGGER_NAME,
|
69
70
|
log_file_path=log_file_path,
|
70
71
|
)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
for key, value in task_group.model_dump().items():
|
88
|
-
logger.debug(f"task_group.{key}: {value}")
|
89
|
-
|
90
|
-
# Check that SSH connection works
|
72
|
+
logger.info("START")
|
73
|
+
with next(get_sync_db()) as db:
|
74
|
+
db_objects_ok, task_group, activity = get_activity_and_task_group(
|
75
|
+
task_group_activity_id=task_group_activity_id,
|
76
|
+
task_group_id=task_group_id,
|
77
|
+
db=db,
|
78
|
+
logger_name=LOGGER_NAME,
|
79
|
+
)
|
80
|
+
if not db_objects_ok:
|
81
|
+
return
|
82
|
+
|
83
|
+
with SingleUseFractalSSH(
|
84
|
+
ssh_config=ssh_config,
|
85
|
+
logger_name=LOGGER_NAME,
|
86
|
+
) as fractal_ssh:
|
87
|
+
|
91
88
|
try:
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
fail_and_cleanup(
|
89
|
+
# Check SSH connection
|
90
|
+
ssh_ok = check_ssh_or_fail_and_cleanup(
|
91
|
+
fractal_ssh=fractal_ssh,
|
96
92
|
task_group=task_group,
|
97
93
|
task_group_activity=activity,
|
98
94
|
logger_name=LOGGER_NAME,
|
99
95
|
log_file_path=log_file_path,
|
100
|
-
exception=e,
|
101
96
|
db=db,
|
102
97
|
)
|
103
|
-
|
104
|
-
|
105
|
-
try:
|
98
|
+
if not ssh_ok:
|
99
|
+
return
|
106
100
|
|
107
101
|
# Check that the (remote) task_group path does not exist
|
102
|
+
# NOTE: this is not part of the try/except below, in order
|
103
|
+
# to avoid removing the existing folder (as part of the
|
104
|
+
# exception-handling).
|
108
105
|
if fractal_ssh.remote_exists(task_group.path):
|
109
106
|
error_msg = f"{task_group.path} already exists."
|
110
107
|
logger.error(error_msg)
|
@@ -119,9 +116,7 @@ def collect_ssh(
|
|
119
116
|
return
|
120
117
|
|
121
118
|
# Create remote `task_group.path` and `script_dir_remote`
|
122
|
-
# folders
|
123
|
-
# the `no error if existing, make parent directories as
|
124
|
-
# needed` scenario for `mkdir`)
|
119
|
+
# folders
|
125
120
|
script_dir_remote = (
|
126
121
|
Path(task_group.path) / SCRIPTS_SUBFOLDER
|
127
122
|
).as_posix()
|
@@ -139,8 +134,7 @@ def collect_ssh(
|
|
139
134
|
Path(tmpdir) / wheel_filename
|
140
135
|
).as_posix()
|
141
136
|
logger.info(
|
142
|
-
"Write wheel
|
143
|
-
f"{tmp_archive_path}"
|
137
|
+
f"Write wheel file into {tmp_archive_path}"
|
144
138
|
)
|
145
139
|
with open(tmp_archive_path, "wb") as f:
|
146
140
|
f.write(wheel_file.contents)
|
@@ -161,8 +155,8 @@ def collect_ssh(
|
|
161
155
|
# Prepare common arguments for _customize_and_run_template
|
162
156
|
common_args = dict(
|
163
157
|
replacements=replacements,
|
164
|
-
script_dir_local=(
|
165
|
-
|
158
|
+
script_dir_local=Path(
|
159
|
+
tmpdir, SCRIPTS_SUBFOLDER
|
166
160
|
).as_posix(),
|
167
161
|
script_dir_remote=script_dir_remote,
|
168
162
|
prefix=(
|
@@ -187,6 +181,7 @@ def collect_ssh(
|
|
187
181
|
)
|
188
182
|
activity.log = get_current_log(log_file_path)
|
189
183
|
activity = add_commit_refresh(obj=activity, db=db)
|
184
|
+
|
190
185
|
# Run script 2
|
191
186
|
stdout = _customize_and_run_template(
|
192
187
|
template_filename="2_pip_install.sh",
|
@@ -315,7 +310,7 @@ def collect_ssh(
|
|
315
310
|
except Exception as e_rm:
|
316
311
|
logger.error(
|
317
312
|
"Removing folder failed. "
|
318
|
-
f"Original error
|
313
|
+
f"Original error: {str(e_rm)}"
|
319
314
|
)
|
320
315
|
fail_and_cleanup(
|
321
316
|
task_group=task_group,
|
@@ -2,13 +2,13 @@ import time
|
|
2
2
|
from pathlib import Path
|
3
3
|
from tempfile import TemporaryDirectory
|
4
4
|
|
5
|
-
from ....ssh._fabric import SingleUseFractalSSH
|
6
5
|
from ..utils_background import fail_and_cleanup
|
7
6
|
from ..utils_background import get_activity_and_task_group
|
8
7
|
from ..utils_background import prepare_tasks_metadata
|
9
8
|
from ..utils_database import create_db_tasks_and_update_task_group_sync
|
10
9
|
from ..utils_pixi import parse_collect_stdout
|
11
10
|
from ..utils_pixi import SOURCE_DIR_NAME
|
11
|
+
from ._utils import check_ssh_or_fail_and_cleanup
|
12
12
|
from fractal_server.app.db import get_sync_db
|
13
13
|
from fractal_server.app.schemas.v2 import FractalUploadedFile
|
14
14
|
from fractal_server.app.schemas.v2 import TaskGroupActivityActionV2
|
@@ -17,6 +17,7 @@ from fractal_server.app.schemas.v2.manifest import ManifestV2
|
|
17
17
|
from fractal_server.config import get_settings
|
18
18
|
from fractal_server.logger import reset_logger_handlers
|
19
19
|
from fractal_server.logger import set_logger
|
20
|
+
from fractal_server.ssh._fabric import SingleUseFractalSSH
|
20
21
|
from fractal_server.ssh._fabric import SSHConfig
|
21
22
|
from fractal_server.syringe import Inject
|
22
23
|
from fractal_server.tasks.v2.ssh._utils import _customize_and_run_template
|
@@ -64,43 +65,34 @@ def collect_ssh_pixi(
|
|
64
65
|
logger_name=LOGGER_NAME,
|
65
66
|
log_file_path=log_file_path,
|
66
67
|
)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
logger.info("START")
|
83
|
-
for key, value in task_group.model_dump(
|
84
|
-
exclude={"env_info"}
|
85
|
-
).items():
|
86
|
-
logger.debug(f"task_group.{key}: {value}")
|
68
|
+
logger.info("START")
|
69
|
+
with next(get_sync_db()) as db:
|
70
|
+
db_objects_ok, task_group, activity = get_activity_and_task_group(
|
71
|
+
task_group_activity_id=task_group_activity_id,
|
72
|
+
task_group_id=task_group_id,
|
73
|
+
db=db,
|
74
|
+
logger_name=LOGGER_NAME,
|
75
|
+
)
|
76
|
+
if not db_objects_ok:
|
77
|
+
return
|
78
|
+
|
79
|
+
with SingleUseFractalSSH(
|
80
|
+
ssh_config=ssh_config,
|
81
|
+
logger_name=LOGGER_NAME,
|
82
|
+
) as fractal_ssh:
|
87
83
|
|
88
|
-
# Check that SSH connection works
|
89
84
|
try:
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
fail_and_cleanup(
|
85
|
+
# Check SSH connection
|
86
|
+
ssh_ok = check_ssh_or_fail_and_cleanup(
|
87
|
+
fractal_ssh=fractal_ssh,
|
94
88
|
task_group=task_group,
|
95
89
|
task_group_activity=activity,
|
96
90
|
logger_name=LOGGER_NAME,
|
97
91
|
log_file_path=log_file_path,
|
98
|
-
exception=e,
|
99
92
|
db=db,
|
100
93
|
)
|
101
|
-
|
102
|
-
|
103
|
-
try:
|
94
|
+
if not ssh_ok:
|
95
|
+
return
|
104
96
|
|
105
97
|
# Check that the (remote) task_group path does not exist
|
106
98
|
if fractal_ssh.remote_exists(task_group.path):
|
@@ -117,11 +109,9 @@ def collect_ssh_pixi(
|
|
117
109
|
return
|
118
110
|
|
119
111
|
# Create remote `task_group.path` and `script_dir_remote`
|
120
|
-
# folders
|
121
|
-
|
122
|
-
|
123
|
-
script_dir_remote = (
|
124
|
-
Path(task_group.path) / SCRIPTS_SUBFOLDER
|
112
|
+
# folders
|
113
|
+
script_dir_remote = Path(
|
114
|
+
task_group.path, SCRIPTS_SUBFOLDER
|
125
115
|
).as_posix()
|
126
116
|
fractal_ssh.mkdir(folder=task_group.path, parents=True)
|
127
117
|
fractal_ssh.mkdir(folder=script_dir_remote, parents=True)
|
@@ -133,9 +123,7 @@ def collect_ssh_pixi(
|
|
133
123
|
Path(task_group.path) / tar_gz_filename
|
134
124
|
).as_posix()
|
135
125
|
tmp_archive_path = Path(tmpdir, tar_gz_filename).as_posix()
|
136
|
-
logger.info(
|
137
|
-
f"Write tar.gz-file contents into {tmp_archive_path}"
|
138
|
-
)
|
126
|
+
logger.info(f"Write tar.gz file into {tmp_archive_path}")
|
139
127
|
with open(tmp_archive_path, "wb") as f:
|
140
128
|
f.write(tar_gz_file.contents)
|
141
129
|
fractal_ssh.send_file(
|
@@ -145,19 +133,32 @@ def collect_ssh_pixi(
|
|
145
133
|
task_group.archive_path = archive_path
|
146
134
|
task_group = add_commit_refresh(obj=task_group, db=db)
|
147
135
|
|
148
|
-
# Set `pixi_bin`
|
149
136
|
settings = Inject(get_settings)
|
150
|
-
pixi_home = settings.pixi.versions[task_group.pixi_version]
|
151
|
-
|
152
137
|
replacements = {
|
153
|
-
(
|
138
|
+
(
|
139
|
+
"__PIXI_HOME__",
|
140
|
+
settings.pixi.versions[task_group.pixi_version],
|
141
|
+
),
|
154
142
|
("__PACKAGE_DIR__", task_group.path),
|
155
|
-
("__TAR_GZ_PATH__", archive_path),
|
143
|
+
("__TAR_GZ_PATH__", task_group.archive_path),
|
156
144
|
(
|
157
145
|
"__IMPORT_PACKAGE_NAME__",
|
158
146
|
task_group.pkg_name.replace("-", "_"),
|
159
147
|
),
|
160
148
|
("__SOURCE_DIR_NAME__", SOURCE_DIR_NAME),
|
149
|
+
("__FROZEN_OPTION__", ""),
|
150
|
+
(
|
151
|
+
"__TOKIO_WORKER_THREADS__",
|
152
|
+
str(settings.pixi.TOKIO_WORKER_THREADS),
|
153
|
+
),
|
154
|
+
(
|
155
|
+
"__PIXI_CONCURRENT_SOLVES__",
|
156
|
+
str(settings.pixi.PIXI_CONCURRENT_SOLVES),
|
157
|
+
),
|
158
|
+
(
|
159
|
+
"__PIXI_CONCURRENT_DOWNLOADS__",
|
160
|
+
str(settings.pixi.PIXI_CONCURRENT_DOWNLOADS),
|
161
|
+
),
|
161
162
|
}
|
162
163
|
|
163
164
|
logger.info("installing - START")
|
@@ -169,7 +170,7 @@ def collect_ssh_pixi(
|
|
169
170
|
|
170
171
|
common_args = dict(
|
171
172
|
script_dir_local=(
|
172
|
-
Path(tmpdir
|
173
|
+
Path(tmpdir, SCRIPTS_SUBFOLDER)
|
173
174
|
).as_posix(),
|
174
175
|
script_dir_remote=script_dir_remote,
|
175
176
|
prefix=(
|
@@ -214,6 +215,11 @@ def collect_ssh_pixi(
|
|
214
215
|
"project_python_wrapper"
|
215
216
|
]
|
216
217
|
|
218
|
+
source_dir = Path(
|
219
|
+
task_group.path, SOURCE_DIR_NAME
|
220
|
+
).as_posix()
|
221
|
+
fractal_ssh.run_command(cmd=f"chmod 755 {source_dir} -R")
|
222
|
+
|
217
223
|
# Read and validate remote manifest file
|
218
224
|
manifest_path_remote = (
|
219
225
|
f"{package_root_remote}/__FRACTAL_MANIFEST__.json"
|
@@ -294,7 +300,7 @@ def collect_ssh_pixi(
|
|
294
300
|
except Exception as e_rm:
|
295
301
|
logger.error(
|
296
302
|
"Removing folder failed. "
|
297
|
-
f"Original error
|
303
|
+
f"Original error: {str(e_rm)}"
|
298
304
|
)
|
299
305
|
fail_and_cleanup(
|
300
306
|
task_group=task_group,
|
@@ -8,6 +8,7 @@ from ..utils_background import get_activity_and_task_group
|
|
8
8
|
from ..utils_templates import get_collection_replacements
|
9
9
|
from ._utils import _copy_wheel_file_ssh
|
10
10
|
from ._utils import _customize_and_run_template
|
11
|
+
from ._utils import check_ssh_or_fail_and_cleanup
|
11
12
|
from fractal_server.app.db import get_sync_db
|
12
13
|
from fractal_server.app.schemas.v2 import TaskGroupActivityActionV2
|
13
14
|
from fractal_server.app.schemas.v2 import TaskGroupV2OriginEnum
|
@@ -53,41 +54,33 @@ def deactivate_ssh(
|
|
53
54
|
logger_name=LOGGER_NAME,
|
54
55
|
log_file_path=log_file_path,
|
55
56
|
)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
logger.debug("START")
|
72
|
-
for key, value in task_group.model_dump().items():
|
73
|
-
logger.debug(f"task_group.{key}: {value}")
|
74
|
-
|
75
|
-
# Check that SSH connection works
|
57
|
+
logger.debug("START")
|
58
|
+
with next(get_sync_db()) as db:
|
59
|
+
db_objects_ok, task_group, activity = get_activity_and_task_group(
|
60
|
+
task_group_activity_id=task_group_activity_id,
|
61
|
+
task_group_id=task_group_id,
|
62
|
+
db=db,
|
63
|
+
logger_name=LOGGER_NAME,
|
64
|
+
)
|
65
|
+
if not db_objects_ok:
|
66
|
+
return
|
67
|
+
|
68
|
+
with SingleUseFractalSSH(
|
69
|
+
ssh_config=ssh_config,
|
70
|
+
logger_name=LOGGER_NAME,
|
71
|
+
) as fractal_ssh:
|
76
72
|
try:
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
fail_and_cleanup(
|
73
|
+
# Check SSH connection
|
74
|
+
ssh_ok = check_ssh_or_fail_and_cleanup(
|
75
|
+
fractal_ssh=fractal_ssh,
|
81
76
|
task_group=task_group,
|
82
77
|
task_group_activity=activity,
|
83
78
|
logger_name=LOGGER_NAME,
|
84
79
|
log_file_path=log_file_path,
|
85
|
-
exception=e,
|
86
80
|
db=db,
|
87
81
|
)
|
88
|
-
|
89
|
-
|
90
|
-
try:
|
82
|
+
if not ssh_ok:
|
83
|
+
return
|
91
84
|
|
92
85
|
# Check that the (local) task_group venv_path does exist
|
93
86
|
if not fractal_ssh.remote_exists(task_group.venv_path):
|
@@ -5,6 +5,7 @@ from ..utils_background import add_commit_refresh
|
|
5
5
|
from ..utils_background import fail_and_cleanup
|
6
6
|
from ..utils_background import get_activity_and_task_group
|
7
7
|
from ..utils_pixi import SOURCE_DIR_NAME
|
8
|
+
from ._utils import check_ssh_or_fail_and_cleanup
|
8
9
|
from fractal_server.app.db import get_sync_db
|
9
10
|
from fractal_server.app.schemas.v2.task_group import TaskGroupActivityStatusV2
|
10
11
|
from fractal_server.logger import reset_logger_handlers
|
@@ -46,43 +47,34 @@ def deactivate_ssh_pixi(
|
|
46
47
|
logger_name=LOGGER_NAME,
|
47
48
|
log_file_path=log_file_path,
|
48
49
|
)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
)
|
60
|
-
if not success:
|
61
|
-
return
|
50
|
+
logger.debug("START")
|
51
|
+
with next(get_sync_db()) as db:
|
52
|
+
db_objects_ok, task_group, activity = get_activity_and_task_group(
|
53
|
+
task_group_activity_id=task_group_activity_id,
|
54
|
+
task_group_id=task_group_id,
|
55
|
+
db=db,
|
56
|
+
logger_name=LOGGER_NAME,
|
57
|
+
)
|
58
|
+
if not db_objects_ok:
|
59
|
+
return
|
62
60
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
).items():
|
68
|
-
logger.debug(f"task_group.{key}: {value}")
|
69
|
-
|
70
|
-
# Check that SSH connection works
|
61
|
+
with SingleUseFractalSSH(
|
62
|
+
ssh_config=ssh_config,
|
63
|
+
logger_name=LOGGER_NAME,
|
64
|
+
) as fractal_ssh:
|
71
65
|
try:
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
fail_and_cleanup(
|
66
|
+
# Check SSH connection
|
67
|
+
ssh_ok = check_ssh_or_fail_and_cleanup(
|
68
|
+
fractal_ssh=fractal_ssh,
|
76
69
|
task_group=task_group,
|
77
70
|
task_group_activity=activity,
|
78
71
|
logger_name=LOGGER_NAME,
|
79
72
|
log_file_path=log_file_path,
|
80
|
-
exception=e,
|
81
73
|
db=db,
|
82
74
|
)
|
83
|
-
|
75
|
+
if not ssh_ok:
|
76
|
+
return
|
84
77
|
|
85
|
-
try:
|
86
78
|
# Check that the (remote) task_group venv_path does exist
|
87
79
|
source_dir = Path(
|
88
80
|
task_group.path, SOURCE_DIR_NAME
|
@@ -7,6 +7,7 @@ from ..utils_background import fail_and_cleanup
|
|
7
7
|
from ..utils_background import get_activity_and_task_group
|
8
8
|
from ..utils_templates import get_collection_replacements
|
9
9
|
from ._utils import _customize_and_run_template
|
10
|
+
from ._utils import check_ssh_or_fail_and_cleanup
|
10
11
|
from fractal_server.app.db import get_sync_db
|
11
12
|
from fractal_server.app.schemas.v2 import TaskGroupActivityActionV2
|
12
13
|
from fractal_server.app.schemas.v2.task_group import TaskGroupActivityStatusV2
|
@@ -54,41 +55,34 @@ def reactivate_ssh(
|
|
54
55
|
log_file_path=log_file_path,
|
55
56
|
)
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
logger.info("START")
|
73
|
-
for key, value in task_group.model_dump().items():
|
74
|
-
logger.debug(f"task_group.{key}: {value}")
|
75
|
-
|
76
|
-
# Check that SSH connection works
|
58
|
+
logger.info("START")
|
59
|
+
with next(get_sync_db()) as db:
|
60
|
+
db_objects_ok, task_group, activity = get_activity_and_task_group(
|
61
|
+
task_group_activity_id=task_group_activity_id,
|
62
|
+
task_group_id=task_group_id,
|
63
|
+
db=db,
|
64
|
+
logger_name=LOGGER_NAME,
|
65
|
+
)
|
66
|
+
if not db_objects_ok:
|
67
|
+
return
|
68
|
+
|
69
|
+
with SingleUseFractalSSH(
|
70
|
+
ssh_config=ssh_config,
|
71
|
+
logger_name=LOGGER_NAME,
|
72
|
+
) as fractal_ssh:
|
77
73
|
try:
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
fail_and_cleanup(
|
74
|
+
# Check SSH connection
|
75
|
+
ssh_ok = check_ssh_or_fail_and_cleanup(
|
76
|
+
fractal_ssh=fractal_ssh,
|
82
77
|
task_group=task_group,
|
83
78
|
task_group_activity=activity,
|
84
79
|
logger_name=LOGGER_NAME,
|
85
80
|
log_file_path=log_file_path,
|
86
|
-
exception=e,
|
87
81
|
db=db,
|
88
82
|
)
|
89
|
-
|
83
|
+
if not ssh_ok:
|
84
|
+
return
|
90
85
|
|
91
|
-
try:
|
92
86
|
# Check that the (remote) task_group venv_path does not
|
93
87
|
# exist
|
94
88
|
if fractal_ssh.remote_exists(task_group.venv_path):
|
@@ -192,8 +186,8 @@ def reactivate_ssh(
|
|
192
186
|
logger.info(f"Deleted folder {task_group.venv_path}")
|
193
187
|
except Exception as rm_e:
|
194
188
|
logger.error(
|
195
|
-
"Removing folder failed
|
196
|
-
f"Original error
|
189
|
+
"Removing folder failed. "
|
190
|
+
f"Original error: {str(rm_e)}"
|
197
191
|
)
|
198
192
|
|
199
193
|
fail_and_cleanup(
|