<#1945 Enable cache in shell task> Pull request op...
# flyte-github
a
#1945 Enable cache in shell task Pull request opened by pingsutw TL;DR Create task metadata and pass it to
PythonInstanceTask
. Type ☑︎ Bug Fix ☐ Feature ☐ Plugin Are all requirements met? ☑︎ Code completed ☐ Smoke tested ☐ Unit tests added ☐ Code documentation added ☐ Any pending items have an associated Issue Complete description
Copy code
from flytekit import task, workflow, ImageSpec, dynamic, kwtypes
from flytekit.extras.tasks.shell import ShellTask, OutputLocation
from flytekit.types.file import FlyteFile

new_flytekit = "git+https://github.com/flyteorg/flytekit.git@master"
image = ImageSpec(apt_packages=["git"], packages=[new_flytekit], registry="pingsutw")


cache_repro = ShellTask(
    name="cache_repro",
    debug=True,
    cache=True,
    cache_version="1.0",
    script=
    """
    echo "Hello World1, {inputs.msg}" > {outputs.o}
    """,
    inputs=kwtypes(msg=str),
    output_locs=[OutputLocation(var="o", var_type=FlyteFile, location='/tmp/repro.txt')],
)


@task(cache=True, cache_version="1.0")
def t1(a: int) -> int:
    print(a)
    return a + 2


@task(cache=True, cache_version="1.0")
def t2(f: FlyteFile) -> FlyteFile:
    print(f)
    return f


@workflow
def wf():
    f = cache_repro(msg="hello")
    t2(f=f)
    t1(a=3)


if __name__ == "__main__":
    wf()

image▾

Tracking Issue NA Follow-up issue NA flyteorg/flytekit GitHub Actions: build (macos-latest, 3.11) GitHub Actions: build (macos-latest, 3.8) GitHub Actions: build (windows-latest, 3.11) GitHub Actions: build-integration (ubuntu-latest, 3.11) GitHub Actions: build (windows-latest, 3.8) GitHub Actions: build (ubuntu-latest, 3.11) GitHub Actions: build-integration (ubuntu-latest, 3.8) ✅ 6 other checks have passed 6/13 successful checks