🔊 improve logging messages
This commit is contained in:
parent
0d4d6d3f46
commit
1ea8f7a1f0
2 changed files with 15 additions and 9 deletions
|
@ -280,7 +280,7 @@ def main():
|
||||||
|
|
||||||
# Log the current run timestamp
|
# Log the current run timestamp
|
||||||
started_at = recent_run.started_at.strftime('%Y-%m-%d %H:%M:%S %Z')
|
started_at = recent_run.started_at.strftime('%Y-%m-%d %H:%M:%S %Z')
|
||||||
logger.info(f"Setting previous run to: {started_at}")
|
logger.info(f"Setting recent run to: {started_at}")
|
||||||
|
|
||||||
# Exit if the script is already running
|
# Exit if the script is already running
|
||||||
except ScriptAlreadyRunningError:
|
except ScriptAlreadyRunningError:
|
||||||
|
|
|
@ -65,7 +65,7 @@ class RecentRun:
|
||||||
|
|
||||||
# Update the values
|
# Update the values
|
||||||
if recent_run:
|
if recent_run:
|
||||||
toml['recent_run'] = recent_run
|
toml['recent-run'] = recent_run
|
||||||
if is_running is not None:
|
if is_running is not None:
|
||||||
toml['is-running'] = is_running
|
toml['is-running'] = is_running
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ class RecentRun:
|
||||||
.astimezone(self._timezone)
|
.astimezone(self._timezone)
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Invalid recent_run '{recent_run}' in {self._file_path}.")
|
f"Invalid recent-run '{recent_run}' in {self._file_path}.")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def datetime(self) -> dt | None:
|
def datetime(self) -> dt | None:
|
||||||
|
@ -167,7 +167,7 @@ class RecentRun:
|
||||||
|
|
||||||
# If no exception occurred, set the recent run time to the current time
|
# If no exception occurred, set the recent run time to the current time
|
||||||
if exc_type is None:
|
if exc_type is None:
|
||||||
self.datetime = recent_run = self._started_at
|
recent_run = self._started_at
|
||||||
|
|
||||||
self._sync_file(recent_run=recent_run, is_running=self._is_running)
|
self._sync_file(recent_run=recent_run, is_running=self._is_running)
|
||||||
|
|
||||||
|
@ -316,22 +316,27 @@ class CiviCrm:
|
||||||
:return: Number of failed requests
|
:return: Number of failed requests
|
||||||
"""
|
"""
|
||||||
error_count = 0
|
error_count = 0
|
||||||
|
self._error_bag = []
|
||||||
failed_requests = {'groups': deque(), 'users': deque()}
|
failed_requests = {'groups': deque(), 'users': deque()}
|
||||||
|
|
||||||
for name, requests in self._requests.items():
|
for name, requests in self._requests.items():
|
||||||
logger.info(f"Sending {len(requests)} {name}")
|
counter = 0
|
||||||
|
number_of_requests = len(requests)
|
||||||
|
logger.info(f"Sending {number_of_requests} {name}")
|
||||||
|
|
||||||
while requests:
|
while requests:
|
||||||
|
counter += 1
|
||||||
request = requests.popleft()
|
request = requests.popleft()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = api.api3(**request)
|
result = api.api3(**request)
|
||||||
logger.info(f"Result: {result}", extra={'result': result})
|
logger.info(f"Result {counter}/{number_of_requests}: "
|
||||||
|
f"{result}", extra={'result': result})
|
||||||
if result.get('is_error', False):
|
if result.get('is_error', False):
|
||||||
raise Exception(result.get('error_message'))
|
raise Exception(result.get('error_message'))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._error_bag.append({
|
error = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'request': {
|
'request': {
|
||||||
'entity': request['entity'],
|
'entity': request['entity'],
|
||||||
|
@ -342,9 +347,10 @@ class CiviCrm:
|
||||||
'method': str(request['method']),
|
'method': str(request['method']),
|
||||||
},
|
},
|
||||||
'error': str(e),
|
'error': str(e),
|
||||||
})
|
}
|
||||||
|
self._error_bag.append(error)
|
||||||
logger.exception(f"Error sending request: {e}",
|
logger.exception(f"Error sending request: {e}",
|
||||||
extra=request)
|
extra={'error': error})
|
||||||
failed_requests[name].append(request)
|
failed_requests[name].append(request)
|
||||||
error_count += 1
|
error_count += 1
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue