Hi everyone! I would like to create a custom task ...
# flyte-support
l
Hi everyone! I would like to create a custom task that extends the logic of my other existing tasks. My custom task should collect some metrics, send events to another API, and invoke the logic of the tasks it wraps. Does Flyte have an out-of-the-box feature for this, or should I create a decorator that wraps Flyte's task decorator? Thank you!
f
you can write wrapper decorators - as explained here
r
To the best of my knowledge, the best option is to use wrappers. These can wrap an eventually returned
flytekit.task
object if you want to be more granular and wrap the underlying task function itself, such as:
Copy code
def wrapper(func):
    @functools.wraps(func)
    def special_logger(*args): ...

    function_task = flytekit.task(
        _task_function=special_logger,
        ...
    )

    return function_task
The link provided by @freezing-airport-6809 provides a probably simpler and effective solution for most use cases.
f
the link is essentially a secondary decorator
l
@curved-petabyte-84246