Skip to content
Snippets Groups Projects
Commit 66d4c324 authored by SKAJohanVenter's avatar SKAJohanVenter
Browse files

Merge branch 'SAR-149-transaction-ids' of gitlab.com:ska-telescope/ska-logging...

Merge branch 'SAR-149-transaction-ids' of gitlab.com:ska-telescope/ska-logging into SAR-149-transaction-ids
parents b1c063e6 3d0b5e9c
No related branches found
No related tags found
No related merge requests found
......@@ -109,10 +109,7 @@ class Transaction:
self._params = params
self._transaction_id_key = transaction_id_key
self._transaction_id = transaction_id if self._is_valid_id(transaction_id) else ""
if not self._transaction_id:
self._transaction_id = self._get_from_params_or_generate_new_id()
self._transaction_id = self._get_id_from_params_or_generate_new_id(transaction_id)
if transaction_id and params.get(self._transaction_id_key):
self.logger.info(
......@@ -137,20 +134,27 @@ class Transaction:
if exc_type:
raise
def _get_from_params_or_generate_new_id(self):
"""Use the transaction_id_key to get the transaction ID from the parameters
or generate a new one if it's not there.
def _get_id_from_params_or_generate_new_id(self, transaction_id):
"""At first use the transaction_id passed or use the transaction_id_key to get the
transaction ID from the parameters or generate a new one if it's not there.
Parameters
----------
transaction_id : [String]
[The transaction ID]
Returns
-------
[String]
[transaction ID]
"""
transaction_id = self._params.get(self._transaction_id_key)
if not self._is_valid_id(transaction_id):
transaction_id = self._generate_new_id()
self.logger.info(f"Generated transaction ID {transaction_id}")
return transaction_id
_transaction_id = (
transaction_id if transaction_id else self._params.get(self._transaction_id_key)
)
if not self._is_valid_id(_transaction_id):
_transaction_id = self._generate_new_id()
self.logger.info(f"Generated transaction ID {_transaction_id}")
return _transaction_id
def _is_valid_id(self, transaction_id):
"""Check if the ID is valid
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment