python3-commons 0.9.8__py3-none-any.whl → 0.9.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,9 @@
1
+ import functools
2
+ import inspect
1
3
  import logging
2
4
  import shlex
3
5
  import threading
6
+ import time
4
7
  from abc import ABCMeta
5
8
  from collections import defaultdict
6
9
  from datetime import date, datetime, timedelta
@@ -58,12 +61,12 @@ def date_range(start_date, end_date):
58
61
  def tries(times):
59
62
  def func_wrapper(f):
60
63
  async def wrapper(*args, **kwargs):
61
- for time in range(times if times > 0 else 1):
64
+ for _time in range(times if times > 0 else 1):
62
65
  # noinspection PyBroadException
63
66
  try:
64
67
  return await f(*args, **kwargs)
65
68
  except Exception as exc:
66
- if time >= times:
69
+ if _time >= times:
67
70
  raise exc
68
71
 
69
72
  return wrapper
@@ -108,3 +111,21 @@ def request_to_curl(
108
111
  curl_cmd.append(shlex.quote(data.decode('utf-8')))
109
112
 
110
113
  return ' '.join(curl_cmd)
114
+
115
+
116
+ def log_execution_time(func):
117
+ _logger = logging.getLogger(func.__module__)
118
+
119
+ @functools.wraps(func)
120
+ async def wrapper(*args, **kwargs):
121
+ start_time = time.monotonic()
122
+
123
+ try:
124
+ return await func(*args, **kwargs)
125
+ finally:
126
+ elapsed = time.monotonic() - start_time
127
+ _logger.info(f'{func.__module__}.{func.__name__} executed in {elapsed:.4f} seconds')
128
+
129
+ wrapper.__signature__ = inspect.signature(func)
130
+
131
+ return wrapper
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python3-commons
3
- Version: 0.9.8
3
+ Version: 0.9.10
4
4
  Summary: Re-usable Python3 code
5
5
  Author-email: Oleg Korsak <kamikaze.is.waiting.you@gmail.com>
6
6
  License-Expression: GPL-3.0
@@ -5,7 +5,7 @@ python3_commons/auth.py,sha256=fINE7zeq-oaEk2lwkdP1KOhfCpcIBaC8P9UzXQI37J0,2922
5
5
  python3_commons/cache.py,sha256=lf27LTD4Z9Iqi5GaK8jH8UC0cL9sHH8wicZ88YDp6Mg,7725
6
6
  python3_commons/conf.py,sha256=DYFA2_n7W40MBbpaNWv4iTWh7-GPsGU6Ilygz32tHhs,2397
7
7
  python3_commons/fs.py,sha256=wfLjybXndwLqNlOxTpm_HRJnuTcC4wbrHEOaEeCo9Wc,337
8
- python3_commons/helpers.py,sha256=qSBQ1A02BEmIY8UPJkCoO28aZq0BPsMg6AGW9k-CThM,3166
8
+ python3_commons/helpers.py,sha256=lmVXsqaFcOFdQT_ZYz4onrbLYfxBn7_H4KzTLwOV1qM,3699
9
9
  python3_commons/object_storage.py,sha256=4-nWfcYF9Uj6bx3aVM6a4P5Ac2fFCTEaDfejDzn63Qk,6441
10
10
  python3_commons/permissions.py,sha256=bhjTp-tq-oaTGFMHNnSBlcVX5XQCTL0nWcu6SdPEAB4,1555
11
11
  python3_commons/db/__init__.py,sha256=5nArsGm17e-pelpOwAeBKy2n_Py20XqklZsNgkcJ-DQ,2947
@@ -21,9 +21,9 @@ python3_commons/serializers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMp
21
21
  python3_commons/serializers/json.py,sha256=91UaXLGKGj0yPyrnuMeNrkG2GuPUgcgAsmIokUgEwpU,808
22
22
  python3_commons/serializers/msgpack.py,sha256=WrvaPE187shSK8zkH4UHHMimEZNMv9RaDSwsBE2HlCw,1269
23
23
  python3_commons/serializers/msgspec.py,sha256=0AliXlEl5sewi0UENjI8St5ZScXE5DNRERKzqWKy2Ps,2674
24
- python3_commons-0.9.8.dist-info/licenses/AUTHORS.rst,sha256=3R9JnfjfjH5RoPWOeqKFJgxVShSSfzQPIrEr1nxIo9Q,90
25
- python3_commons-0.9.8.dist-info/licenses/LICENSE,sha256=xxILuojHm4fKQOrMHPSslbyy6WuKAN2RiG74HbrYfzM,34575
26
- python3_commons-0.9.8.dist-info/METADATA,sha256=iKuAznFlt7lNhTHW_mocJPyS5HYnrsy-OdXTUkwWqJY,1133
27
- python3_commons-0.9.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
28
- python3_commons-0.9.8.dist-info/top_level.txt,sha256=lJI6sCBf68eUHzupCnn2dzG10lH3jJKTWM_hrN1cQ7M,16
29
- python3_commons-0.9.8.dist-info/RECORD,,
24
+ python3_commons-0.9.10.dist-info/licenses/AUTHORS.rst,sha256=3R9JnfjfjH5RoPWOeqKFJgxVShSSfzQPIrEr1nxIo9Q,90
25
+ python3_commons-0.9.10.dist-info/licenses/LICENSE,sha256=xxILuojHm4fKQOrMHPSslbyy6WuKAN2RiG74HbrYfzM,34575
26
+ python3_commons-0.9.10.dist-info/METADATA,sha256=KIEVnOPDu7jA5lzUpjw7scNG9Ic4KJKgK2wWf8rPOC0,1134
27
+ python3_commons-0.9.10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
28
+ python3_commons-0.9.10.dist-info/top_level.txt,sha256=lJI6sCBf68eUHzupCnn2dzG10lH3jJKTWM_hrN1cQ7M,16
29
+ python3_commons-0.9.10.dist-info/RECORD,,