-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split shared cache in backend and frontend (#443)
* Split shared cache in backend and frontend * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a74c8f3
commit 0751a0d
Showing
5 changed files
with
70 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import sys | ||
|
||
from executorlib.shared.cache import execute_task_in_file | ||
from executorlib.cache.backend import backend_execute_task_in_file | ||
|
||
if __name__ == "__main__": | ||
execute_task_in_file(file_name=sys.argv[1]) | ||
backend_execute_task_in_file(file_name=sys.argv[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import os | ||
from typing import Any | ||
|
||
from executorlib.shared.cache import FutureItem | ||
from executorlib.shared.hdf import dump, load | ||
|
||
|
||
def backend_load_file(file_name: str) -> dict: | ||
""" | ||
Load the data from an HDF5 file and convert FutureItem objects to their results. | ||
Args: | ||
file_name (str): The name of the HDF5 file. | ||
Returns: | ||
dict: The loaded data from the file. | ||
""" | ||
apply_dict = load(file_name=file_name) | ||
apply_dict["args"] = [ | ||
arg if not isinstance(arg, FutureItem) else arg.result() | ||
for arg in apply_dict["args"] | ||
] | ||
apply_dict["kwargs"] = { | ||
key: arg if not isinstance(arg, FutureItem) else arg.result() | ||
for key, arg in apply_dict["kwargs"].items() | ||
} | ||
return apply_dict | ||
|
||
|
||
def backend_write_file(file_name: str, output: Any) -> None: | ||
""" | ||
Write the output to an HDF5 file. | ||
Args: | ||
file_name (str): The name of the HDF5 file. | ||
output (Any): The output to be written. | ||
Returns: | ||
None | ||
""" | ||
file_name_out = os.path.splitext(file_name)[0] | ||
os.rename(file_name, file_name_out + ".h5ready") | ||
dump(file_name=file_name_out + ".h5ready", data_dict={"output": output}) | ||
os.rename(file_name_out + ".h5ready", file_name_out + ".h5out") | ||
|
||
|
||
def backend_execute_task_in_file(file_name: str) -> None: | ||
""" | ||
Execute the task stored in a given HDF5 file. | ||
Args: | ||
file_name (str): The file name of the HDF5 file as an absolute path. | ||
Returns: | ||
None | ||
""" | ||
apply_dict = backend_load_file(file_name=file_name) | ||
result = apply_dict["fn"].__call__(*apply_dict["args"], **apply_dict["kwargs"]) | ||
backend_write_file( | ||
file_name=file_name, | ||
output=result, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters