app.decorators.logging_time()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 36
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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