Ilhom Hayot o'g'li
06/08/2022, 2:20 PMKevin Kho
06/08/2022, 2:33 PMend_time
- start_time
with some further processingIlhom Hayot o'g'li
06/08/2022, 2:41 PMKevin Kho
06/08/2022, 2:47 PM@task
returns a class. Can you try switching the order of the decorators?Ilhom Hayot o'g'li
06/08/2022, 2:53 PMKevin Kho
06/08/2022, 3:22 PMNate
06/08/2022, 4:00 PMfrom prefect import Flow
from prefect.tasks.core.function import FunctionTask
from time import sleep, time
from typing import Any, Callable
class timed_task(FunctionTask):
def __init__(
self,
fn: Callable = None,
name: str = None,
**kwargs: Any
):
def timed_fn(**kwargs) -> Callable:
t1 = time()
result = fn(**kwargs)
t2 = time()
print(f'Function {fn.__name__!r} executed in {(t2-t1):.4f}s')
return result
super().__init__(fn=timed_fn, name=name, **kwargs)
@timed_task
def my_func() -> None:
sleep(10)
with Flow('My Timed Flow') as flow:
my_func()
if __name__ == "__main__":
flow.run()