fractal-server 2.8.1__py3-none-any.whl → 2.9.0a1__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 (54) hide show
  1. fractal_server/__init__.py +1 -1
  2. fractal_server/app/db/__init__.py +2 -35
  3. fractal_server/app/models/v2/__init__.py +3 -3
  4. fractal_server/app/models/v2/task.py +0 -72
  5. fractal_server/app/models/v2/task_group.py +102 -0
  6. fractal_server/app/routes/admin/v1.py +1 -20
  7. fractal_server/app/routes/admin/v2/job.py +1 -20
  8. fractal_server/app/routes/admin/v2/task_group.py +53 -13
  9. fractal_server/app/routes/api/v2/__init__.py +11 -2
  10. fractal_server/app/routes/api/v2/{_aux_functions_task_collection.py → _aux_functions_task_lifecycle.py} +43 -0
  11. fractal_server/app/routes/api/v2/_aux_functions_tasks.py +27 -17
  12. fractal_server/app/routes/api/v2/task_collection.py +30 -55
  13. fractal_server/app/routes/api/v2/task_collection_custom.py +3 -3
  14. fractal_server/app/routes/api/v2/task_group.py +83 -14
  15. fractal_server/app/routes/api/v2/task_group_lifecycle.py +221 -0
  16. fractal_server/app/routes/api/v2/workflow.py +1 -1
  17. fractal_server/app/routes/api/v2/workflow_import.py +2 -2
  18. fractal_server/app/routes/aux/_timestamp.py +18 -0
  19. fractal_server/app/schemas/_validators.py +1 -2
  20. fractal_server/app/schemas/v2/__init__.py +3 -2
  21. fractal_server/app/schemas/v2/task_collection.py +0 -21
  22. fractal_server/app/schemas/v2/task_group.py +31 -8
  23. fractal_server/config.py +11 -56
  24. fractal_server/migrations/versions/3082479ac4ea_taskgroup_activity_and_venv_info_to_.py +105 -0
  25. fractal_server/ssh/_fabric.py +18 -0
  26. fractal_server/tasks/utils.py +2 -12
  27. fractal_server/tasks/v2/local/__init__.py +3 -0
  28. fractal_server/tasks/v2/local/collect.py +291 -0
  29. fractal_server/tasks/v2/local/deactivate.py +210 -0
  30. fractal_server/tasks/v2/local/reactivate.py +159 -0
  31. fractal_server/tasks/v2/local/utils_local.py +45 -0
  32. fractal_server/tasks/v2/ssh/__init__.py +0 -0
  33. fractal_server/tasks/v2/ssh/collect.py +386 -0
  34. fractal_server/tasks/v2/ssh/deactivate.py +2 -0
  35. fractal_server/tasks/v2/ssh/reactivate.py +2 -0
  36. fractal_server/tasks/v2/templates/{_2_preliminary_pip_operations.sh → 1_create_venv.sh} +6 -7
  37. fractal_server/tasks/v2/templates/{_3_pip_install.sh → 2_pip_install.sh} +8 -1
  38. fractal_server/tasks/v2/templates/{_4_pip_freeze.sh → 3_pip_freeze.sh} +0 -7
  39. fractal_server/tasks/v2/templates/{_5_pip_show.sh → 4_pip_show.sh} +5 -6
  40. fractal_server/tasks/v2/templates/5_get_venv_size_and_file_number.sh +10 -0
  41. fractal_server/tasks/v2/templates/6_pip_install_from_freeze.sh +35 -0
  42. fractal_server/tasks/v2/utils_background.py +42 -103
  43. fractal_server/tasks/v2/utils_templates.py +32 -2
  44. fractal_server/utils.py +4 -2
  45. {fractal_server-2.8.1.dist-info → fractal_server-2.9.0a1.dist-info}/METADATA +2 -3
  46. {fractal_server-2.8.1.dist-info → fractal_server-2.9.0a1.dist-info}/RECORD +50 -39
  47. fractal_server/app/models/v2/collection_state.py +0 -22
  48. fractal_server/tasks/v2/collection_local.py +0 -357
  49. fractal_server/tasks/v2/collection_ssh.py +0 -352
  50. fractal_server/tasks/v2/templates/_1_create_venv.sh +0 -42
  51. /fractal_server/tasks/v2/{database_operations.py → utils_database.py} +0 -0
  52. {fractal_server-2.8.1.dist-info → fractal_server-2.9.0a1.dist-info}/LICENSE +0 -0
  53. {fractal_server-2.8.1.dist-info → fractal_server-2.9.0a1.dist-info}/WHEEL +0 -0
  54. {fractal_server-2.8.1.dist-info → fractal_server-2.9.0a1.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,386 @@
1
+ import logging
2
+ import os
3
+ import time
4
+ from pathlib import Path
5
+ from tempfile import TemporaryDirectory
6
+
7
+ from ..utils_background import _prepare_tasks_metadata
8
+ from ..utils_background import fail_and_cleanup
9
+ from ..utils_database import create_db_tasks_and_update_task_group
10
+ from fractal_server.app.db import get_sync_db
11
+ from fractal_server.app.models.v2 import TaskGroupActivityV2
12
+ from fractal_server.app.models.v2 import TaskGroupV2
13
+ from fractal_server.app.schemas.v2 import TaskGroupActivityActionV2
14
+ from fractal_server.app.schemas.v2 import TaskGroupActivityStatusV2
15
+ from fractal_server.app.schemas.v2.manifest import ManifestV2
16
+ from fractal_server.logger import get_logger
17
+ from fractal_server.logger import set_logger
18
+ from fractal_server.ssh._fabric import FractalSSH
19
+ from fractal_server.tasks.v2.utils_background import add_commit_refresh
20
+ from fractal_server.tasks.v2.utils_background import get_current_log
21
+ from fractal_server.tasks.v2.utils_package_names import compare_package_names
22
+ from fractal_server.tasks.v2.utils_python_interpreter import (
23
+ get_python_interpreter_v2,
24
+ )
25
+ from fractal_server.tasks.v2.utils_templates import customize_template
26
+ from fractal_server.tasks.v2.utils_templates import get_collection_replacements
27
+ from fractal_server.tasks.v2.utils_templates import (
28
+ parse_script_pip_show_stdout,
29
+ )
30
+ from fractal_server.tasks.v2.utils_templates import SCRIPTS_SUBFOLDER
31
+ from fractal_server.utils import get_timestamp
32
+
33
+ LOGGER_NAME = __name__
34
+
35
+
36
+ def _customize_and_run_template(
37
+ *,
38
+ template_filename: str,
39
+ replacements: list[tuple[str, str]],
40
+ script_dir_local: str,
41
+ prefix: str,
42
+ fractal_ssh: FractalSSH,
43
+ script_dir_remote: str,
44
+ logger_name: str,
45
+ ) -> str:
46
+ """
47
+ Customize one of the template bash scripts, transfer it to the remote host
48
+ via SFTP and then run it via SSH.
49
+
50
+ Args:
51
+ template_filename: Filename of the template file (ends with ".sh").
52
+ replacements: Dictionary of replacements.
53
+ script_dir: Local folder where the script will be placed.
54
+ prefix: Prefix for the script filename.
55
+ fractal_ssh: FractalSSH object
56
+ script_dir_remote: Remote scripts directory
57
+ """
58
+ logger = get_logger(logger_name=logger_name)
59
+ logger.debug(f"_customize_and_run_template {template_filename} - START")
60
+
61
+ # Prepare name and path of script
62
+ if not template_filename.endswith(".sh"):
63
+ raise ValueError(
64
+ f"Invalid {template_filename=} (it must end with '.sh')."
65
+ )
66
+ script_filename = f"{prefix}_{template_filename}"
67
+ script_path_local = Path(script_dir_local) / script_filename
68
+
69
+ customize_template(
70
+ template_name=template_filename,
71
+ replacements=replacements,
72
+ script_path=script_path_local,
73
+ )
74
+
75
+ # Transfer script to remote host
76
+ script_path_remote = os.path.join(
77
+ script_dir_remote,
78
+ script_filename,
79
+ )
80
+ logger.debug(f"Now transfer {script_path_local=} over SSH.")
81
+ fractal_ssh.send_file(
82
+ local=script_path_local,
83
+ remote=script_path_remote,
84
+ )
85
+
86
+ # Execute script remotely
87
+ cmd = f"bash {script_path_remote}"
88
+ logger.debug(f"Now run '{cmd}' over SSH.")
89
+ stdout = fractal_ssh.run_command(cmd=cmd)
90
+ logger.debug(f"Standard output of '{cmd}':\n{stdout}")
91
+
92
+ logger.debug(f"_customize_and_run_template {template_filename} - END")
93
+ return stdout
94
+
95
+
96
+ def _copy_wheel_file_ssh(
97
+ task_group: TaskGroupV2, fractal_ssh: FractalSSH
98
+ ) -> str:
99
+ logger = get_logger(LOGGER_NAME)
100
+ source = task_group.wheel_path
101
+ dest = (
102
+ Path(task_group.path) / Path(task_group.wheel_path).name
103
+ ).as_posix()
104
+ cmd = f"cp {source} {dest}"
105
+ logger.debug(f"[_copy_wheel_file] START {source=} {dest=}")
106
+ fractal_ssh.run_command(cmd=cmd)
107
+ logger.debug(f"[_copy_wheel_file] END {source=} {dest=}")
108
+ return dest
109
+
110
+
111
+ def collect_ssh(
112
+ *,
113
+ task_group_id: int,
114
+ task_group_activity_id: int,
115
+ fractal_ssh: FractalSSH,
116
+ tasks_base_dir: str,
117
+ ) -> None:
118
+ """
119
+ Collect a task package over SSH
120
+
121
+ This function is run as a background task, therefore exceptions must be
122
+ handled.
123
+
124
+ NOTE: by making this function sync, it runs within a thread - due to
125
+ starlette/fastapi handling of background tasks (see
126
+ https://github.com/encode/starlette/blob/master/starlette/background.py).
127
+
128
+
129
+ Arguments:
130
+ task_group_id:
131
+ task_group_activity_id:
132
+ fractal_ssh:
133
+ tasks_base_dir:
134
+ Only used as a `safe_root` in `remove_dir`, and typically set to
135
+ `user_settings.ssh_tasks_dir`.
136
+ """
137
+
138
+ # Work within a temporary folder, where also logs will be placed
139
+ with TemporaryDirectory() as tmpdir:
140
+ LOGGER_NAME = "task_collection_ssh"
141
+ log_file_path = Path(tmpdir) / "log"
142
+ logger = set_logger(
143
+ logger_name=LOGGER_NAME,
144
+ log_file_path=log_file_path,
145
+ )
146
+
147
+ with next(get_sync_db()) as db:
148
+
149
+ # Get main objects from db
150
+ activity = db.get(TaskGroupActivityV2, task_group_activity_id)
151
+ task_group = db.get(TaskGroupV2, task_group_id)
152
+ if activity is None or task_group is None:
153
+ # Use `logging` directly
154
+ logging.error(
155
+ "Cannot find database rows with "
156
+ f"{task_group_id=} and {task_group_activity_id=}:\n"
157
+ f"{task_group=}\n{activity=}. Exit."
158
+ )
159
+ return
160
+
161
+ # Log some info
162
+ logger.debug("START")
163
+ for key, value in task_group.model_dump().items():
164
+ logger.debug(f"task_group.{key}: {value}")
165
+
166
+ # Check that SSH connection works
167
+ try:
168
+ fractal_ssh.check_connection()
169
+ except Exception as e:
170
+ logger.error("Cannot establish SSH connection.")
171
+ fail_and_cleanup(
172
+ task_group=task_group,
173
+ task_group_activity=activity,
174
+ logger_name=LOGGER_NAME,
175
+ log_file_path=log_file_path,
176
+ exception=e,
177
+ db=db,
178
+ )
179
+ return
180
+
181
+ # Check that the (remote) task_group path does not exist
182
+ if fractal_ssh.remote_exists(task_group.path):
183
+ error_msg = f"{task_group.path} already exists."
184
+ logger.error(error_msg)
185
+ fail_and_cleanup(
186
+ task_group=task_group,
187
+ task_group_activity=activity,
188
+ logger_name=LOGGER_NAME,
189
+ log_file_path=log_file_path,
190
+ exception=FileExistsError(error_msg),
191
+ db=db,
192
+ )
193
+ return
194
+
195
+ try:
196
+
197
+ # Prepare replacements for templates
198
+ replacements = get_collection_replacements(
199
+ task_group=task_group,
200
+ python_bin=get_python_interpreter_v2(
201
+ python_version=task_group.python_version
202
+ ),
203
+ )
204
+
205
+ # Prepare common arguments for `_customize_and_run_template``
206
+ script_dir_remote = (
207
+ Path(task_group.path) / SCRIPTS_SUBFOLDER
208
+ ).as_posix()
209
+ common_args = dict(
210
+ replacements=replacements,
211
+ script_dir_local=(
212
+ Path(tmpdir) / SCRIPTS_SUBFOLDER
213
+ ).as_posix(),
214
+ script_dir_remote=script_dir_remote,
215
+ prefix=(
216
+ f"{int(time.time())}_"
217
+ f"{TaskGroupActivityActionV2.COLLECT}_"
218
+ ),
219
+ fractal_ssh=fractal_ssh,
220
+ logger_name=LOGGER_NAME,
221
+ )
222
+
223
+ # Create remote `task_group.path` and `script_dir_remote`
224
+ # folders (note that because of `parents=True` we are in
225
+ # the `no error if existing, make parent directories as
226
+ # needed` scenario for `mkdir`)
227
+ fractal_ssh.mkdir(folder=task_group.path, parents=True)
228
+ fractal_ssh.mkdir(folder=script_dir_remote, parents=True)
229
+
230
+ # Copy wheel file into task group path
231
+ if task_group.wheel_path:
232
+ new_wheel_path = _copy_wheel_file_ssh(
233
+ task_group=task_group,
234
+ fractal_ssh=fractal_ssh,
235
+ )
236
+ task_group.wheel_path = new_wheel_path
237
+ task_group = add_commit_refresh(obj=task_group, db=db)
238
+
239
+ logger.debug("installing - START")
240
+
241
+ # Set status to ONGOING and refresh logs
242
+ activity.status = TaskGroupActivityStatusV2.ONGOING
243
+ activity.log = get_current_log(log_file_path)
244
+ activity = add_commit_refresh(obj=activity, db=db)
245
+
246
+ # Run script 1
247
+ stdout = _customize_and_run_template(
248
+ template_filename="1_create_venv.sh",
249
+ **common_args,
250
+ )
251
+ activity.log = get_current_log(log_file_path)
252
+ activity = add_commit_refresh(obj=activity, db=db)
253
+
254
+ # Run script 2
255
+ stdout = _customize_and_run_template(
256
+ template_filename="2_pip_install.sh",
257
+ **common_args,
258
+ )
259
+ activity.log = get_current_log(log_file_path)
260
+ activity = add_commit_refresh(obj=activity, db=db)
261
+
262
+ # Run script 3
263
+ pip_freeze_stdout = _customize_and_run_template(
264
+ template_filename="3_pip_freeze.sh",
265
+ **common_args,
266
+ )
267
+ activity.log = get_current_log(log_file_path)
268
+ activity = add_commit_refresh(obj=activity, db=db)
269
+
270
+ # Run script 4
271
+ stdout = _customize_and_run_template(
272
+ template_filename="4_pip_show.sh",
273
+ **common_args,
274
+ )
275
+ activity.log = get_current_log(log_file_path)
276
+ activity = add_commit_refresh(obj=activity, db=db)
277
+
278
+ # Run script 5
279
+ venv_info = _customize_and_run_template(
280
+ template_filename="5_get_venv_size_and_file_number.sh",
281
+ **common_args,
282
+ )
283
+ venv_size, venv_file_number = venv_info.split()
284
+ activity.log = get_current_log(log_file_path)
285
+ activity = add_commit_refresh(obj=activity, db=db)
286
+
287
+ pkg_attrs = parse_script_pip_show_stdout(stdout)
288
+
289
+ for key, value in pkg_attrs.items():
290
+ logger.debug(f"parsed from pip-show: {key}={value}")
291
+ # Check package_name match between pip show and task-group
292
+ package_name_pip_show = pkg_attrs.get("package_name")
293
+ package_name_task_group = task_group.pkg_name
294
+ compare_package_names(
295
+ pkg_name_pip_show=package_name_pip_show,
296
+ pkg_name_task_group=package_name_task_group,
297
+ logger_name=LOGGER_NAME,
298
+ )
299
+ # Extract/drop parsed attributes
300
+ package_name = package_name_task_group
301
+ python_bin = pkg_attrs.pop("python_bin")
302
+ package_root_parent_remote = pkg_attrs.pop(
303
+ "package_root_parent"
304
+ )
305
+ manifest_path_remote = pkg_attrs.pop("manifest_path")
306
+
307
+ # TODO SSH: Use more robust logic to determine `package_root`.
308
+ # Examples: use `importlib.util.find_spec`, or parse the output
309
+ # of `pip show --files {package_name}`.
310
+ package_name_underscore = package_name.replace("-", "_")
311
+ package_root_remote = (
312
+ Path(package_root_parent_remote) / package_name_underscore
313
+ ).as_posix()
314
+
315
+ # Read and validate remote manifest file
316
+ pkg_manifest_dict = fractal_ssh.read_remote_json_file(
317
+ manifest_path_remote
318
+ )
319
+ logger.info(f"Loaded {manifest_path_remote=}")
320
+ pkg_manifest = ManifestV2(**pkg_manifest_dict)
321
+ logger.info("Manifest is a valid ManifestV2")
322
+
323
+ logger.info("_prepare_tasks_metadata - start")
324
+ task_list = _prepare_tasks_metadata(
325
+ package_manifest=pkg_manifest,
326
+ package_version=task_group.version,
327
+ package_root=Path(package_root_remote),
328
+ python_bin=Path(python_bin),
329
+ )
330
+ logger.info("_prepare_tasks_metadata - end")
331
+
332
+ logger.info("create_db_tasks_and_update_task_group - " "start")
333
+ create_db_tasks_and_update_task_group(
334
+ task_list=task_list,
335
+ task_group_id=task_group.id,
336
+ db=db,
337
+ )
338
+ logger.info("create_db_tasks_and_update_task_group - end")
339
+
340
+ # Update task_group data
341
+ logger.info(
342
+ "Add pip_freeze, venv_size and venv_file_number "
343
+ "to TaskGroupV2 - start"
344
+ )
345
+ task_group.pip_freeze = pip_freeze_stdout
346
+ task_group.venv_size_in_kB = int(venv_size)
347
+ task_group.venv_file_number = int(venv_file_number)
348
+ task_group = add_commit_refresh(obj=task_group, db=db)
349
+ logger.info(
350
+ "Add pip_freeze, venv_size and venv_file_number "
351
+ "to TaskGroupV2 - end"
352
+ )
353
+
354
+ # Finalize (write metadata to DB)
355
+ logger.debug("finalising - START")
356
+ activity.status = TaskGroupActivityStatusV2.OK
357
+ activity.timestamp_ended = get_timestamp()
358
+ activity = add_commit_refresh(obj=activity, db=db)
359
+ logger.debug("finalising - END")
360
+ logger.debug("END")
361
+
362
+ logger.debug("END")
363
+
364
+ except Exception as collection_e:
365
+ # Delete corrupted package dir
366
+ try:
367
+ logger.info(f"Now delete remote folder {task_group.path}")
368
+ fractal_ssh.remove_folder(
369
+ folder=task_group.path,
370
+ safe_root=tasks_base_dir,
371
+ )
372
+ logger.info(f"Deleted remoted folder {task_group.path}")
373
+ except Exception as e_rm:
374
+ logger.error(
375
+ "Removing folder failed. "
376
+ f"Original error:\n{str(e_rm)}"
377
+ )
378
+ fail_and_cleanup(
379
+ task_group=task_group,
380
+ task_group_activity=activity,
381
+ log_file_path=log_file_path,
382
+ logger_name=LOGGER_NAME,
383
+ exception=collection_e,
384
+ db=db,
385
+ )
386
+ return
@@ -0,0 +1,2 @@
1
+ def deactivate_ssh():
2
+ pass
@@ -0,0 +1,2 @@
1
+ def reactivate_ssh():
2
+ pass
@@ -5,18 +5,17 @@ write_log(){
5
5
  echo "[collect-task, $TIMESTAMP] $1"
6
6
  }
7
7
 
8
+
8
9
  # Variables to be filled within fractal-server
9
10
  PACKAGE_ENV_DIR=__PACKAGE_ENV_DIR__
11
+ PYTHON=__PYTHON__
10
12
 
11
13
  TIME_START=$(date +%s)
12
14
 
13
- VENVPYTHON=${PACKAGE_ENV_DIR}/bin/python
14
-
15
- # Upgrade pip
16
- write_log "START upgrade pip"
17
- "$VENVPYTHON" -m pip install --no-cache-dir "pip<=__FRACTAL_MAX_PIP_VERSION__" --upgrade
18
- "$VENVPYTHON" -m pip install --no-cache-dir setuptools
19
- write_log "END upgrade pip"
15
+ # Create venv
16
+ write_log "START create venv in ${PACKAGE_ENV_DIR}"
17
+ "$PYTHON" -m venv "$PACKAGE_ENV_DIR" --copies
18
+ write_log "END create venv in ${PACKAGE_ENV_DIR}"
20
19
  echo
21
20
 
22
21
  # End
@@ -5,16 +5,23 @@ write_log(){
5
5
  echo "[collect-task, $TIMESTAMP] $1"
6
6
  }
7
7
 
8
-
9
8
  # Variables to be filled within fractal-server
10
9
  PACKAGE_ENV_DIR=__PACKAGE_ENV_DIR__
11
10
  INSTALL_STRING=__INSTALL_STRING__
12
11
  PINNED_PACKAGE_LIST="__PINNED_PACKAGE_LIST__"
12
+ FRACTAL_MAX_PIP_VERSION="__FRACTAL_MAX_PIP_VERSION__"
13
13
 
14
14
  TIME_START=$(date +%s)
15
15
 
16
16
  VENVPYTHON=${PACKAGE_ENV_DIR}/bin/python
17
17
 
18
+ # Upgrade `pip` and install `setuptools`
19
+ write_log "START upgrade pip and install setuptools"
20
+ "$VENVPYTHON" -m pip install --no-cache-dir "pip<=${FRACTAL_MAX_PIP_VERSION}" --upgrade
21
+ "$VENVPYTHON" -m pip install --no-cache-dir setuptools
22
+ write_log "END upgrade pip and install setuptools"
23
+ echo
24
+
18
25
  # Install package
19
26
  write_log "START install ${INSTALL_STRING}"
20
27
  "$VENVPYTHON" -m pip install --no-cache-dir "$INSTALL_STRING"
@@ -1,12 +1,5 @@
1
1
  set -e
2
2
 
3
- write_log(){
4
- TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
5
- echo "[collect-task, $TIMESTAMP] $1"
6
- }
7
-
8
-
9
-
10
3
  # Variables to be filled within fractal-server
11
4
  PACKAGE_ENV_DIR=__PACKAGE_ENV_DIR__
12
5
 
@@ -11,7 +11,6 @@ PACKAGE_ENV_DIR=__PACKAGE_ENV_DIR__
11
11
  PACKAGE_NAME=__PACKAGE_NAME__
12
12
 
13
13
 
14
-
15
14
  TIME_START=$(date +%s)
16
15
 
17
16
  VENVPYTHON=${PACKAGE_ENV_DIR}/bin/python
@@ -38,16 +37,16 @@ echo
38
37
  MANIFEST_RELATIVE_PATH=$($VENVPYTHON -m pip show "$PACKAGE_NAME" --files | grep "__FRACTAL_MANIFEST__.json" | tr -d "[:space:]")
39
38
  write_log "Manifest relative path: $MANIFEST_RELATIVE_PATH"
40
39
  echo
41
- MANIFEST_ABSOLUTE_PATH="${PACKAGE_PARENT_FOLDER}/${MANIFEST_RELATIVE_PATH}"
42
- write_log "Manifest absolute path: $MANIFEST_ABSOLUTE_PATH"
43
- echo
44
- if [ -f "$MANIFEST_ABSOLUTE_PATH" ]; then
40
+ if [ "$MANIFEST_RELATIVE_PATH" != "" ]; then
45
41
  write_log "OK: manifest path exists"
46
42
  echo
47
43
  else
48
- write_log "ERROR: manifest path not found at $MANIFEST_ABSOLUTE_PATH"
44
+ write_log "ERROR: manifest path not found for $PACKAGE_NAME"
49
45
  exit 2
50
46
  fi
47
+ MANIFEST_ABSOLUTE_PATH="${PACKAGE_PARENT_FOLDER}/${MANIFEST_RELATIVE_PATH}"
48
+ write_log "Manifest absolute path: $MANIFEST_ABSOLUTE_PATH"
49
+ echo
51
50
 
52
51
  # End
53
52
  TIME_END=$(date +%s)
@@ -0,0 +1,10 @@
1
+ set -e
2
+
3
+ # Variables to be filled within fractal-server
4
+ PACKAGE_ENV_DIR=__PACKAGE_ENV_DIR__
5
+
6
+ # Find memory usage and file number
7
+ ENV_DISK_USAGE=$(du -sk "${PACKAGE_ENV_DIR}" | cut -f1)
8
+ ENV_FILE_NUMBER=$(find "${PACKAGE_ENV_DIR}" -type f | wc -l)
9
+
10
+ echo $ENV_DISK_USAGE $ENV_FILE_NUMBER
@@ -0,0 +1,35 @@
1
+ set -e
2
+
3
+ write_log(){
4
+ TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
5
+ echo "[collect-task, $TIMESTAMP] $1"
6
+ }
7
+
8
+ # Variables to be filled within fractal-server
9
+ PACKAGE_ENV_DIR=__PACKAGE_ENV_DIR__
10
+ PIP_FREEZE_FILE=__PIP_FREEZE_FILE__
11
+ FRACTAL_MAX_PIP_VERSION=__FRACTAL_MAX_PIP_VERSION__
12
+
13
+ TIME_START=$(date +%s)
14
+
15
+ VENVPYTHON=${PACKAGE_ENV_DIR}/bin/python
16
+
17
+ # Upgrade `pip` and install `setuptools`
18
+ write_log "START upgrade pip and install setuptools"
19
+ "$VENVPYTHON" -m pip install --no-cache-dir "pip<=${FRACTAL_MAX_PIP_VERSION}" --upgrade
20
+ "$VENVPYTHON" -m pip install --no-cache-dir setuptools
21
+ write_log "END upgrade pip and install setuptools"
22
+ echo
23
+
24
+ # Install from pip-freeze file
25
+ write_log "START installing requirements from ${PIP_FREEZE_FILE}"
26
+ "$VENVPYTHON" -m pip install -r "${PIP_FREEZE_FILE}"
27
+ write_log "END installing requirements from ${PIP_FREEZE_FILE}"
28
+ echo
29
+
30
+ # End
31
+ TIME_END=$(date +%s)
32
+ write_log "All good up to here."
33
+ write_log "Elapsed: $((TIME_END - TIME_START)) seconds"
34
+ write_log "Exit."
35
+ echo