Passed
Push — master ( 653794...1bc565 )
by torrua
01:28
created

app.decorators   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A logging_time() 0 36 1
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