flytekit icon indicating copy to clipboard operation
flytekit copied to clipboard

Enable cache in shell task

Open pingsutw opened this issue 2 years ago • 1 comments

TL;DR

Create task metadata and pass it to PythonInstanceTask.

Type

  • [x] Bug Fix
  • [ ] Feature
  • [ ] Plugin

Are all requirements met?

  • [x] Code completed
  • [ ] Smoke tested
  • [ ] Unit tests added
  • [ ] Code documentation added
  • [ ] Any pending items have an associated Issue

Complete description

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

pingsutw avatar Nov 09 '23 01:11 pingsutw

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (9122037) 53.92% compared to head (93a4fbe) 62.79%. Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1945      +/-   ##
==========================================
+ Coverage   53.92%   62.79%   +8.87%     
==========================================
  Files         208      312     +104     
  Lines       18022    23127    +5105     
  Branches     2281     3493    +1212     
==========================================
+ Hits         9718    14523    +4805     
- Misses       7893     8182     +289     
- Partials      411      422      +11     
Files Coverage Δ
flytekit/core/python_function_task.py 41.17% <50.00%> (+0.15%) :arrow_up:

... and 127 files with indirect coverage changes

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Nov 09 '23 02:11 codecov[bot]