Hi, We have many Flyte tasks with same, repeatati...
# flyte-support
m
Hi, We have many Flyte tasks with same, repeatative configurations like shown below.
Copy code
@task(
    cache=False if os.environ.get("ENVIRONMENT") == "test" else True,
    cache_serialize=False if os.environ.get("ENVIRONMENT") == "test" else True,
    cache_version="1.0",
    retries=3,
)
def my_awesome_task(common_input_1: str, common_input_2: str) -> str:
    # my magical task code which returns a string
We have at least 10 such tasks. While all the tasks are working fine, is there any way to avoid this repeatative / boiler plate code and pass same config to each task? Using
@wrapper
decoration won't help here. Any idea how we can reduce this boilerplate code? or - have I written tasks in wrong way?
s
You can write the config to a dict and unpack it in the decorator:
Copy code
task_config = {
    "cache": False if os.environ.get("ENVIRONMENT") == "test" else True,
     "cache_serialize": False if os.environ.get("ENVIRONMENT") == "test" else True,
     "cache_version": "1.0",
     "retries": 3,
}

@task(**task_config)
def func(input_1: str) -> str:
    ...
1
gratitude thank you 2
👍 1
m
That's wonderful. Thank you so much !!
f
Or write your own meta wrapper
m
Answer by @strong-plumber-41198 helped me to reduce "some" boilerplate code but I would like to reduce some more repeatative code. @freezing-airport-6809 thanks for help. Writing a meta wrapper sounds interesting. how do I get started with writing a meta wrapper? Is there any doc you can point me to?
f
thats just a function right
like
Copy code
def my_task(... limited):
    bind_vals ...
    return functools.partial(task, bind_vals...)