|
12 | 12 | pandas.DataFrame. |
13 | 13 | """ |
14 | 14 |
|
| 15 | +from concurrent.futures import Future |
15 | 16 | from typing import Optional |
16 | 17 |
|
17 | 18 | import executorlib._version |
@@ -43,30 +44,82 @@ def get_cache_data(cache_directory: str) -> list[dict]: |
43 | 44 | return get_cache_data(cache_directory=cache_directory) |
44 | 45 |
|
45 | 46 |
|
| 47 | +def get_future_from_cache( |
| 48 | + cache_directory: str, |
| 49 | + cache_key: str, |
| 50 | +) -> Future: |
| 51 | + """ |
| 52 | + Reload future from HDF5 file in cache directory with the given cache key. The function checks if the output file |
| 53 | + exists, if not it checks for the input file. If neither of them exist, it raises a FileNotFoundError. If the output |
| 54 | + file exists, it loads the output and sets it as the result of the future. If only the input file exists, it checks |
| 55 | + if the execution is finished and if there was an error. If there was no error, it sets the output as the result of |
| 56 | + the future, otherwise it raises the error. |
| 57 | +
|
| 58 | + Args: |
| 59 | + cache_directory (str): The directory to store cache files. |
| 60 | + cache_key (str): The key of the cache file to be reloaded. |
| 61 | +
|
| 62 | + Returns: |
| 63 | + Future: Future object containing the result of the execution of the python function. |
| 64 | + """ |
| 65 | + from executorlib.standalone.hdf import get_future_from_cache |
| 66 | + |
| 67 | + return get_future_from_cache( |
| 68 | + cache_directory=cache_directory, |
| 69 | + cache_key=cache_key, |
| 70 | + ) |
| 71 | + |
| 72 | + |
46 | 73 | def terminate_tasks_in_cache( |
47 | 74 | cache_directory: str, |
48 | | - config_directory: Optional[str] = None, |
| 75 | + pysqa_config_directory: Optional[str] = None, |
49 | 76 | backend: Optional[str] = None, |
50 | 77 | ): |
51 | 78 | """ |
52 | 79 | Delete all jobs stored in the cache directory from the queuing system |
53 | 80 |
|
54 | 81 | Args: |
55 | 82 | cache_directory (str): The directory to store cache files. |
56 | | - config_directory (str, optional): path to the config directory. |
| 83 | + pysqa_config_directory (str, optional): path to the pysqa config directory. |
57 | 84 | backend (str, optional): name of the backend used to spawn tasks ["slurm", "flux"]. |
58 | 85 | """ |
59 | 86 | from executorlib.task_scheduler.file.spawner_pysqa import terminate_tasks_in_cache |
60 | 87 |
|
61 | 88 | return terminate_tasks_in_cache( |
62 | 89 | cache_directory=cache_directory, |
63 | | - config_directory=config_directory, |
| 90 | + pysqa_config_directory=pysqa_config_directory, |
| 91 | + backend=backend, |
| 92 | + ) |
| 93 | + |
| 94 | + |
| 95 | +def terminate_task_in_cache( |
| 96 | + cache_directory: str, |
| 97 | + cache_key: str, |
| 98 | + pysqa_config_directory: Optional[str] = None, |
| 99 | + backend: Optional[str] = None, |
| 100 | +): |
| 101 | + """ |
| 102 | + Delete a specific job stored in the cache directory from the queuing system |
| 103 | +
|
| 104 | + Args: |
| 105 | + cache_directory (str): The directory to store cache files. |
| 106 | + cache_key (str): The key of the cache file to be deleted. |
| 107 | + pysqa_config_directory (str, optional): path to the pysqa config directory. |
| 108 | + backend (str, optional): name of the backend used to spawn tasks ["slurm", "flux"]. |
| 109 | + """ |
| 110 | + from executorlib.task_scheduler.file.spawner_pysqa import terminate_task_in_cache |
| 111 | + |
| 112 | + return terminate_task_in_cache( |
| 113 | + cache_directory=cache_directory, |
| 114 | + cache_key=cache_key, |
| 115 | + pysqa_config_directory=pysqa_config_directory, |
64 | 116 | backend=backend, |
65 | 117 | ) |
66 | 118 |
|
67 | 119 |
|
68 | 120 | __all__: list[str] = [ |
69 | 121 | "get_cache_data", |
| 122 | + "get_future_from_cache", |
70 | 123 | "get_item_from_future", |
71 | 124 | "split_future", |
72 | 125 | "terminate_tasks_in_cache", |
|
0 commit comments