iker-python-common 1.0.50__py3-none-any.whl → 1.0.52__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.
@@ -65,6 +65,39 @@ class ConnectionMaker(object):
65
65
  self.engine_opts = engine_opts or {}
66
66
  self.session_opts = session_opts or {}
67
67
 
68
+ @staticmethod
69
+ def create(
70
+ driver: str | None = None,
71
+ host: str | None = None,
72
+ port: int | None = None,
73
+ username: str | None = None,
74
+ password: str | None = None,
75
+ database: str | None = None,
76
+ *,
77
+ engine_opts: dict[str, JsonType] | None = None,
78
+ session_opts: dict[str, JsonType] | None = None,
79
+ ):
80
+ """
81
+ Creates a new instance of ``ConnectionMaker`` using the provided parameters to construct a SQLAlchemy URL.
82
+
83
+ :param driver: Optional database driver.
84
+ :param host: The database host (e.g., 'localhost').
85
+ :param port: The database port.
86
+ :param username: The database username.
87
+ :param password: The database password.
88
+ :param database: The name of the database to connect to.
89
+ :param engine_opts: Optional dictionary of SQLAlchemy engine options.
90
+ :param session_opts: Optional dictionary of SQLAlchemy session options.
91
+ """
92
+ return ConnectionMaker(sqlalchemy.URL.create(drivername=driver,
93
+ host=host,
94
+ port=port,
95
+ username=username,
96
+ password=password,
97
+ database=database),
98
+ engine_opts=engine_opts,
99
+ session_opts=session_opts)
100
+
68
101
  @staticmethod
69
102
  def from_url(
70
103
  url: str | sqlalchemy.URL,
@@ -1,9 +1,9 @@
1
1
  import abc
2
- import datetime
3
2
  import random
4
3
  import time
5
4
 
6
5
  from iker.common.utils import logger
6
+ from iker.common.utils.dtutils import dt_utc_now
7
7
 
8
8
  __all__ = [
9
9
  "Attempt",
@@ -21,8 +21,8 @@ class Attempt(object):
21
21
  number: int,
22
22
  prev_wait: int,
23
23
  next_wait: int,
24
- start_time: datetime.datetime,
25
- check_time: datetime.datetime,
24
+ start_ts: float,
25
+ check_ts: float,
26
26
  last_exception: Exception,
27
27
  ):
28
28
  """
@@ -31,15 +31,15 @@ class Attempt(object):
31
31
  :param number: The attempt number (1-based).
32
32
  :param prev_wait: The wait time before the previous attempt (in seconds).
33
33
  :param next_wait: The wait time before the next attempt (in seconds).
34
- :param start_time: The start time of the first attempt.
35
- :param check_time: The time at which the current attempt is checked.
34
+ :param start_ts: The start timestamp of the first attempt.
35
+ :param check_ts: The timestamp at which the current attempt is checked.
36
36
  :param last_exception: The exception raised during the last attempt, if any.
37
37
  """
38
38
  self.number = number
39
39
  self.prev_wait = prev_wait
40
40
  self.next_wait = next_wait
41
- self.start_time = start_time
42
- self.check_time = check_time
41
+ self.start_ts = start_ts
42
+ self.check_ts = check_ts
43
43
  self.last_exception = last_exception
44
44
 
45
45
 
@@ -127,17 +127,17 @@ class RetryWrapper(object):
127
127
  else:
128
128
  return 0
129
129
 
130
- def __check_timeout(self, start_time: datetime.datetime):
130
+ def __check_timeout(self, start_ts: float) -> tuple[bool, float]:
131
131
  """
132
132
  Checks if the retry operation has exceeded the configured timeout.
133
133
 
134
- :param start_time: The start time of the first attempt.
135
- :return: Tuple (``True`` if within timeout, current time as ``datetime``).
134
+ :param start_ts: The start timestamp of the first attempt.
135
+ :return: Tuple (``True`` if within timeout, current timestamp).
136
136
  """
137
- now = datetime.datetime.now()
137
+ current_ts = dt_utc_now().timestamp()
138
138
  if self.timeout is None:
139
- return True, now
140
- return (now < start_time + datetime.timedelta(seconds=self.timeout)), now
139
+ return True, current_ts
140
+ return current_ts < start_ts + self.timeout, current_ts
141
141
 
142
142
  def __run(self, *args, **kwargs):
143
143
  """
@@ -150,13 +150,13 @@ class RetryWrapper(object):
150
150
  :raises RuntimeError: If all attempts fail or timeout is reached.
151
151
  """
152
152
  attempt_number = 0
153
- start_time = datetime.datetime.now()
153
+ start_ts = dt_utc_now().timestamp()
154
154
  last_exception = None
155
155
 
156
156
  while self.retrials is None or attempt_number <= self.retrials:
157
157
  attempt_number += 1
158
158
 
159
- check_result, check_time = self.__check_timeout(start_time)
159
+ check_result, check_ts = self.__check_timeout(start_ts)
160
160
  if not check_result:
161
161
  break
162
162
 
@@ -164,8 +164,8 @@ class RetryWrapper(object):
164
164
  attempt_number,
165
165
  self.__next_wait(attempt_number - 1),
166
166
  self.__next_wait(attempt_number),
167
- start_time,
168
- check_time,
167
+ start_ts,
168
+ check_ts,
169
169
  last_exception,
170
170
  )
171
171
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: iker-python-common
3
- Version: 1.0.50
3
+ Version: 1.0.52
4
4
  Classifier: Programming Language :: Python :: 3
5
5
  Classifier: Programming Language :: Python :: 3.11
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -3,7 +3,7 @@ iker/common/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
3
3
  iker/common/utils/argutils.py,sha256=hMLNqdZs_Kjc2hw4Npm6N47RivP6JRNzCKIbJr1jYy8,9274
4
4
  iker/common/utils/config.py,sha256=z8rLqli961A-qAV9EaELp-pKuhNUNaq1Btdv-uwG7_I,4690
5
5
  iker/common/utils/csv.py,sha256=_V9OUrKcojec2L-hWagEIVnL2uvGjyJAFTrD7tHNr48,7573
6
- iker/common/utils/dbutils.py,sha256=q-rZ9KNFxAEsSXWcqcihQTsqiDlWbSFHZ5XGVPj2tnk,10335
6
+ iker/common/utils/dbutils.py,sha256=zXZVJCz7HZPityFRF7sHRRMpMraegV_hyYnzApUUPhY,11852
7
7
  iker/common/utils/dockerutils.py,sha256=n2WuzXaZB6_WocSljvPOnfExSIjIHRUbuWp2oBbaPKQ,8004
8
8
  iker/common/utils/dtutils.py,sha256=86vbaa4pgcBWERZvTfJ92PKB3IimxP6tf0O11ho2Ffk,12554
9
9
  iker/common/utils/funcutils.py,sha256=A08f5wjoLgLQKyRJcYeWJnqVm2QcerIx0l-Se2600bc,5869
@@ -11,7 +11,7 @@ iker/common/utils/jsonutils.py,sha256=xYKimWtsqQKiQDQr3EMIhpGrmWSNPzgZR1Sdz60CxS
11
11
  iker/common/utils/logger.py,sha256=FJaai6Sbchy4wKHcUMUCrrkBcXvIxq4qByERZ_TJBps,3881
12
12
  iker/common/utils/numutils.py,sha256=vg739jMqx3W1H_IxzzSJKhtEGZEnQrNgsp_tDKhEVck,4432
13
13
  iker/common/utils/randutils.py,sha256=PuQVSKNOtXTgQh8QCifMMgsGzmevkrInSSKpnqD361Q,12816
14
- iker/common/utils/retry.py,sha256=mETR-ti5NGUaK0BdrusgFogAzd_rZRuW9JSHAB3W2Ms,8947
14
+ iker/common/utils/retry.py,sha256=H9lR6pp_jzgOwKTM-dOWIddjTlQbK-ijcwuDmVvurZM,8938
15
15
  iker/common/utils/s3utils.py,sha256=rb-JVCJuIbmVn4ml7MQ7qKD8Z25t8xnU_u4oY1-APe4,9368
16
16
  iker/common/utils/sequtils.py,sha256=MfYL82TygBRlGK4sw0RJcoB5P3hO6l7saVH5oZ3YDP8,25003
17
17
  iker/common/utils/shutils.py,sha256=44_Qkzkhrs9LsfDflsaY_4Va0IpVLU3o8K_NvqCB04w,7859
@@ -19,7 +19,7 @@ iker/common/utils/span.py,sha256=yiXqk86cLKxkMdkO3pAHEfU5bUvHsGo3p--pAWo_yfM,599
19
19
  iker/common/utils/strutils.py,sha256=Tu_qFeH3K-SfwvMxdrZAc9iLPV8ZmtX4ntyyFGNslf8,5094
20
20
  iker/common/utils/testutils.py,sha256=2VieV5yeCDntSKQSpIeyqRT8BZmZYE_ArMeQz3g7fXY,5568
21
21
  iker/common/utils/typeutils.py,sha256=RVkYkFRgDrx77OHFH7PavMV0AIB0S8ly40rs4g7JWE4,8220
22
- iker_python_common-1.0.50.dist-info/METADATA,sha256=-1LTQO70aQMjIiAieCqzoziAGeRaCE9DKd9WdXBmCrk,1001
23
- iker_python_common-1.0.50.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
24
- iker_python_common-1.0.50.dist-info/top_level.txt,sha256=4_B8Prfc_lxFafFYTQThIU1ZqOYQ4pHHHnJ_fQ_oHs8,5
25
- iker_python_common-1.0.50.dist-info/RECORD,,
22
+ iker_python_common-1.0.52.dist-info/METADATA,sha256=xX-lcqFtKgi1VKIvTeQj7D5po6gZrK38dWGEHmAw08U,1001
23
+ iker_python_common-1.0.52.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
24
+ iker_python_common-1.0.52.dist-info/top_level.txt,sha256=4_B8Prfc_lxFafFYTQThIU1ZqOYQ4pHHHnJ_fQ_oHs8,5
25
+ iker_python_common-1.0.52.dist-info/RECORD,,