fractal-server 2.15.0a2__py3-none-any.whl → 2.15.0a4__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.
Files changed (29) hide show
  1. fractal_server/__init__.py +1 -1
  2. fractal_server/app/routes/admin/v2/task_group_lifecycle.py +0 -3
  3. fractal_server/app/routes/api/v2/task_collection.py +0 -2
  4. fractal_server/app/routes/api/v2/task_collection_pixi.py +1 -12
  5. fractal_server/app/routes/api/v2/task_group_lifecycle.py +0 -3
  6. fractal_server/app/schemas/v2/__init__.py +0 -1
  7. fractal_server/app/schemas/v2/task_group.py +0 -9
  8. fractal_server/tasks/v2/local/_utils.py +1 -5
  9. fractal_server/tasks/v2/local/collect.py +5 -8
  10. fractal_server/tasks/v2/local/collect_pixi.py +8 -11
  11. fractal_server/tasks/v2/local/deactivate.py +5 -9
  12. fractal_server/tasks/v2/local/deactivate_pixi.py +4 -8
  13. fractal_server/tasks/v2/local/reactivate.py +5 -9
  14. fractal_server/tasks/v2/local/reactivate_pixi.py +16 -19
  15. fractal_server/tasks/v2/ssh/_utils.py +45 -4
  16. fractal_server/tasks/v2/ssh/collect.py +32 -37
  17. fractal_server/tasks/v2/ssh/collect_pixi.py +36 -47
  18. fractal_server/tasks/v2/ssh/deactivate.py +21 -28
  19. fractal_server/tasks/v2/ssh/deactivate_pixi.py +20 -26
  20. fractal_server/tasks/v2/ssh/reactivate.py +23 -29
  21. fractal_server/tasks/v2/ssh/reactivate_pixi.py +144 -36
  22. fractal_server/tasks/v2/templates/pixi_2_install.sh +3 -8
  23. fractal_server/tasks/v2/utils_background.py +7 -0
  24. fractal_server/tasks/v2/utils_templates.py +14 -1
  25. {fractal_server-2.15.0a2.dist-info → fractal_server-2.15.0a4.dist-info}/METADATA +1 -1
  26. {fractal_server-2.15.0a2.dist-info → fractal_server-2.15.0a4.dist-info}/RECORD +29 -29
  27. {fractal_server-2.15.0a2.dist-info → fractal_server-2.15.0a4.dist-info}/LICENSE +0 -0
  28. {fractal_server-2.15.0a2.dist-info → fractal_server-2.15.0a4.dist-info}/WHEEL +0 -0
  29. {fractal_server-2.15.0a2.dist-info → fractal_server-2.15.0a4.dist-info}/entry_points.txt +0 -0
@@ -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,41 +65,34 @@ def collect_ssh_pixi(
64
65
  logger_name=LOGGER_NAME,
65
66
  log_file_path=log_file_path,
66
67
  )
67
- with SingleUseFractalSSH(
68
- ssh_config=ssh_config,
69
- logger_name=LOGGER_NAME,
70
- ) as fractal_ssh:
71
-
72
- with next(get_sync_db()) as db:
73
- success, task_group, activity = get_activity_and_task_group(
74
- task_group_activity_id=task_group_activity_id,
75
- task_group_id=task_group_id,
76
- db=db,
77
- )
78
- if not success:
79
- return
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:
80
83
 
81
- # Log some info
82
- logger.info("START")
83
- for key, value in task_group.model_dump().items():
84
- logger.debug(f"task_group.{key}: {value}")
85
-
86
- # Check that SSH connection works
87
84
  try:
88
- fractal_ssh.check_connection()
89
- except Exception as e:
90
- logger.error("Cannot establish SSH connection.")
91
- fail_and_cleanup(
85
+ # Check SSH connection
86
+ ssh_ok = check_ssh_or_fail_and_cleanup(
87
+ fractal_ssh=fractal_ssh,
92
88
  task_group=task_group,
93
89
  task_group_activity=activity,
94
90
  logger_name=LOGGER_NAME,
95
91
  log_file_path=log_file_path,
96
- exception=e,
97
92
  db=db,
98
93
  )
99
- return
100
-
101
- try:
94
+ if not ssh_ok:
95
+ return
102
96
 
103
97
  # Check that the (remote) task_group path does not exist
104
98
  if fractal_ssh.remote_exists(task_group.path):
@@ -115,11 +109,9 @@ def collect_ssh_pixi(
115
109
  return
116
110
 
117
111
  # Create remote `task_group.path` and `script_dir_remote`
118
- # folders (note that because of `parents=True` we are in
119
- # the `no error if existing, make parent directories as
120
- # needed` scenario for `mkdir`)
121
- script_dir_remote = (
122
- Path(task_group.path) / SCRIPTS_SUBFOLDER
112
+ # folders
113
+ script_dir_remote = Path(
114
+ task_group.path, SCRIPTS_SUBFOLDER
123
115
  ).as_posix()
124
116
  fractal_ssh.mkdir(folder=task_group.path, parents=True)
125
117
  fractal_ssh.mkdir(folder=script_dir_remote, parents=True)
@@ -130,12 +122,8 @@ def collect_ssh_pixi(
130
122
  archive_path = (
131
123
  Path(task_group.path) / tar_gz_filename
132
124
  ).as_posix()
133
- tmp_archive_path = (
134
- Path(tmpdir) / tar_gz_filename
135
- ).as_posix()
136
- logger.info(
137
- f"Write tar.gz-file contents into {tmp_archive_path}"
138
- )
125
+ tmp_archive_path = Path(tmpdir, tar_gz_filename).as_posix()
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,20 @@ 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
- ("__PIXI_HOME__", pixi_home),
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__", ""),
161
150
  }
162
151
 
163
152
  logger.info("installing - START")
@@ -169,15 +158,15 @@ def collect_ssh_pixi(
169
158
 
170
159
  common_args = dict(
171
160
  script_dir_local=(
172
- Path(tmpdir) / SCRIPTS_SUBFOLDER
161
+ Path(tmpdir, SCRIPTS_SUBFOLDER)
173
162
  ).as_posix(),
174
163
  script_dir_remote=script_dir_remote,
175
164
  prefix=(
176
165
  f"{int(time.time())}_"
177
166
  f"{TaskGroupActivityActionV2.COLLECT}"
178
167
  ),
179
- fractal_ssh=fractal_ssh,
180
168
  logger_name=LOGGER_NAME,
169
+ fractal_ssh=fractal_ssh,
181
170
  )
182
171
 
183
172
  # Run the three pixi-related scripts
@@ -294,7 +283,7 @@ def collect_ssh_pixi(
294
283
  except Exception as e_rm:
295
284
  logger.error(
296
285
  "Removing folder failed. "
297
- f"Original error:\n{str(e_rm)}"
286
+ f"Original error: {str(e_rm)}"
298
287
  )
299
288
  fail_and_cleanup(
300
289
  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
- with SingleUseFractalSSH(
57
- ssh_config=ssh_config,
58
- logger_name=LOGGER_NAME,
59
- ) as fractal_ssh:
60
-
61
- with next(get_sync_db()) as db:
62
- success, task_group, activity = get_activity_and_task_group(
63
- task_group_activity_id=task_group_activity_id,
64
- task_group_id=task_group_id,
65
- db=db,
66
- )
67
- if not success:
68
- return
69
-
70
- # Log some info
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
- fractal_ssh.check_connection()
78
- except Exception as e:
79
- logger.error("Cannot establish SSH connection.")
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
- return
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,41 +47,34 @@ def deactivate_ssh_pixi(
46
47
  logger_name=LOGGER_NAME,
47
48
  log_file_path=log_file_path,
48
49
  )
49
- with SingleUseFractalSSH(
50
- ssh_config=ssh_config,
51
- logger_name=LOGGER_NAME,
52
- ) as fractal_ssh:
53
-
54
- with next(get_sync_db()) as db:
55
- success, task_group, activity = get_activity_and_task_group(
56
- task_group_activity_id=task_group_activity_id,
57
- task_group_id=task_group_id,
58
- db=db,
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
- # Log some info
64
- logger.debug("START")
65
- for key, value in task_group.model_dump().items():
66
- logger.debug(f"task_group.{key}: {value}")
67
-
68
- # Check that SSH connection works
61
+ with SingleUseFractalSSH(
62
+ ssh_config=ssh_config,
63
+ logger_name=LOGGER_NAME,
64
+ ) as fractal_ssh:
69
65
  try:
70
- fractal_ssh.check_connection()
71
- except Exception as e:
72
- logger.error("Cannot establish SSH connection.")
73
- fail_and_cleanup(
66
+ # Check SSH connection
67
+ ssh_ok = check_ssh_or_fail_and_cleanup(
68
+ fractal_ssh=fractal_ssh,
74
69
  task_group=task_group,
75
70
  task_group_activity=activity,
76
71
  logger_name=LOGGER_NAME,
77
72
  log_file_path=log_file_path,
78
- exception=e,
79
73
  db=db,
80
74
  )
81
- return
75
+ if not ssh_ok:
76
+ return
82
77
 
83
- try:
84
78
  # Check that the (remote) task_group venv_path does exist
85
79
  source_dir = Path(
86
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
- with SingleUseFractalSSH(
58
- ssh_config=ssh_config,
59
- logger_name=LOGGER_NAME,
60
- ) as fractal_ssh:
61
-
62
- with next(get_sync_db()) as db:
63
- success, task_group, activity = get_activity_and_task_group(
64
- task_group_activity_id=task_group_activity_id,
65
- task_group_id=task_group_id,
66
- db=db,
67
- )
68
- if not success:
69
- return
70
-
71
- # Log some info
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
- fractal_ssh.check_connection()
79
- except Exception as e:
80
- logger.error("Cannot establish SSH connection.")
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
- return
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.\n"
196
- f"Original error:\n{str(rm_e)}"
189
+ "Removing folder failed. "
190
+ f"Original error: {str(rm_e)}"
197
191
  )
198
192
 
199
193
  fail_and_cleanup(
@@ -1,14 +1,26 @@
1
+ import time
1
2
  from pathlib import Path
2
3
  from tempfile import TemporaryDirectory
3
4
 
4
5
  from ..utils_background import fail_and_cleanup
5
6
  from ..utils_background import get_activity_and_task_group
7
+ from ..utils_pixi import SOURCE_DIR_NAME
8
+ from ._utils import check_ssh_or_fail_and_cleanup
6
9
  from fractal_server.app.db import get_sync_db
10
+ from fractal_server.app.schemas.v2 import TaskGroupActivityActionV2
11
+ from fractal_server.app.schemas.v2 import TaskGroupActivityStatusV2
12
+ from fractal_server.config import get_settings
7
13
  from fractal_server.logger import reset_logger_handlers
8
14
  from fractal_server.logger import set_logger
9
15
  from fractal_server.ssh._fabric import SingleUseFractalSSH
10
16
  from fractal_server.ssh._fabric import SSHConfig
17
+ from fractal_server.syringe import Inject
11
18
  from fractal_server.tasks.utils import get_log_path
19
+ from fractal_server.tasks.v2.ssh._utils import _customize_and_run_template
20
+ from fractal_server.tasks.v2.utils_background import add_commit_refresh
21
+ from fractal_server.tasks.v2.utils_background import get_current_log
22
+ from fractal_server.tasks.v2.utils_templates import SCRIPTS_SUBFOLDER
23
+ from fractal_server.utils import get_timestamp
12
24
 
13
25
 
14
26
  def reactivate_ssh_pixi(
@@ -42,60 +54,156 @@ def reactivate_ssh_pixi(
42
54
  log_file_path=log_file_path,
43
55
  )
44
56
 
45
- with SingleUseFractalSSH(
46
- ssh_config=ssh_config,
47
- logger_name=LOGGER_NAME,
48
- ) as fractal_ssh:
49
-
50
- with next(get_sync_db()) as db:
51
- success, task_group, activity = get_activity_and_task_group(
52
- task_group_activity_id=task_group_activity_id,
53
- task_group_id=task_group_id,
54
- db=db,
55
- )
56
- if not success:
57
- return
58
-
59
- # Log some info
60
- logger.info("START")
61
- for key, value in task_group.model_dump().items():
62
- logger.debug(f"task_group.{key}: {value}")
63
-
64
- # Check that SSH connection works
57
+ logger.info("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:
65
72
  try:
66
- fractal_ssh.check_connection()
67
- except Exception as e:
68
- logger.error("Cannot establish SSH connection.")
69
- fail_and_cleanup(
73
+ # Check SSH connection
74
+ ssh_ok = check_ssh_or_fail_and_cleanup(
75
+ fractal_ssh=fractal_ssh,
70
76
  task_group=task_group,
71
77
  task_group_activity=activity,
72
78
  logger_name=LOGGER_NAME,
73
79
  log_file_path=log_file_path,
74
- exception=e,
75
80
  db=db,
76
81
  )
77
- return
82
+ if not ssh_ok:
83
+ return
78
84
 
79
- try:
80
- raise NotImplementedError("pixi-task reactivation FIXME")
85
+ # Check that the (remote) task_group source_dir does not
86
+ # exist
87
+ source_dir = Path(
88
+ task_group.path, SOURCE_DIR_NAME
89
+ ).as_posix()
90
+ if fractal_ssh.remote_exists(source_dir):
91
+ error_msg = f"{source_dir} already exists."
92
+ logger.error(error_msg)
93
+ fail_and_cleanup(
94
+ task_group=task_group,
95
+ task_group_activity=activity,
96
+ logger_name=LOGGER_NAME,
97
+ log_file_path=log_file_path,
98
+ exception=FileExistsError(error_msg),
99
+ db=db,
100
+ )
101
+ return
102
+
103
+ settings = Inject(get_settings)
104
+ replacements = {
105
+ (
106
+ "__PIXI_HOME__",
107
+ settings.pixi.versions[task_group.pixi_version],
108
+ ),
109
+ ("__PACKAGE_DIR__", task_group.path),
110
+ ("__TAR_GZ_PATH__", task_group.archive_path),
111
+ (
112
+ "__IMPORT_PACKAGE_NAME__",
113
+ task_group.pkg_name.replace("-", "_"),
114
+ ),
115
+ ("__SOURCE_DIR_NAME__", SOURCE_DIR_NAME),
116
+ ("__FROZEN_OPTION__", "--frozen"),
117
+ }
118
+
119
+ logger.info("installing - START")
120
+
121
+ # Set status to ONGOING and refresh logs
122
+ activity.status = TaskGroupActivityStatusV2.ONGOING
123
+ activity.log = get_current_log(log_file_path)
124
+ activity = add_commit_refresh(obj=activity, db=db)
125
+
126
+ script_dir_remote = Path(
127
+ task_group.path, SCRIPTS_SUBFOLDER
128
+ ).as_posix()
129
+ common_args = dict(
130
+ script_dir_local=(
131
+ Path(tmpdir) / SCRIPTS_SUBFOLDER
132
+ ).as_posix(),
133
+ script_dir_remote=script_dir_remote,
134
+ prefix=(
135
+ f"{int(time.time())}_"
136
+ f"{TaskGroupActivityActionV2.REACTIVATE}"
137
+ ),
138
+ logger_name=LOGGER_NAME,
139
+ fractal_ssh=fractal_ssh,
140
+ )
141
+
142
+ # Run script 1 - extract tar.gz into `source_dir`
143
+ _customize_and_run_template(
144
+ template_filename="pixi_1_extract.sh",
145
+ replacements=replacements,
146
+ **common_args,
147
+ )
148
+ activity.log = get_current_log(log_file_path)
149
+ activity = add_commit_refresh(obj=activity, db=db)
150
+
151
+ # Write pixi.lock into `source_dir`
152
+ pixi_lock_local = Path(tmpdir, "pixi.lock").as_posix()
153
+ pixi_lock_remote = Path(
154
+ task_group.path, SOURCE_DIR_NAME, "pixi.lock"
155
+ ).as_posix()
156
+ logger.info(
157
+ f"Write `env_info` contents into {pixi_lock_local}"
158
+ )
159
+ with open(pixi_lock_local, "w") as f:
160
+ f.write(task_group.env_info)
161
+ fractal_ssh.send_file(
162
+ local=pixi_lock_local,
163
+ remote=pixi_lock_remote,
164
+ )
165
+
166
+ # Run script 2 - run pixi-install command
167
+ _customize_and_run_template(
168
+ template_filename="pixi_2_install.sh",
169
+ replacements=replacements,
170
+ **common_args,
171
+ )
172
+ activity.log = get_current_log(log_file_path)
173
+ activity = add_commit_refresh(obj=activity, db=db)
174
+
175
+ # Run script 3 - post-install
176
+ _customize_and_run_template(
177
+ template_filename="pixi_3_post_install.sh",
178
+ replacements=replacements,
179
+ **common_args,
180
+ )
181
+ activity.log = get_current_log(log_file_path)
182
+ activity = add_commit_refresh(obj=activity, db=db)
183
+
184
+ # Finalize (write metadata to DB)
185
+ activity.status = TaskGroupActivityStatusV2.OK
186
+ activity.timestamp_ended = get_timestamp()
187
+ activity = add_commit_refresh(obj=activity, db=db)
188
+ task_group.active = True
189
+ task_group = add_commit_refresh(obj=task_group, db=db)
190
+ logger.info("END")
81
191
 
82
192
  reset_logger_handlers(logger)
83
193
 
84
194
  except Exception as reactivate_e:
85
- # Delete corrupted venv_path
195
+ # Delete corrupted source_dir
86
196
  try:
87
- logger.info(
88
- f"Now delete folder {task_group.venv_path}"
89
- )
197
+ logger.info(f"Now delete folder {source_dir}")
90
198
  fractal_ssh.remove_folder(
91
- folder=task_group.venv_path,
199
+ folder=source_dir,
92
200
  safe_root=tasks_base_dir,
93
201
  )
94
- logger.info(f"Deleted folder {task_group.venv_path}")
202
+ logger.info(f"Deleted folder {source_dir}")
95
203
  except Exception as rm_e:
96
204
  logger.error(
97
- "Removing folder failed.\n"
98
- f"Original error:\n{str(rm_e)}"
205
+ "Removing folder failed. "
206
+ f"Original error: {str(rm_e)}"
99
207
  )
100
208
 
101
209
  fail_and_cleanup(
@@ -32,14 +32,9 @@ write_log "Changed working directory to ${PACKAGE_DIR}"
32
32
 
33
33
  # -----------------------------------------------------------------------------
34
34
 
35
- FROZEN_FLAG=""
36
- if [[ "${FROZEN_OPTION}" == "true" ]]; then
37
- FROZEN_FLAG="--frozen"
38
- fi
39
-
40
- write_log "START '${PIXI_EXECUTABLE} install ${FROZEN_FLAG} --manifest-path ${PYPROJECT_TOML}'"
41
- ${PIXI_EXECUTABLE} install ${FROZEN_FLAG} --manifest-path "${PYPROJECT_TOML}"
42
- write_log "END '${PIXI_EXECUTABLE} install ${FROZEN_FLAG} --manifest-path ${PYPROJECT_TOML}'"
35
+ write_log "START '${PIXI_EXECUTABLE} install ${FROZEN_OPTION} --manifest-path ${PYPROJECT_TOML}'"
36
+ ${PIXI_EXECUTABLE} install ${FROZEN_OPTION} --manifest-path "${PYPROJECT_TOML}"
37
+ write_log "END '${PIXI_EXECUTABLE} install ${FROZEN_OPTION} --manifest-path ${PYPROJECT_TOML}'"
43
38
  echo
44
39
 
45
40
  TIME_END=$(date +%s)
@@ -30,6 +30,7 @@ def get_activity_and_task_group(
30
30
  task_group_activity_id: int,
31
31
  task_group_id: int,
32
32
  db: DBSyncSession,
33
+ logger_name: str,
33
34
  ) -> tuple[bool, TaskGroupV2, TaskGroupActivityV2]:
34
35
  task_group = db.get(TaskGroupV2, task_group_id)
35
36
  activity = db.get(TaskGroupActivityV2, task_group_activity_id)
@@ -40,6 +41,12 @@ def get_activity_and_task_group(
40
41
  f"{task_group=}\n{activity=}. Exit."
41
42
  )
42
43
  return False, None, None
44
+
45
+ # Log some info about task group
46
+ logger = get_logger(logger_name=logger_name)
47
+ for key, value in task_group.model_dump(exclude={"env_info"}).items():
48
+ logger.debug(f"task_group.{key}: {value}")
49
+
43
50
  return True, task_group, activity
44
51
 
45
52