| Total Complexity | 1 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | """ |
||
| 2 | Decorators for Bot functions |
||
| 3 | """ |
||
| 4 | |||
| 5 | import time |
||
| 6 | from functools import wraps |
||
| 7 | from app.logger import log |
||
| 8 | |||
| 9 | |||
| 10 | def logging_time(func): |
||
| 11 | """ |
||
| 12 | :param func: |
||
| 13 | :return: |
||
| 14 | """ |
||
| 15 | |||
| 16 | @wraps(func) |
||
| 17 | def wrapper(*args, **kwargs): |
||
| 18 | """ |
||
| 19 | :param args: |
||
| 20 | :param kwargs: |
||
| 21 | :return: |
||
| 22 | """ |
||
| 23 | |||
| 24 | def duration(start, end): |
||
| 25 | return f"{end - start:.2f}" |
||
| 26 | |||
| 27 | start_time = time.time() |
||
| 28 | log.debug( |
||
| 29 | "%s - Start time: %s", |
||
| 30 | func.__name__, |
||
| 31 | time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(start_time)), |
||
| 32 | ) |
||
| 33 | result = func(*args, **kwargs) |
||
| 34 | end_time = time.time() |
||
| 35 | log.debug( |
||
| 36 | "%s - End time: %s", |
||
| 37 | func.__name__, |
||
| 38 | time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(start_time)), |
||
| 39 | ) |
||
| 40 | log.debug( |
||
| 41 | "%s - Duration: %s seconds", func.__name__, duration(start_time, end_time) |
||
| 42 | ) |
||
| 43 | return result |
||
| 44 | |||
| 45 | return wrapper |
||
| 46 |