Skip to content

Commit

Permalink
feat: cli for basic retrieval of an object from the prefect cache
Browse files Browse the repository at this point in the history
  • Loading branch information
pgierz committed Oct 9, 2024
1 parent d4192b3 commit fb32986
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/pymorize/caching.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
This module contains the functions that are used to cache the results of the tasks.
"""

import base64
import json
import pickle
from pathlib import Path
Expand Down Expand Up @@ -42,3 +44,13 @@ def inspect_cache(cache_dir="~/.prefect/storage"):
logger.error(f" Error reading file: {str(e)}")
raise e
logger.info("\n")


def inspect_result(result):
with open(result, "r") as file:
cached_data = json.load(file)
# FIXME: handle pickling library...
pickled_result_base64 = cached_data["result"]
pickled_result = base64.b64decode(pickled_result_base64)
unpickled_result = pickle.loads(pickled_result)
return unpickled_result
13 changes: 13 additions & 0 deletions src/pymorize/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,19 @@ def inspect_prefect(cache_dir, verbose, quiet, logfile, profile_mem):
return 0


@cache.command()
@click_loguru.logging_options
@click_loguru.init_logger()
@click.argument(
"result",
type=click.Path(exists=True),
)
def inspect_result(result, verbose, quiet, logfile, profile_mem):
obj = caching.inspect_result(result)
logger.info(obj)
return 0


################################################################################
################################################################################
################################################################################
Expand Down

0 comments on commit fb32986

Please sign in to comment.